Skip to content

Sanitize filename in Blobstore send_blob Content-Disposition header - #164

Merged
riddhi-shivhare merged 4 commits into
GoogleCloudPlatform:mainfrom
riddhi-shivhare:fix-blobstore-content-disposition
Nov 27, 2026
Merged

riddhi-shivhare merged 4 commits into
GoogleCloudPlatform:mainfrom
riddhi-shivhare:fix-blobstore-content-disposition

Conversation

@riddhi-shivhare

@riddhi-shivhare riddhi-shivhare commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

BlobstoreDownloadHandler.send_blob now 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.

  • Tests pass
  • Appropriate changes to README are included in PR

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.
@riddhi-shivhare riddhi-shivhare changed the title Escape filename in Blobstore send_blob Content-Disposition header Sanitize filename in Blobstore send_blob Content-Disposition header Nov 27, 2026
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.
@riddhi-shivhare
riddhi-shivhare merged commit fd82f7d into GoogleCloudPlatform:main Nov 27, 2026
10 checks passed
@riddhi-shivhare riddhi-shivhare mentioned this pull request Nov 27, 2026
1 of 2 tasks
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.

2 participants