zeroclaw/src/gateway
Argenis 7edcd5727d
fix(channels): address critical security bugs in Gmail Pub/Sub push (#4200)
* feat(channels): add Gmail Pub/Sub push notifications for real-time email

Add GmailPushChannel that replaces IMAP polling with Google's Pub/Sub
push notification system for real-time email-driven automation.

- New channel at src/channels/gmail_push.rs implementing the Channel trait
- Registers Gmail watch subscription (POST /gmail/v1/users/me/watch)
  with automatic renewal before the 7-day expiry
- Handles incoming Pub/Sub notifications at POST /webhook/gmail
- Fetches new messages via Gmail History API (startHistoryId-based)
- Dispatches email messages to the agent with full metadata
- Sends replies via Gmail messages.send API
- Config: gmail_push.enabled, topic, label_filter, oauth_token,
  allowed_senders, webhook_url
- OAuth token encrypted at rest via existing secret store
- Webhook endpoint added to gateway router
- 30+ unit tests covering notification parsing, header extraction,
  body decoding, sender allowlist, and config serialization

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(config): fix pre-existing test compilation errors in schema.rs

- Remove #[cfg(unix)] gate on `use tempfile::TempDir` import since
  TempDir is used unconditionally in bootstrap file tests
- Add explicit type annotations on tokio::fs::* calls to resolve
  type inference failures (create_dir_all, write, read_to_string)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(channels): fix extract_body_text_plain test

Gmail API sends base64url without padding. The decode_body function
converted URL-safe chars back to standard base64 but did not restore
the padding, causing STANDARD decoder to fail and falling back to
snippet. Add padding restoration before decoding.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(channels): address critical security bugs in Gmail Pub/Sub push

- Add webhook authentication via shared secret (webhook_secret config
  field or GMAIL_PUSH_WEBHOOK_SECRET env var), preventing unauthorized
  message injection through the unauthenticated webhook endpoint
- Add 1MB body size limit on webhook endpoint to prevent memory exhaustion
- Fix race condition in handle_notification: hold history_id lock across
  the read-fetch-update cycle to prevent duplicate message processing
  when concurrent webhook notifications arrive
- Sanitize RFC 2822 headers (To/Subject) to prevent CRLF injection
  attacks that could add arbitrary headers to outgoing emails
- Fix extract_email_from_header panic on malformed angle brackets by
  using rfind('>') and validating bracket ordering
- Add 30s default HTTP client timeout for all Gmail API calls,
  preventing indefinite hangs
- Clone tx sender before message processing loop to avoid holding
  the mutex lock across network calls

---------

Co-authored-by: Giulio V <vannini.gv@gmail.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 15:33:57 +03:00
..
api_pairing.rs fix(pairing): add SQLite persistence, fix config defaults, align with plan 2026-03-24 15:17:29 +03:00
api_plugins.rs fix(plugins): integrate WASM tools into registry, add gateway routes and tests 2026-03-24 15:17:30 +03:00
api.rs fix(channels): address critical security bugs in Gmail Pub/Sub push (#4200) 2026-03-24 15:33:57 +03:00
canvas.rs fix(gateway): address critical security and reliability bugs in Live Canvas (#4196) 2026-03-24 15:33:54 +03:00
hardware_context.rs feat(hardware): add RPi GPIO, Aardvark I2C/SPI/GPIO, and hardware plugin system (#4125) 2026-03-24 15:30:43 +03:00
mod.rs fix(channels): address critical security bugs in Gmail Pub/Sub push (#4200) 2026-03-24 15:33:57 +03:00
nodes.rs feat(gateway): add dynamic node discovery and capability advertisement (#3448) 2026-03-13 18:23:48 -04:00
sse.rs feat(observer): live tool call notifications (#3221) 2026-03-11 19:07:34 -04:00
static_files.rs feat(gateway): add path_prefix for reverse-proxy deployments 2026-03-24 15:31:15 +03:00
ws.rs fix(mcp): wire MCP tools into WebSocket chat and gateway /api/tools (#4096) 2026-03-24 15:30:43 +03:00