Skip to content
XSS Write-up Advanced

The invisible Messages of Gmail

A postMessage listener in Gmail accepted messages from any origin and used the data to load an iframe with a javascript: URL, allowing an attacker to execute arbitrary code in the victim's Gmail session. The attacker could read and send emails and change passwords of accounts registered to that email.

Enguerran Gillier Follow

Published on opnsec.com

Bounty$5,000 View original

Last year, I looked for DOM XSS in Gmail website. Instead of using url params or the emails themselves as the source of the attack, I decided to use the much more discreet yet ubiquitous postMessage api.

Enguerran Gillier, on opnsec.com

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.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the message event listener did not validate the origin of incoming postMessage events and passed the message data directly into an iframe src, allowing a javascript: URL to execute.

Impact

An attacker could execute arbitrary code in the victim's Gmail page, potentially reading and sending emails and changing passwords of accounts registered to that email, though in Chrome a CSP blocked the javascript: URL and the attack worked only in IE11 and Edge at the time.

What the attacker needed

Victim uses IE11 or Edge (at the time); attacker can send postMessage to Gmail frame; attacker knows or bypasses channel name

The fix

Google fixed it by adding a check on the origin of the message containing the URL.

How it was found

  1. Use a postMessage logger extension to observe cross-frame messages in Gmail.
  2. Identify a message from hangouts.google.com to mail.google.com containing a URL with the word 'frame'.
  3. In DevTools, find the code that loads the iframe via appendChild and set a breakpoint.
  4. From the console, send a message to the frame with the same data but with a javascript: URL instead of the normal URL.
  5. Observe a CSP error in Chrome, but the payload executed in IE11 and Edge at the time.

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 write-up has not been written yet. The Original tab links to the source.

Gmail is made of many frames (separate web pages inside one tab) that talk to each other using a browser feature called postMessage. The code that received these messages did not check who sent them, so a malicious website could send a message that made Gmail load a special link starting with 'javascript:' which runs code. That let the attacker act as the victim inside Gmail.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.