GreedyBear icon indicating copy to clipboard operation
GreedyBear copied to clipboard

Advanced feed returns IOCs when tag_key and tag_value match different tags

Open Saurabh-1785 opened this issue 1 week ago • 1 comments

When an authenticated user supplies both tag_key and tag_value to /api/feeds/advanced/, the endpoint can return an IOC whose tags match those parameters separately. For example, a search for malware=botnet_cc returns an IOC whose malware is Mirai, because botnet_cc appears in its threat_type tag.

I reproduced this through the authenticated API against a local PostgreSQL test database on develop at 18dfaff.

Steps to reproduce

  1. Use the existing FeedsTagsTestCase fixture. It assigns two tags to 140.246.171.141, one with key="malware", value="Mirai" and another with key="threat_type", value="botnet_cc". Test fixture
  2. Using the fixture's authenticated client, send GET /api/feeds/advanced/?tag_key=malware&tag_value=botnet_cc.
  3. Inspect the value fields in the response's iocs array.

All three requests below returned HTTP 200. The middle row shows the false positive.

tag_key tag_value Expected result for 140.246.171.141 Actual result
malware Mirai Included Included ✅
malware botnet_cc Excluded Included ❌
malware absent Excluded Excluded ✅

Cause

FeedsFilterSet declares tag_key and tag_value as separate filters on the reverse tags relation. Django applies them in successive queryset .filter() calls, so each condition can match a different Tag row for the same IOC. The final .distinct() removes duplicate IOCs, but an IOC that matched across two rows still qualifies.

Proposed fix

Have FeedsFilterSet collect the supplied tag lookups and apply them in a single .filter() call. When both parameters are present, use queryset.filter(tags__key__iexact=tag_key, tags__value__icontains=tag_value) so one tag must satisfy both conditions. When only one parameter is present, apply just that lookup. This preserves case-insensitive exact matching for keys and case-insensitive substring matching for values.

Add a regression test using the existing two-tag fixture. Assert that malware with botnet_cc excludes the IOC and that malware with mirai includes it. The existing combined-filter test checks only the positive case, so it passes with the current behavior.

@regulartim kindly check this and I'd be happy to work on this.

Saurabh-1785 avatar Nov 26 '26 04:11 Saurabh-1785

Hey @Saurabh-1785 ! Good catch, thank you! I'll assign you.

regulartim avatar Nov 26 '26 06:11 regulartim