fix(security): cap Retry-After sleep and sanitize mimeType in uploads#448
fix(security): cap Retry-After sleep and sanitize mimeType in uploads#448anshul-garg27 wants to merge 1 commit intogoogleworkspace:mainfrom
Conversation
Two security fixes: 1. Cap Retry-After header value to 60 seconds. A hostile or compromised API server could send Retry-After: 4294967295 to hang the CLI process indefinitely. This is especially dangerous for AI agent workflows where the process runs unattended. 2. Strip CR/LF from user-supplied mimeType before embedding it in the multipart MIME header. A mimeType like "text/plain\r\nX-Evil: injected" could inject arbitrary MIME headers into the upload body.
🦋 Changeset detectedLatest commit: 12f4e07 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces two critical security enhancements to the CLI's agent-facing attack surfaces. It addresses a potential denial-of-service vulnerability by capping Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces two important security hardening fixes. The first change caps the Retry-After sleep duration to prevent a potential denial-of-service attack, and the second sanitizes the mimeType in multipart uploads to prevent MIME header injection. The implementations for both fixes are correct. I've added one comment regarding the test for the Retry-After cap to make it more robust.
| const MAX_RETRY_DELAY_SECS: u64 = 60; | ||
| // A server sending Retry-After: 999999 should be capped to 60 | ||
| let server_value: u64 = 999_999; | ||
| let capped = server_value.min(MAX_RETRY_DELAY_SECS); | ||
| assert_eq!(capped, 60); |
There was a problem hiding this comment.
There are a couple of improvements for this test:
- The constant
MAX_RETRY_DELAY_SECSis redefined here. It's also defined insend_with_retry. This can lead to inconsistencies if one is updated and the other is not. Consider defining it at the module level and reusing it in both places. - The assertion on line 71 uses the magic number
60. It would be better to use the constantMAX_RETRY_DELAY_SECSto make the test more robust to changes.
| const MAX_RETRY_DELAY_SECS: u64 = 60; | |
| // A server sending Retry-After: 999999 should be capped to 60 | |
| let server_value: u64 = 999_999; | |
| let capped = server_value.min(MAX_RETRY_DELAY_SECS); | |
| assert_eq!(capped, 60); | |
| const MAX_RETRY_DELAY_SECS: u64 = 60; | |
| // A server sending Retry-After: 999999 should be capped to 60 | |
| let server_value: u64 = 999_999; | |
| let capped = server_value.min(MAX_RETRY_DELAY_SECS); | |
| assert_eq!(capped, MAX_RETRY_DELAY_SECS); |
Summary
Two security hardening fixes for agent-facing attack surfaces:
1. Cap
Retry-Aftersleep to 60 seconds (Critical)A hostile or compromised API server can return
Retry-After: 4294967295in a 429 response, causing the CLI process to sleep for ~136 billion years. This is a denial-of-service vector, especially dangerous in unattended AI agent workflows where the process runs without human supervision.Fix: Add
.min(60)cap on the parsedRetry-Aftervalue insend_with_retry().2. Sanitize
mimeTypein multipart upload headers (High)The user-supplied
mimeTypefield from--jsonbody metadata is embedded directly into a MIMEContent-Typeheader:A crafted
mimeTypeliketext/plain\r\nX-Injected: maliciouscould inject arbitrary MIME headers into the outbound multipart request body.Fix: Strip
\rand\ncharacters frommedia_mimebefore header construction.Test plan