Skip to content

Conversation

cx-ricardo-jesus
Copy link
Contributor

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

Closes #

Reason for Proposed Changes

  • Currently, it returns a false positive result on cases when there is a Bicep template, and a secret is retrieved from a keyVault module using the built-in function called getSecret.
  • Also, it's detected a false positive on the following cases:
    validationToken: module_name.outputs.parameter_field
  • This last example returns a false positive when it's just pointing to a module output.

Proposed Changes

  • For the first case, it was created a new AllowRule was created on the "Generic Secret" query that covers the cases when it's used the built-in function getSecret. The new allowRule has the following pattern:
    (?i)['\"]?secret[_]?(key|value)?['\"]?\\s*(:|=)\\s*[a-zA-Z]*\\.getSecret\\(\\s*[\"']?([A-Za-z0-9/~^_!@#&%(){};=?*+-<>,:;[\\]%$]*)[\"']?
  • For the second case, it was created a new allowRule on the query "Generic Token" that covers the specific cases when a parameter with a token in its name is just pointing to a module output. The pattern used on the new allowRule was based on the official outputs documentation from AzureResourceManager Bicep documentation (https://learn.microsoft.com/en-us/azure/azure-resource-manager/bicep/outputs?tabs=azure-powershell#outputs-from-modules) that has a defined syntax:
    <module-name>.outputs.<property-name>
  • The new allow rule covers the vast majority of the cases; however, it can cause a false negative, although the chances are almost nil, in cases where, for example, a token is defined on a YAML file(which can have strings defined without "") with the syntax mentioned above.

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 4, 2025 15:29
@github-actions github-actions bot added query New query feature azure PR related with Azure Cloud labels Sep 4, 2025
Copy link
Contributor

github-actions bot commented Sep 4, 2025

kics-logo

KICS version: v2.1.11

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

Copy link
Contributor

@cx-artur-ribeiro cx-artur-ribeiro left a comment

Choose a reason for hiding this comment

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

Hey Ricardo, just a quick fix, all good for me besides that!

@@ -346,6 +350,10 @@
{
"description": "Avoiding next_token Var",
"regex": "(?i)['\"]?next(_)?token['\"]?\\s*[:=]\\s*['\"]?([[A-Za-z0-9/~^_!@&%()=?*+-]+)['\"]?"
},
{
"description": "Avoiding reference to module outputs in Bicep",
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a quick improvement, I would put "reference" as "references", like shown below:

Suggested change
"description": "Avoiding reference to module outputs in Bicep",
"description": "Avoiding references to module outputs in Bicep",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
azure PR related with Azure Cloud query New query feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants