Skip to content

fix(query): fix fp in password and secrets Generic Token#7555

Merged
cx-andre-pereira merged 8 commits into
Checkmarx:masterfrom
cx-andre-pereira:AST-81967--FP_Passwords_and_Secrets_Generic_Token
Jul 30, 2025
Merged

fix(query): fix fp in password and secrets Generic Token#7555
cx-andre-pereira merged 8 commits into
Checkmarx:masterfrom
cx-andre-pereira:AST-81967--FP_Passwords_and_Secrets_Generic_Token

Conversation

@cx-andre-pereira

@cx-andre-pereira cx-andre-pereira commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

Reason for Proposed Changes

  • Currently the implementation to prevent flagging of github id-token(s) such as : 'id-token: write' is not detecting relevant instances reliably.
  • The regex used at the moment ((?i)['\"]?id-token\\s*[:=]\\s*(write|read|none)\\s*$) is faulty and inconsistent relative to the rest of the regex rules for passwords_and_secrets's regex_rules.
  • This regex stands out for its requirement to scan a full line to detect the id-token ($ => "end of string"), this way something like a trailing comment will have to be explicitly captured by the regex or a text like : permissions: {id-token: write, contents: ...} will also require the capture of unnecessary text.

Proposed Changes

  • To better standardize regex logic i propose the implementation of an updated regex:
    • (?i)['\"]?id-token['\"]?\\s*[:=]\\s*(write|read|none)
  • Aside from the obvious removal of the undesirable \\s*$, i added an extra check ['\"]? after the "id-token" key-word to better align the regex composition logic with most other regex rules.
  • With this implementation detection of the "id-token" is much more reliable and independent of trailing comments or any data structure it might find itself within.
  • Finally the 2 new tests positive53 and negative53 verify, respectively, that the id-token is detected when there is a trailing comment and that it is flagged with an invalid command.

NOTE: the regex are written with double backslashes to represent the exact characters used in the passwords_and_secrets's regex_rules file strings for they are literal strings, not raw.

originalPR

I submit this contribution under the Apache-2.0 license.

@cx-andre-pereira cx-andre-pereira requested a review from a team as a code owner July 16, 2025 10:52
@github-actions github-actions Bot added community Community contribution query New query feature labels Jul 16, 2025
Comment thread assets/queries/common/passwords_and_secrets/test/negative53.yml

@cx-eduardo-semanas cx-eduardo-semanas 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.

LGTM

@cx-andre-pereira cx-andre-pereira merged commit e71bc89 into Checkmarx:master Jul 30, 2025
31 of 32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community Community contribution query New query feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants