Skip to content

Added support to scan github commit metadata for targeted scans #4189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 2, 2025

Conversation

kashifkhan0771
Copy link
Contributor

@kashifkhan0771 kashifkhan0771 commented May 29, 2025

Description:

GitHub re-verification(Targeted Scan) works by downloading the file containing the secret and re-scanning it. However, secrets detected in commit metadata don’t have associated files, which causes the download to fail with an unclear error message. This PRs add the support for Github re-verification to scan the commit metadata if no file is there.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@kashifkhan0771 kashifkhan0771 requested review from a team as code owners May 29, 2025 13:31
@@ -1543,6 +1556,12 @@ func (s *Source) scanTarget(ctx context.Context, target sources.ChunkingTarget,
return fmt.Errorf("invalid GitHub URL")
}

// scan commit metadata if the source meta has no file
if meta.GetFile() == "" && meta.GetCommit() != "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add a log message (at level 2) explaining what's happening. (If you do this, I think you can eliminate the comment - the log message text should explain to readers what's happening.)

You might as well add the commit hash as a context value here, instead of right before calling HandleFile in scanCommitMetadata. That way, if someone adds more logging later, they'll get the commit hash without having to think about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✔️

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, sorry, I wasn't clear about the context thing. I meant something like this:

ctx := context.WithValues(ctx, "commit_hash", meta.GetCommit())
ctx.Logger().V(2).Info("secret metadata has no file; scanning commit metadata instead")
return s.scanCommitMetadata(ctx, segments[1], segments[2], meta, &chunkSkel, reporter)

Note how the commit hash is now embedded into the context so all future log messages that use this context will inherit it. (I also put the message at level 2, so it will only show up with the --debug or --trace flags.)

Copy link
Collaborator

@rosecodym rosecodym left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this!

@kashifkhan0771 kashifkhan0771 merged commit 957ece9 into trufflesecurity:main Jun 2, 2025
13 checks passed
@kashifkhan0771 kashifkhan0771 deleted the fix/oss-206 branch June 2, 2025 05:07
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