Manage secret scanning exceptions

When you push to an app's platform-managed Git repository, secret scanning checks the files that the push adds or changes for credentials, such as keys, passwords, tokens, and connection strings. If the scan finds a credential, the platform rejects the update to that branch.

This article explains how to read a rejection message, respond when a finding is a real credential, and add an exception when a finding is a false positive.

Note

Secret scanning applies only to apps that use a platform-managed Git repository. It doesn't apply to apps that use an external GitHub repository. For more information about repository options, see Build, preview, and deploy apps. For an overview of how secret scanning helps protect apps, see Security and governance in the Copilot Managed Runtime.

Prerequisites

Before you begin, make sure you have:

  • An app that uses a platform-managed Git repository.
  • A local clone of the app's repository with permission to push to it. For more information, see Collaborate on an app.

Understand the rejection message

When the scan finds a credential, git push returns a rejection message that names the credential type, the pattern ID, and the location of the finding:

! [remote rejected] main -> main (SecretsScan: <credential type> (<pattern ID>) detected in src/settings.json:12)

The value in parentheses is the pattern ID. You need this ID to add an exception. For example, in General Password (PasswordContextInScript), the pattern ID is PasswordContextInScript.

If the push contains more than one finding, the message shows the number of findings and the first finding:

SecretsScan: 3 secret(s) detected (first: <credential type> (<pattern ID>) in src/settings.json:12); see .grs/secrets-allowlist.json

Resolve the first finding, and then push again to see the next one.

Resolve a real credential

Before you add an exception, determine whether the finding is a real credential or a false positive. A false positive is a value that matches a credential pattern but isn't a working credential, such as a sample value, a test fixture, or a documentation placeholder.

Important

If the finding is a real credential, don't add an exception. Deleting the credential in a later commit isn't enough, because the credential remains in the repository history.

To resolve a real credential:

  1. Rotate the credential in the service that issued it.
  2. Remove the credential from every commit in the push. For example, use git commit --amend to update the most recent commit, or git rebase to edit earlier commits.
  3. Push again.

If the finding is a false positive, add an exception.

Add an exception

  1. Copy the pattern ID from the rejection message.

  2. Create or update the .grs/secrets-allowlist.json file at the root of the repository. Add an exception that specifies the pattern ID and the file path from the rejection message. For example:

    {
      "version": 1,
      "allowlist": [
        {
          "patternId": "PasswordContextInScript",
          "path": "tests/diagnostics.test.ts",
          "reason": "Fake credentials used by a redaction unit test"
        }
      ]
    }
    
  3. Commit the file, and then push it with the rejected change:

    git add .grs/secrets-allowlist.json
    git commit -m "Allow test credentials in diagnostics test"
    git push
    

    You can also push the allow list file to the branch before you push the rejected change.

The platform reads exceptions from the commit that becomes the new tip of the branch you push. Each branch uses its own copy of the allow list file.

Allow list file format

The .grs/secrets-allowlist.json file contains a JSON object with the following properties:

Property Required Description
version No Schema version. If present, the value must be the number 1.
allowlist No Array of exceptions. If omitted, no exceptions apply.

Each exception in the allowlist array is an object with the following properties:

Property Required Description
patternId Yes Pattern ID from the rejection message, such as PasswordContextInScript or SymmetricKey512. Matching isn't case-sensitive.
path No Repository-relative path of one file, with forward slashes (/). Matching is exact and case-sensitive. Folders and wildcards aren't supported. If omitted, the exception applies to every file in the branch.
reason No Explanation of why the value is safe. Recommended for reviewers.

When you edit the allow list file, follow these rules:

  • Add one exception for each combination of pattern ID and file. An exception covers every finding of that pattern in its file, so you don't need an exception for each line.
  • Use the exact property names version, allowlist, patternId, path, and reason. Property names are case-sensitive.
  • Set path to a single string. To allow a pattern in more than one file, add one exception for each file.
  • Use standard JSON without comments or trailing commas, and save the file with UTF-8 encoding.
  • Keep the file size at or below 1 MB (1,048,576 bytes).

Caution

The platform ignores a misspelled or non-string path property, which makes the exception apply to every file in the branch.

Best practices for secret scanning exceptions

To keep exceptions narrow and reviewable, follow these practices:

  • Include a path in each exception rather than allowing a pattern in every file.
  • Add a clear reason to every exception.
  • Review changes to .grs/secrets-allowlist.json as carefully as code changes. Anyone who can push to a branch can change its exceptions.
  • Remove exceptions that you no longer need.

Troubleshoot secret scanning rejections

Use the following table to identify and resolve common causes of secret scanning rejections.

Symptom Cause Fix
SecretsScan: failed to load .grs/secrets-allowlist.json: <reason> The allow list file is invalid, for example because of malformed JSON, unsupported version (expected 1), allowlist entry missing 'patternId', or a file that exceeds the size limit. The platform rejects every push to the branch until you fix the file, even pushes with no findings. Fix the problem that the reason identifies, and then push again.
The rejection message is cut off before the pattern ID. Rejection messages are limited to 200 characters and list every check that failed. Fix the other reported problems first, and then push again.
The push is still rejected after you add an exception. The allow list file isn't in the pushed commit, the exception doesn't match the finding, or the push contains another finding. Make sure the allow list file is in the commit that you push. Check that path matches the path in the message exactly, including case, and that patternId matches the ID in the message. If the message shows a different finding, resolve that finding too.