Integrations

Security testing for AI agents with Gmail access

An AI agent connected to Gmail acts through OAuth scopes such as reading mail, sending mail and changing settings. Every inbound email is untrusted text the agent reads. Google advises choosing the most narrowly focused scope possible. We test whether a crafted email can make your agent send, forward or reveal mail it should not.

Gmail is named here as a surface we test. Names and logos belong to their owners; no customer relationship, partnership or endorsement is implied.

What can an agent do through the Gmail API?

Google's Gmail API scopes page lists what each scope allows. gmail.readonly lets an app view email messages and settings. gmail.send lets it send email on the user's behalf. gmail.compose manages drafts and sends email, and gmail.modify reads, composes and sends email. gmail.settings.basic allows seeing, editing, creating or changing email settings and filters. The full https://mail.google.com/ scope adds permanent deletion that bypasses the trash.

The sending call itself is users.messages.send, and filters are created with users.settings.filters.create. In an agent, the recipients, body and filter criteria for those calls can all come from the model.

How do Gmail actions get abused?

ActionAbuse pathClass
Read messagesAn inbound email contains instructions the agent follows when it summarizes or triages the inbox.Prompt injection
Send or replyThe agent sends other messages, attachments or a summary of the inbox to an outside address.Data exfiltration
Create filters or change settingsA filter quietly forwards, archives or labels future mail so the owner does not see it.Unsafe actions
Restricted scope where a narrower one would doAn agent that only drafts replies holds a scope that can read and send everything.Privilege escalation

Email is an unusually open channel. Anyone who knows the address can put text in front of the agent, without logging in to anything you control.

Illustrative trace

Illustrative example, not a real customer finding.

What least-privilege controls does Google document?

Google's scopes guidance says to choose the most narrowly focused scope possible, avoid requesting scopes the app does not require, and use non-sensitive scopes where they cover the feature. It classifies gmail.send as sensitive and gmail.readonly, gmail.compose, gmail.modify, gmail.settings.basic and the full mail scope as restricted, which brings additional verification requirements for public apps. It also notes that the full mail scope is only needed for immediate permanent deletion and that every other action is possible with less permissive scopes.

Scopes decide what is possible. Your own checks decide what is allowed: which recipients the agent may send to, whether it may send without a person confirming, and whether it may touch settings at all.

What do we test?

In an Agent Action Pentest we list the scopes your agent's OAuth grant holds and compare them with its task. We send crafted emails into a test mailbox the agent reads and check whether it sends, forwards, replies with other mail, creates filters or deletes messages. Testing uses mailboxes you create for the engagement, never a production inbox. Related risks: prompt injection, indirect prompt injection, excessive agency and sensitive information disclosure. Email agents built on the OpenAI Agents SDK or LangChain call Gmail through tools you write, so the recipient and confirmation checks belong there.

Agent Action Pentest: $2,500 fixed. Written report within 72 hours of access, or a full refund.

See the offer or email yaz@plaw.io

Questions

Do you need access to a real mailbox?

No. We use test mailboxes you create, with the same OAuth client and scopes your agent uses.

Which Gmail scope should an email agent use?

The narrowest one that covers its task, per Google's guidance. A drafting agent rarely needs send or settings scopes.

Do you test Gmail itself?

No. We test your agent and the code around its Gmail calls.

Related pages

Sources

  1. Google for Developers: Choose Gmail API scopes
  2. Gmail API: users.messages.send
  3. Gmail API: users.settings.filters.create
  4. OWASP GenAI LLM Top 10 2026 (published 2026-08-03)

Last reviewed: