-
Notifications
You must be signed in to change notification settings - Fork 911
fix(security): cap Retry-After sleep and sanitize mimeType in uploads #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6323e5e
6b4e832
9ae4818
8f355cc
081db71
bb77df7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@googleworkspace/cli": patch | ||
| --- | ||
|
|
||
| fix(security): cap Retry-After sleep to 60s and sanitize mimeType in multipart uploads |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -763,12 +763,17 @@ fn build_multipart_body( | |||||||||||||||||||||||
| ) -> Result<(Vec<u8>, String), GwsError> { | ||||||||||||||||||||||||
| let boundary = format!("gws_boundary_{:016x}", rand::random::<u64>()); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Determine the media MIME type from the metadata's mimeType field, or fall back | ||||||||||||||||||||||||
| let media_mime = metadata | ||||||||||||||||||||||||
| // Determine the media MIME type from the metadata's mimeType field, or fall back. | ||||||||||||||||||||||||
| // Strip CR/LF to prevent MIME header injection via user-controlled mimeType. | ||||||||||||||||||||||||
| let media_mime_raw = metadata | ||||||||||||||||||||||||
| .as_ref() | ||||||||||||||||||||||||
| .and_then(|m| m.get("mimeType")) | ||||||||||||||||||||||||
| .and_then(|v| v.as_str()) | ||||||||||||||||||||||||
| .unwrap_or("application/octet-stream"); | ||||||||||||||||||||||||
| let media_mime: String = media_mime_raw | ||||||||||||||||||||||||
| .chars() | ||||||||||||||||||||||||
| .filter(|c| !c.is_control()) | ||||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||||
|
Comment on lines
+773
to
+776
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After sanitizing
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good edge case — added a fallback to application/octet-stream if the sanitized mime ends up empty |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Build multipart/related body | ||||||||||||||||||||||||
| let metadata_json = metadata | ||||||||||||||||||||||||
|
|
@@ -1246,6 +1251,31 @@ mod tests { | |||||||||||||||||||||||
| assert!(body_str.contains("Binary data")); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[tokio::test] | ||||||||||||||||||||||||
| async fn test_build_multipart_body_sanitizes_mime_injection() { | ||||||||||||||||||||||||
| // A malicious mimeType with CRLF should be stripped to prevent | ||||||||||||||||||||||||
| // MIME header injection in the multipart body. | ||||||||||||||||||||||||
| let metadata = Some(json!({ | ||||||||||||||||||||||||
| "name": "evil.txt", | ||||||||||||||||||||||||
| "mimeType": "text/plain\r\nX-Injected: malicious" | ||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||
| let content = b"payload"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| let (body, _) = build_multipart_body(&metadata, content).unwrap(); | ||||||||||||||||||||||||
| let body_str = String::from_utf8(body).unwrap(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // After stripping CR/LF, the Content-Type line should NOT have a | ||||||||||||||||||||||||
| // line break that would create a separate injected header. | ||||||||||||||||||||||||
| // The CRLF between "text/plain" and "X-Injected" is removed, | ||||||||||||||||||||||||
| // so the value is concatenated into a single line. | ||||||||||||||||||||||||
| assert!( | ||||||||||||||||||||||||
| !body_str.contains("Content-Type: text/plain\r\nX-Injected"), | ||||||||||||||||||||||||
| "CRLF injection must not produce a separate header line" | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| // Verify the sanitized mime type appears as one continuous string | ||||||||||||||||||||||||
| assert!(body_str.contains("Content-Type: text/plainX-Injected: malicious")); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||
| fn test_build_url_basic() { | ||||||||||||||||||||||||
| let doc = RestDescription { | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.