How Material Security Uncovered a Vulnerability in the Gmail API
The Gmail API endpoint for retrieving attachment content did not apply sufficient authorization checks, so any authenticated Google user with a valid attachmentId could retrieve the contents of any attachment from any Gmail-based account. The messageId parameter was also not validated, and attachmentIds remained valid even after the associated application was deauthorized.
Published on material.security
Example H2
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 users.messages.attachments.get method looked up the attachment by attachmentId without verifying that the caller had access to the mailbox or message it belonged to, and it also failed to validate the messageId parameter.
Impact
Any authenticated Gmail user with a valid attachmentId could read the contents of the attachment it pointed to, regardless of permissions; however, attachmentIds are long enough that brute-forcing is impractical, so the vulnerability could not be exploited at scale.
What the attacker needed
A valid Google account; a valid attachmentId
The fix
Google fixed the issue by adding proper authorization checks to the attachment retrieval endpoint, as the report states Google moved quickly to fix it.
How it was found
- Authenticate to the Gmail API with a valid Google account.
- Call users.messages.get on a message to obtain an attachmentId.
- Call users.messages.attachments.get with the userId, messageId and attachmentId to retrieve the attachment content.
- Supply a valid attachmentId from a mailbox the caller should not access, with an arbitrary messageId value, to retrieve that attachment's data.
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.
When you use a web service like Gmail through its API, the service is supposed to check that you are allowed to see the data you ask for. Here, one specific API call that fetches email attachments skipped that check, so anyone with a valid attachment identifier could read attachments belonging to other people's mailboxes. The identifiers are long and random, so guessing them is impractical, but anyone who obtained one (for example a third-party app that had been granted access) could use it.
What is IDOR?
One user can read or change another user's data, usually by changing an identifier the server trusts without checking who is asking. One of the most paid bug classes on web programs.