Skip to content

fix(query): fixed allowRule's on Generic Token and Generic Secret from Passwords and Secrets query#7739

Merged
cx-andre-pereira merged 1 commit into
masterfrom
AST-102190--fix-regex-on-allow-rules
Sep 24, 2025
Merged

fix(query): fixed allowRule's on Generic Token and Generic Secret from Passwords and Secrets query#7739
cx-andre-pereira merged 1 commit into
masterfrom
AST-102190--fix-regex-on-allow-rules

Conversation

@cx-ricardo-jesus

@cx-ricardo-jesus cx-ricardo-jesus commented Sep 24, 2025

Copy link
Copy Markdown
Contributor

Closes #

Reason for Proposed Changes

  • On the current implementation, in the allowRule below, the regex covers the cases when there are no parentheses at the end, it also allows the built in function getSecret not to have any argument, which is not valid according to its documentation and the usage of the characters " or ' was not mandatory which is not valid since, according to the built-in function documentation, the argument must be a string thus, it should have the characters " or ' .
{
          "description": "Allow secrets retrieved from Bicep getSecret built in function",
          "regex": "(?i)['\"]?secret[_]?(key|value)?['\"]?\\s*(:|=)\\s*[a-zA-Z]*\\.getSecret\\(\\s*[\"']?([A-Za-z0-9/~^_!@#&%(){};=?*+-<>,:;[\\]%$]*)[\"']?"
}
  • On the other allowRule, that was made to ignore the cases when a module output is referenced on Bicep format files, the ['"]? should be removed since the target file type does not use quotes to declare variables.
{
          "description": "Avoiding references to module outputs in Bicep",
          "regex": "(?i)['\"]?token(_)?(key)?\\s*[:=]\\s*([a-zA-Z][a-zA-Z0-9_]*)\\.outputs\\.([a-zA-Z][a-zA-Z0-9_]*)"
}

Proposed Changes

  • Changed the first allowRule from (?i)['\"]?secret[_]?(key|value)?['\"]?\\s*(:|=)\\s*[a-zA-Z]*\\.getSecret\\(\\s*[\"']?([A-Za-z0-9/~^_!@#&%(){};=?*+-<>,:;[\\]%$]*)[\"']? to (?i)['\"]?secret[_]?(key|value)?['\"]?\\s*(:|=)\\s*[a-zA-Z]*\\.getSecret\\(\\s*[\"']([A-Za-z0-9/~^_!@#&%(){};=?*+-<>,:;[\\]%$]+)[\"']\\).

  • Removed the ['"] from the beginning of the second allowRule, changing the allowRule from (?i)['\"]?token(_)?(key)?\\s*[:=]\\s*([a-zA-Z][a-zA-Z0-9_]*)\\.outputs\\.([a-zA-Z][a-zA-Z0-9_]*) to (?i)token(_)?(key)?\\s*[:=]\\s*([a-zA-Z][a-zA-Z0-9_]*)\\.outputs\\.([a-zA-Z][a-zA-Z0-9_]*).

I submit this contribution under the Apache-2.0 license.

@cx-ricardo-jesus cx-ricardo-jesus requested a review from a team as a code owner September 24, 2025 13:28
@github-actions github-actions Bot added the query New query feature label Sep 24, 2025
@github-actions

Copy link
Copy Markdown
Contributor

kics-logo

KICS version: v2.1.13

Category Results
CRITICAL CRITICAL 0
HIGH HIGH 0
MEDIUM MEDIUM 0
LOW LOW 0
INFO INFO 0
TRACE TRACE 0
TOTAL TOTAL 0
Metric Values
Files scanned placeholder 1
Files parsed placeholder 1
Files failed to scan placeholder 0
Total executed queries placeholder 47
Queries failed to execute placeholder 0
Execution time placeholder 0

@cx-artur-ribeiro cx-artur-ribeiro 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, nice that you taken a look into the documentation to improve the regex pattern.

@cx-andre-pereira cx-andre-pereira merged commit b7a4a9c into master Sep 24, 2025
44 checks passed
@cx-andre-pereira cx-andre-pereira deleted the AST-102190--fix-regex-on-allow-rules branch September 24, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

query New query feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants