Skip to content

[K9VULN-16354] Differentiate local module findings per caller to prevent fingerprint collisions#197

Merged
whitemerch merged 4 commits into
mainfrom
chakib.hamie/local_modules_finding_identity
Jun 22, 2026
Merged

[K9VULN-16354] Differentiate local module findings per caller to prevent fingerprint collisions#197
whitemerch merged 4 commits into
mainfrom
chakib.hamie/local_modules_finding_identity

Conversation

@whitemerch

@whitemerch whitemerch commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Motivation

When the same local Terraform module is instantiated from more than one caller, the resources it produces are attributed to the module body file and share the same finding fingerprint (repository, file path, resource type/name, rule id). Distinct module calls therefore collide and collapse into a single finding, hiding per-caller context and the per-call resolved values.

This stacks on top of #193 and folds the module call chain into the fingerprint so each caller yields its own finding.

JIRA Ticket: K9VULN-16354

Changes

  • Each instantiated local-module resource now gets a per-caller synthetic document (id = file id + call chain + instance) backed by a lightweight synthetic file entry that carries the module call chain; the document keeps an empty body so it is not re-scanned.
  • The call chain is propagated through the vulnerability and the SARIF VulnerableFile, and folded into the Datadog fingerprint via GetDatadogFingerprintHash. When the chain is empty (every non-module finding) the hash is byte-identical to before, so existing fingerprints are unchanged.
  • The module evaluation cache is now keyed by the call chain in addition to dir/address/inputs, so two distinct callers passing identical inputs are evaluated separately instead of sharing the first caller's resolved resources and call chain.

Author Checklist

  • I have reviewed my own PR.
  • I have added or updated relevant unit tests where necessary. If no tests are added, I've explained why.
  • All new and existing tests pass.
  • I have tested my changes on staging (if applicable).
  • I have updated any relevant documentation (if applicable).

QA Instruction

Scan a repo where two root stacks call the same local module (even with identical inputs). Confirm two findings are produced, each attributed to the module body file with a distinct fingerprint, instead of a single collapsed finding. Confirm non-module findings keep their previous fingerprints. See TestInspect_TwoCallersGetDistinctCallChains and TestGetDatadogFingerprintHash_ModuleCallChain.

Blast Radius

This only affects findings for resources instantiated from local Terraform modules: their document identity and fingerprint now include the call chain. Root resources and all non-module findings are unchanged (empty chain reproduces the previous hash).

Additional Notes

Builds on #193; the call chain is used only for fingerprinting for now and is also carried on the finding so it can be surfaced to users in a follow-up.

I submit this contribution under the Apache-2.0 license.

…y so identical inputs from different callers do not share one cached subtree.
…by FileMetadata clones that carry the call chain and keep line info for detection.
@whitemerch
whitemerch force-pushed the chakib.hamie/local_modules_finding_identity branch from cf0b527 to 1ad0cdd Compare June 18, 2026 15:30
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jun 18, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 93.65%
Overall Coverage: 49.79% (+0.47%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ec726e1 | Docs | Datadog PR Page | Give us feedback!

@whitemerch
whitemerch marked this pull request as ready for review June 18, 2026 17:17
@whitemerch
whitemerch requested a review from a team as a code owner June 18, 2026 17:17
@whitemerch
whitemerch marked this pull request as draft June 18, 2026 17:18
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@whitemerch
whitemerch force-pushed the chakib.hamie/local_modules_finding_identity branch from 1ad0cdd to ec726e1 Compare June 18, 2026 17:27
@whitemerch
whitemerch marked this pull request as ready for review June 18, 2026 17:28

@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: ec726e1ff2

ℹ️ 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".

ResourceSource: linesVulne.ResourceSource,
FileSource: linesVulne.FileSource,
BlockLocation: linesVulne.BlockLocation,
ModuleCallChain: file.ModuleCallChain,

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 Include module chain before storage de-duplication

Fresh evidence for the similarity-ID collision is that the normal scan path persists these results and then calls MemoryStorage.GetVulnerabilities before CreateSummary/SARIF; that de-dup key includes SimilarityID but not ModuleCallChain. Since the chain is only copied here after generateSimilaritiesID ran above, two root callers with identical resolved values still have the same query/file/line/search/keyActualValue and one is dropped before the SARIF fingerprint can use the chain, so the full CLI scan still collapses the exact scenario this change is meant to preserve.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Base automatically changed from chakib.hamie/local_modules_follow_ups to main June 18, 2026 18:22
@whitemerch
whitemerch merged commit 992a7fb into main Jun 22, 2026
4 checks passed
@whitemerch
whitemerch deleted the chakib.hamie/local_modules_finding_identity branch June 22, 2026 07:05
@whitemerch whitemerch mentioned this pull request Jun 24, 2026
5 tasks
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.

2 participants