Mailgun misconfiguration leads to email snooping and postmaster@-access on email.mg.gitlab.com
A Mailgun configuration issue allowed an attacker to claim the domain email.mg.gitlab.com because it was not added as a separate domain in Mailgun, and a CNAME record pointed to Mailgun. The attacker could then create a mailing list for [redacted] and receive emails sent to that address.
Originally disclosed on HackerOne
- Fixed in under an hour
- Disclosed after 56 days
Summary by the program
@fransrosen Identified a vulnerability in our Mailgun configuration that allowed mail to several of our subdomains to be leaked. @fransrosen included enough information in the report so that we were able to immediately correct the issue and report the problem to Mailgun. Thanks @fransrosen for one of the more interesting vulnerability reports we've seen!
The report
Hi,
Previously a blog post went out about Uber's Sendgrid issues: http://blog.pentestnepal.tech/post/149985438982/reading-ubers-internal-emails-uber-bug-bounty
Also, a report from @uranium238 went out due to a similar issue with Slack (that I know uses Mailgun): https://hackerone.com/reports/163938
Now, by reasons I do not know, this actually has some issues still unpatched by Mailgun, which in combination with a misconfiguration, currently exposes at least email.mg.gitlab.com.
The problem lies in this issue:
- You add the domain
mg.gitlab.comto Mailgun - Mailgun asks you to add a MX record to
mg.gitlab.com - You add that, then Mailgun also tells you that to get tracking you need to add a CNAME from
email.mg.gitlab.comto mailgun.org as well. - What is missing here, is for you to actually add
email.mg.gitlab.comto your account as a separate domain by itself. By not doing this, anyone can add this domain to their account. - You probably later on remove the MX from
mg.gitlab.comagain, but the CNAME is still there foremail.mg.gitlab.com
The problem with missing out on #4 above is how DNS CNAMEs works. If you have a CNAME pointing to another domain, this CNAME will actually inherit the MX-records from the other domain. This basically means that your email.mg.gitlab.com is now listed with MX-records from Mailgun:
$ host email.mg.gitlab.com
email.mg.gitlab.com is an alias for mailgun.org.
mailgun.org has address 173.203.37.113
mailgun.org mail is handled by 10 mxb.mailgun.org.
mailgun.org mail is handled by 10 mxa.mailgun.org.
Due to this, I can claim this domain as mine in Mailgun:

And due to this, I can now create a mailing list called [email protected] with Access-level: everyone:

I'll add my own email as a recipient:

I'll now try and see if I can receive emails to [email protected]:

The logs of Mailgun will show me the routing:

And my inbox now have the emails sent to [email protected]:

Since postmaster can be used to issue certificates for these domains, and since no one but you should have access to the whitelisted SSL-issuing aliases (ref: https://wiki.mozilla.org/CA:Problematic_Practices#Email_Address_Prefixes_for_DV_Certs)
I recommend that you:
- Add the both domains
email.mg.gitlab.comto your Mailgun account. I have removed it again so you can take it back, remember that anyone can right now claim it themselves.. - Keep in mind that all domains pointing to Mailgun (MX/CNAME) needs to be claimed by you, even the sub sub domains of the ones already in Mailgun. So make sure that no other domains pointing to Mailgun are missing inside your Mailgun account.
Regards, Frans
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The domain email.mg.gitlab.com was not added as a separate domain in Mailgun, and because a CNAME pointed to Mailgun, it inherited Mailgun's MX records, allowing anyone to claim it.
Impact
An attacker could receive emails sent to [redacted], and postmaster can be used to issue certificates for the domain.
What the attacker needed
Mailgun account; domain not claimed in Mailgun
The fix
The domain email.mg.gitlab.com should be added to the Mailgun account, and all domains pointing to Mailgun via MX or CNAME should be claimed.
How it was found
- Add the domain mg.gitlab.com to Mailgun and set up the required MX record.
- Add a CNAME record from email.mg.gitlab.com to mailgun.org for tracking.
- Do not add email.mg.gitlab.com as a separate domain in Mailgun.
- An attacker can then claim email.mg.gitlab.com in their own Mailgun account.
- The attacker creates a mailing list for [redacted] with access level 'everyone'.
- The attacker adds their own email as a recipient and receives emails sent to [redacted]
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Mailgun is an email service. When you set up a domain with Mailgun, you add DNS records so Mailgun can send and receive email for you. If you forget to add a subdomain like email.mg.gitlab.com to your Mailgun account, someone else can add it to their own account and start receiving emails sent to that subdomain.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.