The Confused Mailman: Sending SPF and DMARC passing mail as any Gmail or G Suite customer
G Suite's mail routing rules allowed changing the envelope recipient without verifying ownership of the destination, and combined with an inbound gateway that skips SPF/DMARC checks, an attacker could relay spoofed emails through Google's backend so they pass strict SPF and DMARC policies. This enabled sending email as any Gmail or G Suite customer, bypassing anti-spoofing protections.
Published on ezh.es
Due to missing verification when configuring mail routes, both Gmail’s and any G Suite customer’s strict DMARC/SPF policy may be subverted by using G Suite’s mail routing rules to relay and grant authenticity to fraudulent messages. This is notably not the same as classic mail spoofing of yesteryear in which the From…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
G Suite (now Google Workspace) administrators can configure mail routing rules for their domain under Settings for Gmail → Default routing. These rules apply to inbound mail before it is processed by the rest of Google's infrastructure, and they can add custom headers, rewrite the subject line, or change the envelope recipient.
The bug described here abuses two G Suite features together: the routing rule that changes the envelope recipient, and the inbound gateway setting. The result is that a message which is plainly spoofed when it arrives at Google's border is re-sent by Google's own backend, and therefore passes SPF and DMARC for the impersonated domain, provided that domain is itself a Gmail or G Suite customer.
This is not classic From header spoofing. Classic spoofing is blocked by SPF and DMARC. Here the attacker sends mail as any other user or G Suite customer while still passing even the most restrictive SPF and DMARC rules.
Setup
The researcher used a personal G Suite domain, [email protected], as the attacker-controlled domain. The victim account was a university G Suite mailbox on a domain the researcher did not control, [email protected]. The impersonated domain was google.com, chosen because its DMARC policy is p=reject, so any SPF violation should cause the message to be dropped outright.
The proof of concept used administrative access to a personal G Suite domain to create routing rules and configure an inbound gateway, and the message arrived via a MailChannels relay. The impersonated domain was also a G Suite customer.
Finding it
While exploring the G Suite administrator console, the researcher found the Default routing option under Settings for Gmail, which allows global inbound mail routing rules. Among the available actions were applying custom headers, modifying the subject line, and changing who the email should be sent to before the rest of Google's infrastructure processes it.

