Secrets

SonarQube Community Build detects exposed Secrets in your source code and language-agnostic config files, starting in the SonarQube Community Build.

Secrets are pieces of user-specific or system-level credentials that should be protected and accessible to legitimate users only. SonarQube Community Build detects exposed Secrets in all files processed by the language analyzers and in all files configured through the sonar.text.inclusions property.

This page explains how to configure the secret-specific parameters and to adjust the secret detection scope.

SonarQube Community Build doesn’t support defining custom rules based on your own secret patterns to detect secrets that are specific to your company. See Feature comparison table to find out which SonarQube deployments support this feature.

Configuring secret-specific parameters (general procedure)

Discover and update the secret-specific Analysis parameters in Administration > Configuration > General Settings > Languages > Secrets

Adjusting the secret detection scope

By default, SonarQube Server and SonarQube Community Build detect exposed secrets in all files processed by the language analyzers. You can refine the scope of the secret detection by:

  • Excluding hidden files from the analysis.

  • Adding files based on path-matching patterns.

  • Adjusting the binary file exclusion setup.

Analysis of hidden files

Depending on which scanner is used, additional hidden files tracked by Git are included in the secrets analysis.

This behavior can be disabled by setting the sonar.scanner.excludeHiddenFiles analysis parameter to true.

Adding files based on path-matching patterns

If you’re using a git repository, you can add files to the secret detection scope by defining path-matching patterns: the files matching the patterns will be included provided they are tracked by git.

To add additional files to the secret detection:

  1. In the SonarQube Server UI:

    • For a global configuration: go to Administration > Configuration > General Settings > Languages > Secrets

    • For a project-level configuration: open your project page and go to Project Settings > General Settings > Languages > Secrets

  2. Enable the Activate inclusion of custom file path patterns option.

  3. In the List of file path patterns to include, adjust the default path-matching patterns if necessary (see the Defining matching patterns page).

Alternatively, configure the parameters listed below on the CI/CD host. See the Analysis parameters page for more information about other parameters.

Property

Description

sonar.text.inclusions.activate

Enables the inclusion of files to the secret detection according to the path-matching patterns defined in sonar.text.inclusions.

sonar.text.inclusions

Comma-separated list of path-matching patterns.

Possible values: A path can be relative (to the sonar.projectBaseDir property, which is by default the directory from which the analysis was started) or absolute.

Default value: **/*.sh,**/*.bash,**/*.zsh,**/*.ksh,**/*.ps1,**/*.properties, **/*.conf,**/*.pem,**/*.config,.env,.aws/config

Adjusting the binary file exclusion setup

SonarQube Server and SonarQube Community Build exclude binary files from the analysis. In case binary file types are still included in your analysis, you can exclude these additional files.

To do so:

  1. In the SonarQube Server and SonarQube Community Build UI,

    • For a global configuration: go to Administration > Configuration > General Settings > Languages > Secrets.

    • For a project-level configuration: open your project page and go to Project Settings > General Settings > Languages > Secrets.

  2. In Additional binary file suffixes, enter the list of suffixes to be excluded.

Alternatively, configure the parameter below on the CI/CD host. See the Analysis parameters page for more information about other parameters.

Property

Description

sonar.text.excluded.file.suffixes

Comma-separated list of additional binary file suffixes to be excluded.

Analysis of files that don't contain code

Files that don’t contain code (for example, build.gradle and sonar-project.properties) are scanned durning analysis and displayed in the SonarQube Server UI after an issue is detected in them. If no secrets are detected in those files, they are not displayed in the UI.

Deactivating secrets analysis

You can deactivate the analysis of secrets by setting the sonar.text.activate property to false.

Last updated

Was this helpful?