Safeguard
Security Guides•

In what order should you rotate secrets after a malicious package?

Rotate the secrets with the widest access first, starting with publish and cloud credentials. A practical order, plus how to check each one for misuse.

Safeguard Security Team
4 min read

Rotate in order of blast radius: credentials that can publish or deploy code first, then cloud and infrastructure keys, then third party service tokens, then everything else the job could read. Rotating in a random order, or rotating the oldest first, leaves your most powerful secret live while you work through the list.

Why order matters

A malicious install script or build step runs with whatever the job could read. If the attacker holds a copy of your secrets, every minute a powerful one stays valid is a minute they can use it. GitHub's hardening guidance says the goal of rotation is to shrink how long a stolen secret stays usable, and that a secret printed in a log should be treated as exposed and rotated. During an incident, apply the same logic to every secret the job could reach.

The order to follow

PrioritySecret typeWhy first
1Package registry publish tokens and signing keysLets an attacker ship malware under your name
2Deploy credentials and cloud keysDirect path to production
3Source control tokens with write accessLets an attacker alter code and workflows
4Database, queue and storage credentialsData access
5Third party SaaS tokensNarrower, but often hold customer data
6Read only tokens and test keysLowest impact

Steps

  1. Freeze the pipeline so no new job starts and reads fresh secrets.
  2. List every secret the affected jobs could read: repository, environment and organization secrets, plus anything fetched from a vault at run time.
  3. Create the replacement first, deploy it, then revoke the old one. This avoids an outage that tempts people to skip revocation.
  4. For each old credential, check its audit log for use you do not recognise before or after the incident window.
  5. Prefer short lived credentials going forward. npm now supports only granular tokens, and you set an expiry when you create one, so choose a short one.
  6. Record the time each secret was revoked. You will need it for the incident timeline.

What rotation does not fix

New secrets do not remove a foothold. If the attacker changed a workflow file, added a deploy key or a webhook, or planted a script in a cache, the new secret will be read by the same malicious code. Review recent changes to workflow files and to repository settings before you release the pipeline. See how to check whether a leaked key was used and what to do about a secret in git history.

A note on shared secrets

One credential used by many pipelines is the hardest to rotate, because every consumer breaks at once. Plan for it: list the consumers, schedule the change, and update them in a batch right after creating the replacement. If you find a shared deploy key during the incident, put splitting it into per pipeline credentials on the hardening backlog. Smaller credentials mean smaller incidents and simpler rotations.

Try it yourself

Click through it at your own pace, or open it full screen.

Click through the monitoring flow and notice how a new advisory on a package you already use surfaces without a fresh scan.

Quick check

Should I revoke first or create the new secret first?

Create and deploy the replacement first when you can do it in minutes, then revoke. If the old secret is known to be abused right now, revoke immediately and accept the outage.

Do I need to rotate secrets the job could not read?

Not for this incident. Scope the list to what the affected jobs could access, and rotate on your normal schedule for the rest.

Safeguard can scan your dependencies and generate an SBOM so you can see which projects pulled the affected package. You can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.