The last option, shown as Change envelope recipient, was the interesting one: it lets the administrator specify an arbitrary recipient and causes Google's backend to resend the email to someone else. G Suite accepts that recipient value without validating that the administrator owns either the destination address or the destination domain.
The immediate concern was SPF and DMARC. If incoming mail, including spoofed mail, could be redirected through Google's backend, the resent message would no longer look spoofed under SPF and DMARC, as long as the victim also treats Google as an approved sender.
Exploitation
Step 1: redirect spoofed mail through the routing rule
The first attempt was simply to send a spoofed email through the routing rules. This worked against domains that had no SPF/DMARC or used a weaker soft-fail or quarantine policy. It failed against domains using DMARC's hardened reject policy: the spoofed messages were dropped at Google's border mail servers by SPF/DMARC enforcement before the routing rule could act on them. Since most worthwhile impersonation targets use p=reject, this looked like a dead end.
Step 2: add an inbound gateway to skip the border checks
The workaround was the inbound gateway setting in the G Suite admin panel. Google's documentation describes it as follows (emphasis in the original):
An inbound mail gateway is a server that all your incoming mail passes through. The gateway typically processes the mail in some way, such as archiving it or filtering spam. It then passes the mail to the mail server that delivers the mail to recipients.
[...]
You configure the inbound gateway setting to identify the gateway's IP address or range of addresses. Gmail skips performing SPF checks on IP addresses included in the Gateway IPs list. If an inbound gateway is set up, the DMARC check should be done by the inbound gateway and will be skipped for messages arriving from listed hosts.
That note is the key. Messages that would otherwise be rejected for SPF and DMARC failures, including spoofed messages, can be injected into Google's mail infrastructure and then processed by the custom routing rules.
Step 3: chain the two features
By combining the missing recipient validation in the mail routing rules with an inbound gateway, the researcher caused Google's backend to resend mail for any domain, even though the message was clearly spoofed when it was received. This is useful to an attacker when the impersonated victim also uses Gmail or G Suite, because the message sent by Google's backend will pass both SPF and DMARC: the victim's domain, by virtue of using G Suite, is configured to allow Google's backend to send mail from it. Because the message originates from Google's backend, it is also likely to have a lower spam score and so be filtered less often.
Step 4: the proof of concept
The researcher sent a message from a google.com address to the university G Suite mailbox, using the personal G Suite domain as the attacker domain. Sending to another G Suite account demonstrated that Google's mail filtering and anti-spam techniques did not block or detect the attack. The following is the message as seen by the end victim, with irrelevant headers removed:
Delivered-To: [email protected]
Received: by [redacted] with SMTP id z22csp1120956oti;
Fri, 3 Apr 2020 15:41:27 -0700 (PDT)
X-Received: by [redacted]:: with SMTP id bo21mr10227430pjb.58.1585953687701;
Fri, 03 Apr 2020 15:41:27 -0700 (PDT)
ARC-Authentication-Results: i=2; mx.google.com;
arc=pass (i=1);
spf=pass (google.com: domain of [email protected] designates [redacted] as permitted sender) [email protected];
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com
Return-Path: <[email protected]>
Received: from mail-sor-f69.google.com (mail-sor-f69.google.com. [[redacted]])
by mx.google.com with SMTPS id o11sor13151518plk.43.2020.04.03.15.41.27
for <[email protected]>
(Google Transport Security);
Fri, 03 Apr 2020 15:41:27 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates [redacted] as permitted sender) client-ip=[redacted];
Authentication-Results: mx.google.com;
arc=pass (i=1);
spf=pass (google.com: domain of not_malicious_[email protected] designates [redacted] as permitted sender) [email protected];
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com
X-Original-Authentication-Results: mx.google.com;
spf=softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) [email protected]
X-Received: by [redacted]:: with SMTP id j11mr3579141plk.236.1585953687402;
Fri, 03 Apr 2020 15:41:27 -0700 (PDT)
ARC-Authentication-Results: i=1; mx.google.com;
spf=softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) [email protected]
Return-Path: <[email protected]>
Received: from chocolate.birch.relay.mailchannels.net (chocolate.birch.relay.mailchannels.net. [[redacted]])
by mx.google.com with ESMTPS id s12si7121157pgq.251.2020.04.03.15.41.26
for <[email protected]>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Fri, 03 Apr 2020 15:41:26 -0700 (PDT)
Received-SPF: softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) client-ip=[redacted];
X-Sender-Id: dreamhost|x-authsender|[email protected]
Received: from relay.mailchannels.net (localhost [[redacted]]) by relay.mailchannels.net (Postfix) with ESMTP id 574F47E11C3 for <[email protected]>; Fri,
3 Apr 2020 22:41:26 +0000 (UTC)
From: [email protected]
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\))
Date: Fri, 3 Apr 2020 16:41:24 -0600
Subject: Google Bounce Test
Message-Id: <[email protected]>
X-Mailer: Apple Mail (2.3608.80.23.2.2)
Hey this is a spoofed email!
The first notable header is Google's debug ARC analysis of the message when it was first received from the inbound gateway at the attacker's relay address, where it detected the SPF and DMARC failure but did not act on it because of the inbound gateway configuration:
ARC-Authentication-Results: i=1; mx.google.com;
spf=softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) [email protected]
The second is the result when the victim receives the message and Google re-evaluates it, determining that both SPF and DMARC pass under the strict p=REJECT policy:
Authentication-Results: mx.google.com;
arc=pass (i=1);
spf=pass (google.com: domain of [email protected] designates [redacted] as permitted sender) [email protected];
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com
A completely illegitimate message from a highly trusted domain with strong SPF and DMARC configurations was delivered directly to the victim's inbox without any warning:


