A crates.io API token lets whoever holds it publish new versions of the Rust crates your account owns. Because other projects pull those versions in as dependencies, a stolen token is a supply chain problem, not only an account problem: a malicious release of a popular crate can reach many builds before anyone notices. Revoke the token first, then check what was published while it was exposed.
Check your GitHub account for leaked secrets — free
- Provider
- crates.io
- Severity
- Critical
- Impact
- Source code and build access
- Checked live by LeakWatch
- No
What a crates.io API token looks like
crates.io API tokens start with cio, followed by a long run of letters and digits:
cio…XXXX crates.io API token (masked)
Cargo can read the token from the CARGO_REGISTRY_TOKEN environment variable, or store it in a credentials file after cargo login. The file lives in the Cargo home folder and is easy to copy into a dotfiles repository by mistake. The prefix is short, so the value on its own tells you little. What identifies it is the place it appears: a token next to the word crates in a configuration file or script.
How crates.io API tokens get leaked
- A copied Cargo credentials file. A home folder backup or dotfiles repository that includes the file Cargo writes after login.
- Publish commands in scripts. A release script that passes the token on the command line, so it is saved in shell history or echoed in a CI log.
- CI variables printed by accident. A debug step that prints the environment, or a pipeline that writes the token into a file that is later archived as an artifact.
- Docker build contexts. A token copied into an image build and left in a layer that is then pushed to a public registry.
- Shared snippets. A token pasted into a question about a failed publish, a forum post or an issue, with the real value left in.
What to do in the first hour
- Revoke the token. Open the account settings, go to the API tokens section, find the token by its name and delete it. Do this before anything else, because a leaked token keeps publishing until it is gone.
- Check what was published. Open each crate you own on the registry and review the version list for releases you did not make. Note the publish dates and compare them with the exposure window.
- Check the owners. Confirm that the owner list of each crate contains only people and teams you expect. Cargo can list owners for a crate, so you can script this check across your crates.
- Yank what you did not release. Yanking stops new projects from resolving the version. The registry generally does not let you delete a published version, so yanking and then publishing a fixed version is the usual response. Tell your users if a release may have run in their builds.
- Create a narrower replacement. Recent registry token scopes let you limit a token to publishing updates, or to the crate names a pipeline needs. Give CI only the scope it uses and set an expiry date.
- Clean the repository and the logs. Remove the value from files, check CI logs and any archived artifacts, then decide whether to rewrite history. For the full order of steps, see I accidentally pushed an API key to GitHub.
Not sure what else leaked from the same pipeline? Run a free scan.
Revoke it at the Rust registry
Open the account settings on the registry, find the API tokens section and delete the token that leaked. A deleted token stops working for new requests, including publishes started with it. Make sure you are signed in to the account that created the token, since tokens belong to a single user. Tokens owned by a team or a former maintainer may need to be deleted by that person. The exact menu labels can change, and this guide has not yet been checked against the live page, so read the labels carefully before deleting.
How LeakWatch detects it
The rule is called “Crates.io API Token”. It looks for the word crates, optionally followed by io, _, . or -, placed near an assignment, and then a value that begins with cio and continues with 32 letters or digits. A value stored under a generic name such as a CARGO_TOKEN variable is not reported by this rule, so search your files for that name by hand as well. The severity is critical. This type is not checked live: LeakWatch does not send the token to crates.io.
LeakWatch detects this format but does not check it live: it can tell you the key is exposed, not whether it still works. Assume it does until you have revoked it.
FAQ
Can someone publish a crate with my token?
Yes, if the token has publish scope and your account owns the crate. The token acts as your account, so every crate you maintain is exposed, not only the one in the file where the value was found.
Is yanking a version enough?
Not by itself. A yanked version stops being picked up by new dependency resolution, but code that was already downloaded stays on machines that used it. Yank the bad version, publish a fixed one, and tell your users to update.
How should CI get the token instead?
Store it in your CI provider’s secret store, expose it only to the job that publishes, and give it the narrowest scope and an expiry date. Never put it in a committed file or in a command that will be printed.