Skip to content

Align indexed and patterned hash meta fields (#74) - #88

Merged
Neo23x0 merged 1 commit into
YARAHQ:masterfrom
munzzyy:fix/align-indexed-hash-fields
Jul 6, 2026
Merged

Align indexed and patterned hash meta fields (#74)#88
Neo23x0 merged 1 commit into
YARAHQ:masterfrom
munzzyy:fix/align-indexed-hash-fields

Conversation

@munzzyy

@munzzyy munzzyy commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #74

align_yara_rule_hashes in main/rule_processors.py only matches a fixed list of exact key names (hash, md5, sha1, sha256, etc.). The issue's key dump shows a ton of hash fields that don't match anything on that list: hash1 through hash31, md5_1 through md5_6, SHA256_1/SHA256_2, hash_1 through hash_9, hash1_sha256, thumbprint1-thumbprint4, sample_md5, sample_sha1, parent_hash, and more. All of those pass straight through to the output instead of collapsing into hash the way md5/sha1/sha256 already do.

This adds a regex check alongside the existing name list to catch the indexed/patterned variants (hash1, hash_1, md5_1, sha256_1, hash1_sha256, thumbprint2, etc.) and aligns them to hash the same way. I also added a small exclusion list for a few fields that look hash-ish but shouldn't get swept in: logic_hash is the pipeline's own dedup key (set earlier in process_yara_rules), and malpedia_hash/yarahub_reference_md5/exemplar_hashes are third-party reference fields, not a rule's own sample hash.

I didn't try to solve the whole issue here (it lists 200+ meta keys total, covering author/description/TLP casing too) - that's a much bigger and more opinionated change. This just closes the hash-field gap the issue calls out specifically, since that's the largest and most mechanical chunk of it.

Verification:

  • Ran the full key list from the issue through the new pattern locally - it catches all the indexed/typo'd hash keys and correctly skips the 4 exclusions plus unrelated fields like sharing/tlp.
  • Added tests/test_rule_processors_hashes.py covering both cases (indexed keys aligning to hash, and the exclusions staying put).
  • Ran the existing test suite - two tests fail (test_rule_collector.py, test_rule_output_guardrails.py) but they fail the same way on a clean checkout of master with no changes, so that's pre-existing drift, not something this touches.
  • flake8 main tests --select=E9,F63,F7,F82 (the syntax-error check CI runs) is clean.

Issue YARAHQ#74 documented that align_yara_rule_hashes only matches a fixed
list of exact key names, so indexed/patterned hash fields used across
real rule sets (hash1..hash31, md5_1..md5_6, SHA256_1/2, hash_1..hash_9,
hash1_sha256, thumbprint1-4, sample_md5, sample_sha1, parent_hash, etc.)
pass through unnormalized instead of collapsing to 'hash' like the
plain-named variants already do.

Add a regex match for the indexed/patterned key shapes alongside the
existing exact-name list, plus an explicit exclusion for a few
hash-adjacent fields that are not raw sample hash values (logic_hash is
the pipeline's own dedup key, malpedia_hash/yarahub_reference_md5 are
third-party reference fields, exemplar_hashes is a list not a hash
string) so they're not swept in by a broader pattern.

Verified against the full key list from the issue - the new pattern
picks up 84 indexed/typo'd hash-shaped keys while leaving the 5 keys
above and other non-hash fields (sharing, tlp, etc.) untouched.
@Neo23x0
Neo23x0 merged commit ef21d77 into YARAHQ:master Jul 6, 2026
1 check passed
@Neo23x0

Neo23x0 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observation: Inconsistent and overlapping YARA meta field usage

2 participants