Root cause
The mistake is missing verification when configuring mail routes. The Change envelope recipient action accepts an arbitrary recipient without checking that the administrator owns the destination address or domain. Combined with the inbound gateway setting, which by design skips SPF checks and defers DMARC to the gateway for listed hosts, an attacker can inject a spoofed message and have Google's backend re-send it.
SPF and DMARC authenticate the sending IP, not the visible From header. Because the resent message leaves from Google's backend, and the impersonated domain is itself a G Suite customer that authorises Google to send its mail, the checks pass. The spoofed message was accepted because the inbound gateway setting skips SPF checks and defers DMARC for listed hosts, and was then resent by Google's backend, which is an authorised sender for the impersonated domain.
Impact
An attacker with a G Suite domain can send mail as any other user or G Suite customer, passing even the most restrictive SPF and DMARC rules. The victim must use Gmail or G Suite for the impersonated domain to be an authorised sender. Because the message originates from Google's backend, it is also likely to have a lower spam score and be filtered less often. The proof of concept delivered a spoofed google.com message, under a p=reject policy, straight to a G Suite inbox with no warning.
Fix
Google stated that a series of mitigations based on return-path modification and anti-abuse mechanisms were deployed shortly after the post went live. The author added an update that the issue was patched within seven hours of publication. The report does not describe the code changes themselves.
What happened, in plain words
Email has a trust problem. When a message arrives in your inbox, the computer that received it has no built-in way to know whether the message really came from the address written in its From line. Anyone can type any address there. Two systems, called SPF and DMARC, were bolted onto email to fix this. They let the owner of a domain publish a list of computers that are allowed to send mail for that domain, and they let receiving mail servers check the sending computer against that list. If the sending computer is not on the list, the message can be rejected.
This report describes a bug in Google's G Suite (now called Google Workspace) that let an attacker get around both SPF and DMARC. The attacker could send a message that looked like it came from any Gmail or G Suite customer, and the message would still pass the strictest SPF and DMARC checks. The trick was to use two G Suite settings together: a mail routing rule that changes who an incoming message is delivered to, and an "inbound gateway" setting that tells Google to skip its own SPF checks for certain computers.
The attacker sent a spoofed message to their own G Suite domain. Google's border servers would normally reject it, but the inbound gateway setting told them to skip the check. The routing rule then told Google's backend to resend the message to someone else. Because the resent message left from Google's own servers, and the impersonated domain was also a G Suite customer that trusts Google's servers, the message passed SPF and DMARC on the way out. It landed in the victim's inbox with no warning.
The researcher reported the bug to Google on 3 April 2020. Google accepted it, then marked it as a duplicate. On 1 August 2020 the researcher noted no evidence of progress or mitigations and the issue was still reproducible. The researcher set a disclosure deadline, and the bug was published on 19 August 2020. Google stated that mitigations based on return-path modification and anti-abuse mechanisms were deployed shortly after the post went live. The author added an update that the issue was patched within seven hours of publication.
A quick detour into mail spoofing
If you already know what SPF and DMARC are, you can skip this section. If not, read on, because the whole bug depends on them.
Email is very old technology. It comes from a time when the internet was just research universities and government labs. If someone misused a computer back then, you could call them or their supervisor and tell them off personally. As the internet grew and more adversaries got online, trusting systems like email needed to change.
One of email's growing pains is that neither the content nor the sender of a message is authenticated by default. When a mail server receives a message, there is no clear way to be sure the message actually came from the address it claims. In other words, anyone could claim they have a message from [email protected] and mail servers had few formal or rigorous means to call their bluff. This was an enormous problem because of phishing and scams: users trust and rely on email domains to be sure they are talking to who they think they are.
Enter SPF and DMARC
The solution was to bolt on new controls that let the operator of a domain tell mail servers which IP addresses are allowed to send mail from their domain. An IP address is the numeric address of a computer on the internet, a bit like a postal address for a building. Because email runs over TCP, a protocol that sets up a reliable connection between two computers, the sending IP address cannot easily be forged. So a receiving mail server can compare the sender's IP address against the authorised senders list. If the sender's IP is not on the list, the mail server can confidently reject the message and keep fraudulent email out of its users' inboxes.
The key takeaway, which matters for this bug, is that SPF and DMARC use a sender's IP to protect against spoofed and fraudulent messages. In other words, if the message originates from an approved source, it is considered legitimate under SPF and DMARC. The check is about where the message came from, not about what the From line says.
The bug
While poking around on the G Suite administrator console, the researcher noticed they could create global mail routing rules for inbound mail on their domain using the "Default routing" option under "Settings for Gmail". These rules allowed them to, among other things, apply custom headers, modify the subject line, or change who the email should be sent to before it is processed by the rest of Google's infrastructure.

