Repository navigation
Sanitize filename in Blobstore send_blob Content-Disposition header - #164
Merged
riddhi-shivhare merged 4 commits intoNov 27, 2026
Conversation
BlobstoreDownloadHandler.send_blob now removes control characters from the attachment filename and escapes backslashes and double quotes before placing it in the filename parameter. Output for filenames without those characters is unchanged. Adds tests for send_blob header generation.
In the quoted filename parameter, double quotes and backslashes are now replaced with underscores, since not all clients unescape them. Also percent-encode slashes in filename*, strip C1 control characters from text filenames, and send no filename parameter when the name is empty after stripping. Adds tests for these cases.
send_blob with save_as=True no longer raises TypeError when the BlobInfo has no filename. Documents that only ASCII control characters are removed from bytes filenames, and adds tests for the no-filename cases.
Use raw literals for the filename regexes, set the copyright year of the new test file to 2026, and add tests for a double quote in a text filename and for a trailing backslash.
shruti-mantri
approved these changes
Nov 27, 2026
1 of 2 tasks
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.
BlobstoreDownloadHandler.send_blobnow removes control characters from the attachment filename and replaces double quotes and backslashes with underscores in the filename="..." parameter. Text filenames keep their original name, percent-encoded, in filename*=. If there is no filename left, the header is plain attachment. Output for ordinary filenames is unchanged. Adds tests for send_blob header generation.