Secret detection alerts you when an active personal access token (PAT) is exposed in your default branch. Acting on that finding is harder: revoking the token breaks dependent pipelines, and replacing it safely takes several manual steps. While the finding waits in your vulnerability report, the token stays live.
Starting in GitLab 19.6 in beta for GitLab Ultimate, you can remediate a leaked GitLab PAT directly from the vulnerability page. Select Rotate and fix, and GitLab revokes the token, stores a replacement in GitLab Secrets Manager, and uses GitLab Duo Agent Platform to open a merge request (MR) to update your CI/CD jobs. You review and merge the MR. GitLab never exposes the new token value to you or your agents.
Why leaked tokens stay active after detection
Imagine that secret detection flags an active PAT in deploy.sh:
export GITLAB_TOKEN="glpat-..."
Fixing this manually requires tracking down the token's owner, revoking it, generating a replacement with matching scopes, storing it securely, and opening MRs to update your scripts and CI/CD jobs.
Because this process is tedious, remediations often stall or go wrong:
- The finding ages: Nobody wants to break the pipeline, so the finding sits in the vulnerability report while the token remains active.
- The fix stops halfway: Someone revokes the token immediately, breaking the build. In a rush to recover, they paste a replacement into a less secure CI/CD variable.
- The new token leaks: Someone shares the replacement token in a chat thread so a teammate can configure it.
In the gap between detected and rotated, the token still works for anyone who can read the repository.
Rotate and fix in a snap
The Rotate and fix function closes this gap by combining secret detection and validity checks, GitLab Secrets Manager, and GitLab Duo Agent Platform.
When you open an active PAT finding and select AI actions > Fix with AI > Rotate and fix, GitLab:
- Revokes the leaked token and creates a replacement with the same name, scopes, and duration (reset from the rotation date).
- Stores the new value as a project secret in Secrets Manager, available to all branches and environments.
- Marks the token as inactive on the vulnerability.
- Starts a GitLab Duo Developer Flow session, which opens an MR to remove the hardcoded token and configure your CI/CD jobs to read the secret.
You review the MR, merge it, and resolve the vulnerability.
Update the code without exposing the new token
Rotation finishes before the agent starts, so GitLab Duo never sees the new token. By the time GitLab Duo reads the file to remove the hardcoded credential, the value is revoked and the replacement is safely stored in Secrets Manager. The agent receives only the vulnerability and its file location, the new secret's name, and your username so it can assign the MR to you. GitLab Duo then updates your pipeline configuration:
deploy:
secrets:
GITLAB_TOKEN:
gitlab_secrets_manager:
name: ROTATED_GITLAB_TOKEN_123
file: false
script:
- ./deploy.sh
Your script continues using GITLAB_TOKEN, which Secrets Manager injects at runtime.
What to know before you implement
- Availability: This beta feature requires GitLab Ultimate 19.6 or later. It is enabled by default on GitLab.com, available behind the
secrets_manager_pat_rotationfeature flag on GitLab Self-Managed, and not yet available on GitLab Dedicated. - Supported secret types: Rotation supports GitLab PATs, including fine-grained PATs. It doesn't yet cover other secrets that secret detection finds, such as cloud provider keys.
- Immediate and irreversible: The leaked token stops working right away, and you can't undo the rotation. Scripts outside GitLab CI/CD and jobs in other projects that used the old token need a new token, because the new secret is scoped only to the current project and its raw value cannot be retrieved.
- Ownership rules: On GitLab.com, you can rotate only your own tokens. On GitLab Self-Managed, administrators can also rotate tokens belonging to other users.
- Independent of AI: If the GitLab Duo session cannot start, GitLab still rotates the old token and stores the replacement so you can update the code manually.
For role requirements, required settings, and step-by-step instructions, see the leaked token rotation documentation.
Automate rotation across a group
Rotating tokens one by one doesn't scale across large organizations. Rotate and fix makes two API calls: the projectSecretCreateFromLeakedToken GraphQL mutation, which rotates the token and stores the secret, and a request that starts the GitLab Duo Developer Flow.
We packaged both calls into leaked-token-rotation-automation, a dependency-free Python CLI and CI/CD component that batch-rotates tokens across an entire group:
- Active vulnerability findings: Rotates active leaked PATs across your group's repositories and opens an MR for each finding. On GitLab.com, it rotates your own tokens and lists other users' tokens in the report for follow-up. On GitLab Self-Managed, an administrator can rotate every user's tokens.
- Tokens in CI/CD variables: Secret detection doesn't scan project CI/CD variables, and any project Maintainer can read a variable that isn't hidden. The tool finds GitLab PATs in those variables, rotates them, and stores the new values in Secrets Manager. If any jobs use the variable, GitLab Duo opens an MR to update them. Each token rotates itself using its own
apiorself_rotatescope, so this command also works on tokens that belong to other users. It skips group, instance, file-type, and hidden variables.
Every run defaults to dry-run mode (pass --apply to execute), stops after 10 rotations (configurable with --limit), and never includes token values in reports. See the project README for installation instructions, CI/CD component usage, and required token scopes.
Getting started
To try this out, you need GitLab Ultimate, GitLab Duo Agent Platform, and Secrets Manager, which you can evaluate with a free 30-day trial. Each rotation consumes GitLab Credits for the Developer Flow session and for the stored secret and each CI/CD job that reads it.
- Review the prerequisites and troubleshooting guide to ensure validity checks and Developer Flow are enabled. On GitLab Self-Managed, also enable the
secrets_manager_pat_rotationfeature flag. - Open an active PAT finding in your vulnerability report, select AI actions > Fix with AI > Rotate and fix, and review the resulting merge request.
- Run the
leaked-token-rotation-automationtool in dry-run mode to preview which tokens you can rotate across your group.
What's next
We’re building a migration workflow into GitLab that recreates sensitive CI/CD variables as GitLab Secrets Manager secrets, with no values to re-enter. GitLab will automatically find variables that look like credentials and apply default access policies to the ones you choose to migrate. GitLab Duo will then open a merge request that updates your pipeline configuration, so all you have to do is review and merge.