The last option, shown as "Change envelope recipient", was especially interesting because it let the administrator specify an arbitrary recipient and cause Google's backend to resend the email to someone else. The "envelope recipient" is the address the mail system actually delivers to, which is not always the same as the address written in the To line of the message. Worryingly, the recipient value is accepted by G Suite without any validation to ensure the administrator owns either the destination email address or the destination domain. This behaviour immediately set off alarm bells, because this buggy feature would let the attacker redirect incoming emails, including spoofed emails, to someone else using Google's backend so that it no longer appears to be spoofed according to SPF and DMARC, if the victim also designates Google as an approved sender.
Unfortunately, this initial procedure of sending a spoofed email through routing rules did not entirely work. The researcher was able to get Google's backend to redirect and redeliver spoofed emails using domains that either did not have SPF/DMARC or used a weaker soft-fail or quarantine policy. But domains that used DMARC's hardened reject policy failed to deliver, because the spoofed emails were being dropped at Google's border mail servers due to SPF/DMARC enforcement. This was disappointing because most targets worth impersonating use p=reject, so they would seem not vulnerable. Was this the end of the journey? It was not.
In all seriousness, the workaround was not terribly complicated. By digging around in the G Suite admin panel a bit more, the researcher found a section to configure what Google called an "inbound gateway" for the domain. Google provides a succinct explanation of this feature in their docs (emphasis in the original):
An inbound mail gateway is a server that all your incoming mail passes through. The gateway typically processes the mail in some way, such as archiving it or filtering spam. It then passes the mail to the mail server that delivers the mail to recipients.
[...]
You configure the inbound gateway setting to identify the gateway's IP address or range of addresses. Gmail skips performing SPF checks on IP addresses included in the Gateway IPs list. If an inbound gateway is set up, the DMARC check should be done by the inbound gateway and will be skipped for messages arriving from listed hosts.
The final note on SPF and DMARC with inbound gateways was just what the researcher was looking for. It would allow them to inject messages that would otherwise be flat out rejected due to SPF and DMARC failures, such as spoofed messages, into Google's mail infrastructure, and have them processed by the custom mail routing rules.
By chaining together both the broken recipient validation in G Suite's mail routing rules and an inbound gateway, the researcher was able to cause Google's backend to resend mail for any domain, even though the message was clearly spoofed when it was received. This is advantageous for an attacker if the victim they intend to impersonate also uses Gmail or G Suite, because the message sent by Google's backend will pass both SPF and DMARC: the victim's domain, by virtue of using G Suite, is configured to allow Google's backend to send mail from it. Additionally, since the message originates from Google's backend, it is also likely that the message will have a lower spam score and so should be filtered less often.
Proof of concept
In this proof of concept, the researcher used a personal G Suite domain ([email protected]) to send a seemingly legitimate email from a google.com address to a university's G Suite email on a domain the researcher did not control ([email protected]). They chose to send to another G Suite account to demonstrate that Google's strong mail filtering and anti-spam techniques do not block or detect this attack. They also chose to impersonate google.com because its DMARC policy is set to p=reject, so any violation of SPF, regardless of the SPF policy, should result in the message simply being dropped with prejudice.
The following is a slightly cleaned up email from the end victim's perspective, with various irrelevant headers removed to improve readability:
Delivered-To: [email protected]
Received: by [redacted] with SMTP id z22csp1120956oti;
Fri, 3 Apr 2020 15:41:27 -0700 (PDT)
X-Received: by [redacted]:: with SMTP id bo21mr10227430pjb.58.1585953687701;
Fri, 03 Apr 2020 15:41:27 -0700 (PDT)
ARC-Authentication-Results: i=2; mx.google.com;
arc=pass (i=1);
spf=pass (google.com: domain of [email protected] designates [redacted] as permitted sender) [email protected];
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com
Return-Path: <[email protected]>
Received: from mail-sor-f69.google.com (mail-sor-f69.google.com. [[redacted]])
by mx.google.com with SMTPS id o11sor13151518plk.43.2020.04.03.15.41.27
for <[email protected]>
(Google Transport Security);
Fri, 03 Apr 2020 15:41:27 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates [redacted] as permitted sender) client-ip=[redacted];
Authentication-Results: mx.google.com;
arc=pass (i=1);
spf=pass (google.com: domain of not_malicious_[email protected] designates [redacted] as permitted sender) [email protected];
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com
X-Original-Authentication-Results: mx.google.com;
spf=softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) [email protected]
X-Received: by [redacted]:: with SMTP id j11mr3579141plk.236.1585953687402;
Fri, 03 Apr 2020 15:41:27 -0700 (PDT)
ARC-Authentication-Results: i=1; mx.google.com;
spf=softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) [email protected]
Return-Path: <[email protected]>
Received: from chocolate.birch.relay.mailchannels.net (chocolate.birch.relay.mailchannels.net. [[redacted]])
by mx.google.com with ESMTPS id s12si7121157pgq.251.2020.04.03.15.41.26
for <[email protected]>
(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Fri, 03 Apr 2020 15:41:26 -0700 (PDT)
Received-SPF: softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) client-ip=[redacted];
X-Sender-Id: dreamhost|x-authsender|[email protected]
Received: from relay.mailchannels.net (localhost [[redacted]]) by relay.mailchannels.net (Postfix) with ESMTP id 574F47E11C3 for <[email protected]>; Fri,
3 Apr 2020 22:41:26 +0000 (UTC)
From: [email protected]
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.80.23.2.2\))
Date: Fri, 3 Apr 2020 16:41:24 -0600
Subject: Google Bounce Test
Message-Id: <[email protected]>
X-Mailer: Apple Mail (2.3608.80.23.2.2)
Hey this is a spoofed email!
This block is the raw text of the email as the victim's mail server received it. Every line before the blank line is a header: a labelled piece of metadata about the message. The blank line separates the headers from the body, which here is just the sentence "Hey this is a spoofed email!".
Delivered-Tois the address the message was actually delivered to.Receivedlines are added by each mail server the message passed through, newest at the top. They record which server handed the message to which, and when.X-Receivedlines are similar, added by Google's internal systems.ARC-Authentication-Resultsrecords the results of authentication checks, in a chain. ARC is a way of preserving those results as a message is forwarded or resent, so later servers can see what earlier servers found. Thei=1andi=2are positions in that chain.Return-Pathis the address that bounces should go to. It is set by the last server that handled the message.Received-SPFrecords the result of the SPF check for a particular hop.Authentication-Resultsrecords the results of SPF, DMARC and ARC checks for the message as a whole.Fromis the visible sender address, the one the victim sees in their mail client.Subject,Date,Message-Id,Mime-Version,Content-Type,Content-Transfer-EncodingandX-Mailerare ordinary message metadata.
The first notable header in this message is Google's debug ARC analysis of the message when it was received for the first time from the inbound gateway at the attacker's relay address, where it detected the SPF and DMARC failure but did not act on it due to the inbound gateway configuration:
ARC-Authentication-Results: i=1; mx.google.com;
spf=softfail (google.com: domain of transitioning [email protected] does not designate [redacted] as permitted sender) [email protected]
This says that at the first hop, Google checked SPF and got softfail: the sending computer was not on the list of computers allowed to send mail for google.com. A softfail is a weak failure, a hint that something is wrong rather than a hard rejection. Here the SPF failure was detected but not acted on, because of the inbound gateway configuration.
The second is when the victim ([email protected]) receives the message and Google re-evaluates it and determines that both SPF and DMARC pass with the strict p=REJECT policy:
Authentication-Results: mx.google.com;
arc=pass (i=1);
spf=pass (google.com: domain of [email protected] designates [redacted] as permitted sender) [email protected];
dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com
This says that at the final hop, Google checked SPF again and got pass: the sending computer, [redacted], is on the list of computers allowed to send mail for google.com. It also checked DMARC and got pass, with the policy p=REJECT and sp=REJECT (the policy for subdomains), and dis=NONE meaning no action was taken because nothing failed. The arc=pass means the ARC chain was intact. In plain words: the message that was clearly spoofed when it arrived was now, on the way out, coming from a computer that google.com itself authorises. So the checks passed.
This results in a completely illegitimate message from a highly trusted domain with strong SPF and DMARC configurations being delivered directly to the victim's inbox without any sort of warning:


