fix(security): honor relay-declared sender_type in Google Chat adapter to prevent BOT filter bypass#22107
Closed
memosr wants to merge 1 commit into
Closed
Conversation
…r to prevent BOT filter bypass
Collaborator
|
Merged via PR #22432. Your commit was cherry-picked onto current main with your authorship preserved in git log; we added 5 regression tests (3 unit on |
Contributor
Author
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
The Google Chat adapter (
plugins/platforms/google_chat/adapter.py)supports three envelope formats — Pub/Sub native, Cloud Function
direct, and a "Format 3" relay/flat shape used by custom Cloud Run
relays. Format 3 hardcodes
sender.type = "HUMAN"regardless of theactual sender:
This breaks the downstream BOT self-filter at line 1145:
Two related issues result:
1. Bot-loop DoS
If the Cloud Run relay forwards every message in a space (including
the bot's own replies — easy to misconfigure), the bot will re-process
its own output indefinitely:
type = "HUMAN"→ BOT filter doesn't fireThe dedup guard at line 1139 doesn't always catch this either, because
relay envelopes can have empty
message_name(the relay synthesizesan
event_typerather than carrying amessages/...resource path).2. Allowlist impersonation (relay-trust-boundary attack)
GOOGLE_CHAT_ALLOWED_USERSis checked at line 1537 againstuser_id = sender_email or sender_name. In Format 3,sender_emailcomes directly from the envelope:
A caller with write access to the Pub/Sub topic the relay publishes
to (a GCP project member with the right role, or a compromised relay)
can craft an envelope claiming to be any allowlisted user:
{ "event_type": "MESSAGE", "sender_email": "allowlisted@company.com", "text": "<malicious command>", "space_name": "spaces/TARGET" }The adapter accepts the spoofed sender, marks it
HUMAN, and theallowlist check passes. The relay's trust boundary is implicit but
the adapter doesn't enforce it.
Fix
Honor the relay's declared
sender_typefield (mirrors what Format 1and Format 2 already do via
sender.type). Default to"HUMAN"forbackward compatibility when the field is absent:
A correctly configured relay can now mark its forwarded bot replies
as
sender_type: "BOT"and the existing BOT self-filter at line 1145will reject them. Operators with relays that already mark sender type
need no behavior change; relays that don't are safe by default thanks
to the
"HUMAN"fallback.The relay setup documentation should call out that the relay must
forward
sender.typefrom the original Chat event into the envelopeas
sender_type, but that's a docs change rather than a code change.Type of Change
Checklist
"HUMAN"matches previous behaviorsender.type"HUMAN"or"BOT", falls back otherwisesender_type