Skip to content

Fix regex logic for SecretsUsedInArgOrEnv to match comment and test #6089

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

markercm
Copy link

@markercm markercm commented Jul 16, 2025

I've added the regex pattern that @Nuru suggested in #5775 (comment) and added tests for the function to ensure that it actually works.

Copilot created the tests.

Inspired by a comment in but doesn't actually address #5775

@markercm markercm force-pushed the fix-SecretsUsedInArgOrEnv-logic-to-match-comment-and-test branch from ccae356 to dcda7e3 Compare July 16, 2025 19:31
Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

I'm not sure what is the difference between matching PASSWORD_ROOT but not matching DB_PASSWORD_ROOT. If this is causing too many false positives (not sure if the case) then matching last component or full text could be more limited set. @colinhemmings

A more general fix would be to add the skip comments per-line, that are currently only supported per-file.

key string
isSecret bool
}{
// Positive matches
Copy link
Member

Choose a reason for hiding this comment

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

None of these tests seem to actually check for the change of behavior (handling secrets in the middle of string).

Copy link
Author

Choose a reason for hiding this comment

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

{name: "contains key but not fitst of last or full", key: "new_key_file_path", isSecret: false},

This matches on the old behavior even though key is neither the first nor last nor full match but doesn't with the new logic.

@markercm
Copy link
Author

A more general fix would be to add the skip comments per-line, that are currently only supported per-file.

I would agree with you and would love to see that get prioritized as it seems like the only real option.

}

for _, tc := range testCases {
tc := tc
Copy link
Member

Choose a reason for hiding this comment

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

Check the linter error caused by this line

Copy link
Author

Choose a reason for hiding this comment

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

😮‍💨 fixed in ae3cbeb

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

Successfully merging this pull request may close these issues.

2 participants