Glossary
- SPF (Sender Policy Framework): a system where a domain owner publishes a list of computers (by IP address) that are allowed to send mail for that domain, so receiving servers can check the sender.
- DMARC (Domain-based Message Authentication, Reporting and Conformance): a system built on top of SPF that tells receiving servers what to do when a message fails the check, for example reject it, quarantine it, or let it through.
- IP address: the numeric address of a computer on the internet, like a postal address for a building.
- TCP: a protocol that sets up a reliable connection between two computers, which is why the sending IP address cannot easily be forged.
- Spoofing: sending a message that claims to come from an address or domain that the sender does not control.
Fromheader: the visible sender address shown in a mail client.- Envelope recipient: the address the mail system actually delivers to, which is not always the same as the address in the
Toline. - Header: a labelled piece of metadata attached to an email, such as
SubjectorReceived. - G Suite / Google Workspace: Google's paid suite of business tools, including Gmail on a custom domain, with an administrator console for settings.
- Administrator console: the web interface where a domain administrator configures settings for their organisation.
- Mail routing rule: a rule that tells a mail system to modify or redirect incoming messages, for example by changing the recipient or adding a header.
- Inbound gateway: a server that all incoming mail passes through before reaching the final mail server; Gmail can be told to skip SPF checks for listed gateway IP addresses and to leave DMARC to the gateway.
p=reject: a DMARC policy that tells receiving servers to reject messages that fail the check.soft-fail: a weak SPF failure, a hint that something is wrong rather than a hard rejection.quarantine: a DMARC policy that tells receiving servers to put failing messages in a quarantine or spam folder rather than reject them outright.- ARC (Authenticated Received Chain): a way of preserving the results of authentication checks as a message is forwarded or resent, so later servers can see what earlier servers found.
- Relay: a mail server that passes a message on to another server rather than delivering it directly.
- Spam score: a number a mail system assigns to a message to estimate how likely it is to be spam; lower scores are filtered less often.
- Return-path: the address that bounces should go to, set by the last server that handled the message.
- Duplicate (in bug tracking): a report that is marked as describing the same issue as an existing report.
- Disclosure: making the details of a security bug public.
- Mitigation: a change that reduces the impact of a bug, which may not be a full fix.
- Patch: a code change that fixes a bug.