key-…

Exposed Mailgun API Key? Here's how to detect and rotate it

Mailgun key in your code? Rotate it in API Security, then check your sending logs. Get clear steps for the fix, plus a free Trust scan to check your repo.

A Mailgun API key (historically starting with key-) authenticates to the Mailgun API and can send email through your domains and read your account data. Anyone with it can send as you and pull your sending logs. Because the key controls your whole sending setup, a leak means you should rotate it right away.

What an attacker can do with a leaked Mailgun API Key

How Mailgun API Keys get exposed

Scan your repo for exposed Mailgun API Keys - free

Trust checks the files in your repo and the JavaScript your site ships. No signup, results in about a minute.

Run a free scan →

How to rotate a leaked Mailgun API Key

  1. Go to app.mailgun.com/settings/api_security and sign in.
  2. Click the rotate (circular arrows) icon next to the private API key to generate a new one - the old key keeps working for 48 hours unless you expire it sooner.
  3. Copy the new key, update your server environment or secrets manager, and redeploy.
  4. Once your app is confirmed working on the new key, click the link to expire the old key immediately instead of waiting out the 48 hours.
  5. Rotate your webhook signing key and SMTP credentials too if they were in the same leaked file, since they don't rotate with the API key.
  6. Open Sending → Logs in the dashboard and review recent sends and recipients for mail you didn't send, then contact Mailgun support if you see abuse.

Open the Mailgun API Key dashboard →

Which Mailgun credential is it?

Mailgun has more than one credential, and they rotate in different places. Find out which one you have before you act.

  • Private API key: the main one. Rotate it first (steps above).
  • Webhook signing key and SMTP password: separate from the API key. Rotate them too if they sat in the same file.

If you want to be sure nothing went out

  • Open Sending, then Logs, and sort by newest. Look for sends you did not make.
  • Check your sending volume over the last few days. A sudden jump is a sign worth a closer look.
  • If your domain looks flagged, tell Mailgun support. They can help you recover your sending reputation.
  • Check Google Postmaster Tools for your domain's reputation, if you send to many Gmail users.

How Trust helps

Trust's repo scan looks for Mailgun keys in the key- format in your files. Run it before you push, and again after you rotate.

Other secret types to check

Keep your app safe