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
- Sends email through your verified domains, so spam and phishing go out with your reputation behind it.
- Reads your email logs - recipients, subject lines, and delivery events - exposing your customers' addresses.
- Pulls stored data like suppression lists, mailing lists, and bounce records tied to your account.
- Runs up sending volume and can get your domain throttled, suspended, or blocklisted by inbox providers.
How Mailgun API Keys get exposed
- Committed to a public repo in a .env file, config, or deploy script.
- Exposed in a client-side bundle or mobile app instead of being called from your server.
- Pasted into a screenshot, forum post, or support chat while debugging delivery.
- Captured in server logs or an HTTP trace that recorded the request auth.
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
- Go to app.mailgun.com/settings/api_security and sign in.
- 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.
- Copy the new key, update your server environment or secrets manager, and redeploy.
- 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.
- 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.
- 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
- Twilio API Key / Auth TokenSK… / Auth Token
- Database Connection Stringpostgres:// (mysql/mongodb/redis://)
- Private Key (RSA / SSH / EC)-----BEGIN … PRIVATE KEY-----
- JWT Signing SecretHS256 signing secret
- AWS Access KeyAKIA…
- Stripe Secret Keysk_live_…