Skip to content

Add Sigma rule ID extraction to EntityExtractor#185

Merged
rolandpg merged 10 commits into
masterfrom
copilot/add-sigma-rule-id-extraction
Jul 7, 2026
Merged

Add Sigma rule ID extraction to EntityExtractor#185
rolandpg merged 10 commits into
masterfrom
copilot/add-sigma-rule-id-extraction

Conversation

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds first-class sigma_rule extraction from CTI text so Sigma references are indexed as entities and carried through remember() into note.semantic.entities.

Related issue

Linked automatically by the system.

Changes

  • Entity extractor

    • Added sigma_rule to REGEX_PATTERNS in /src/zettelforge/entity_indexer.py
    • Added sigma_rule to ENTITY_TYPES
    • Implemented matching for:
      • sigma:rule_name
      • Sigma Rule: rule_name
      • bare Sigma-style rule IDs (prefix_segment_segment...) with Sigma-focused prefix constraints to reduce snake_case false positives
    • Refactored Sigma prefix set into a class constant for maintainability
  • Test coverage (tests/test_basic.py::TestEntityExtractor)

    • Added positive cases for:
      • sigma:apt28_cobalt_strike
      • Sigma Rule: win_susp_powershell_encoded_cmd
      • bare win_susp_powershell_encoded_cmd
    • Added negative cases for:
      • no Sigma rule present → empty sigma_rule
      • common snake_case identifiers (e.g., user_id) are not extracted as Sigma rules
  • Integration behavior

    • Added TestMemoryManager::test_remember_includes_sigma_rule_entities to verify extracted Sigma IDs are present in note.semantic.entities after remember().
ext = EntityExtractor()
result = ext.extract_all("Detection via sigma:apt28_cobalt_strike")
assert "apt28_cobalt_strike" in result["sigma_rule"]

Testing

  • Tests pass (pytest tests/ -v)
  • Linting passes (ruff check src/zettelforge/)
  • New tests added for new functionality
  • No new external infrastructure dependencies without discussion

Copilot AI linked an issue Jul 2, 2026 that may be closed by this pull request
6 tasks
Copilot AI changed the title [WIP] Add Sigma rule ID extraction using regex patterns Add Sigma rule ID extraction to EntityExtractor Jul 2, 2026
Copilot AI requested a review from rolandpg July 2, 2026 01:47
claude added 2 commits July 7, 2026 02:16
The single-branch pattern applied the logsource-prefix whitelist even
to explicitly labeled references, so sigma:lateral_movement_smb_admin_share
was missed, while any two-token identifier starting with a whitelisted
prefix (file_name, win_rate, net_income, apt_get) was extracted as a
Sigma rule. Labeled forms now accept any snake_case rule name; bare IDs
require a whitelisted prefix plus at least two more segments. The regex
loop in extract_regex now flattens multi-group alternation matches.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TqYpmV8TABMzq27HBTLtNP
@rolandpg
rolandpg marked this pull request as ready for review July 7, 2026 02:19

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ule-id-extraction

# Conflicts:
#	tests/test_basic.py
devin-ai-integration[bot]

This comment was marked as resolved.

…ata-suffix FPs

Review feedback: the labeled form now accepts canonical Sigma YAML UUID
rule ids (Sigma Rule: 929a690e-...), the bare-ID prefix whitelist gains
SigmaHQ event-type filename prefixes (registry, dns, pipe, image, posh,
wmi, driver), and bare IDs ending in generic metadata suffixes
(aws_access_key_id, file_create_time, image_file_name) are excluded via
lookbehinds. Regression tests for each.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TqYpmV8TABMzq27HBTLtNP
@rolandpg
rolandpg merged commit 8e2e8f0 into master Jul 7, 2026
14 checks passed
@rolandpg
rolandpg deleted the copilot/add-sigma-rule-id-extraction branch July 7, 2026 03:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 901c111ef5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

"tool",
"campaign",
"attack_pattern",
"sigma_rule",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Map extracted Sigma IDs to existing SigmaRule nodes

When users query text like Sigma Rule: <uuid> for a rule ingested through zettelforge.sigma.ingest, this new extractor emits sigma_rule:<uuid>. The ingest path persists detection KG edges from SigmaRule:<uuid> (src/zettelforge/sigma/entities.py builds from_type: "SigmaRule" and _persist_relations passes that through), and GraphRetriever looks up the exact (entity_type, entity_value), so traversal starts from a different node and misses the ingested rule relationships. Separately from the previously noted YAML-id extraction gap, the fresh evidence is that the lowercase entity type introduced here is incompatible with the existing SigmaRule endpoints.

Useful? React with 👍 / 👎.

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.

Add Sigma rule ID extraction

3 participants