Skip to content

security: fix OData injection, path-segment injection, token file perms, error verbosity#3

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781199334-security-hardening
Open

security: fix OData injection, path-segment injection, token file perms, error verbosity#3
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1781199334-security-hardening

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Fixes 5 security issues found during a full codebase audit:

Critical — OData injection (Outlook server)

outlook_read_thread interpolates thread_id directly into a $filter clause. A crafted value like ' or 1 eq 1 or ' breaks out of the filter and returns arbitrary messages. Similarly, outlook_search interpolates query into $search="…" — an embedded " escapes the phrase.

Fix: new _sanitize.py module adds escape_odata_string() (doubles ') and escape_odata_search() (strips ").

Critical — path-segment injection (both servers)

All 20 endpoints interpolate user-supplied IDs into URL paths (/messages/{message_id}/modify, etc.). A crafted ID containing / or ? redirects the HTTP request to an unintended API endpoint.

Fix: safe_id(value, name) validates IDs match ^[A-Za-z0-9_\-+=.]+$ before interpolation. Added to every tool function that accepts an ID parameter.

High — token files world-readable

gmail_token.json and outlook_token.json are written via Path.write_text() inheriting umask (~0o644). Any local user can read refresh tokens.

Fix: TOKEN_PATH.chmod(0o600) after every write.

High — verbose error messages

RuntimeError(f"gmail error {status}: {r.text}") returns the full upstream body, which may contain email content or internal error details.

Fix: truncate r.text to 200 chars in both gmail.py and graph.py.

Medium — unbounded top

outlook_search accepted arbitrary top values. Now clamped to [1, 1000].

Link to Devin session: https://app.devin.ai/sessions/929ae96deee24a03b03b82e2890d3921
Requested by: @fafaisland

…missions, and error verbosity

- Add _sanitize.py to both servers with safe_id(), escape_odata_string(), escape_odata_search()
- Validate all user-supplied IDs (message_id, thread_id, draft_id, etc.) against path-traversal chars
- Escape OData filter value in outlook_read_thread to prevent filter injection
- Strip double-quotes from outlook_search query to prevent $search breakout
- Restrict token file permissions to 0o600 (owner-only) in both auth modules
- Truncate error response bodies to 200 chars to avoid leaking sensitive API data
- Clamp outlook_search top parameter to [1, 1000]

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant