Skip to content

fix: bound gzip decompression, sandbox media responses, drop container root, and harden CI workflows - #855

Open
cpriti-os wants to merge 2 commits into
googleapis:mainfrom
cpriti-os:fix/testbench-security-hardening
Open

cpriti-os wants to merge 2 commits into
googleapis:mainfrom
cpriti-os:fix/testbench-security-hardening

Conversation

@cpriti-os

@cpriti-os cpriti-os commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Applies six fixes to storage-testbench:

  1. Bounded gzip decompression on request bodies (testbench/common.py): Replace unbounded gzip.decompress(request.data) in handle_gzip_request with decompress_gzip_bounded (128 MiB cap, HTTP 413 on overflow, supporting concatenated gzip streams).
  2. Bounded gzip decompression on downloads (gcs/object.py): Reuse decompress_gzip_bounded for decompressive transcoding in Object.rest_media.
  3. Sandbox headers on object media downloads (gcs/object.py): Set Content-Security-Policy: sandbox and X-Content-Type-Options: nosniff on Object.rest_media responses so uploaded HTML/SVG objects cannot execute scripts on the testbench origin.
  4. Non-root container user (Dockerfile): Create and switch to a dedicated non-root testbench user instead of running the server as root.
  5. Least-privilege workflow permissions (.github/workflows/{build,docker,style}.yaml): Declare top-level permissions: { contents: read } on all GitHub Actions workflows.
  6. Pinned GitHub Actions (.github/workflows/{build,docker,style}.yaml): Pin docker/build-push-action and actions/setup-python to commit SHAs instead of mutable tags.

Testing

  • Added unit tests in tests/test_common.py (test_decompress_gzip_bounded_within_limit, test_decompress_gzip_bounded_concatenated_streams, test_decompress_gzip_bounded_exceeds_limit) and tests/test_object.py (test_rest_media_sets_sandbox_security_headers, test_rest_media_bounded_gzip_transcode).
  • Formatted with isort and black==22.3.0; verified with pytest.

…r root, and harden CI workflows

- Enforce a maximum decompressed output size (128 MiB) in handle_gzip_request
  and Object.rest_media via decompress_gzip_bounded, returning HTTP 413 if
  exceeded.
- Add Content-Security-Policy: sandbox and X-Content-Type-Options: nosniff
  headers to Object.rest_media responses.
- Run the container image as a dedicated non-root user in Dockerfile.
- Set explicit permissions (contents: read) and pin GitHub Actions to commit
  SHAs across build, docker, and style workflows.
@cpriti-os
cpriti-os requested a review from a team as a code owner November 26, 2026 05:28
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