Skip to content

fix(s3): send the same content headers as storage view on object GET - #14634

Merged
abnegate merged 11 commits into
mainfrom
cursor/s3-object-get-content-headers-fb91
Oct 22, 2026
Merged

abnegate merged 11 commits into
mainfrom
cursor/s3-object-get-content-headers-fb91

Conversation

@abnegate

Copy link
Copy Markdown
Member

What does this PR do?

Object GET and HEAD on the S3-compatible gateway now send the same content headers as GET /v1/storage/buckets/{bucketId}/files/{fileId}/view:

  • Content-Security-Policy: script-src 'none';
  • X-Content-Type-Options: nosniff
  • Content-Disposition: attachment for SVG and for any type outside the storage-mimes allow-list (the same list the view endpoint uses to decide what can be rendered inline)

Stored Content-Disposition metadata and the response-content-disposition / response-content-type query overrides cannot switch those types to inline. Safe types (for example image/png) still honor response-content-disposition.

S3 routes stay in the s3 group so AWS clients keep the existing CORS expose list and SigV4 auth. The S3 init hook applies the same baseline Server, X-Content-Type-Options, and HSTS headers that the api/web/graphql init hook already sets. Range responses (206), ETag, and presigned URLs are unchanged aside from the extra headers.

Test Plan

  • Added testGetObjectContentHeaders in tests/e2e/Services/Storage/S3CustomServerTest.php:
    • GET and HEAD of SVG and HTML objects assert CSP, nosniff, and attachment
    • response-content-type / response-content-disposition cannot make those objects inline
    • stored Content-Disposition: inline from a COPY REPLACE cannot make SVG inline
    • PNG can still use response-content-disposition=inline
    • switching a PNG to application/xhtml+xml via query is forced to attachment
    • ranged GET (206) still includes the headers and ETag
  • Existing S3 multipart and overwrite tests cover normal downloads

Related PRs and Issues

  • Header parity with the storage view endpoint

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?
Open in Web Open in Cursor 

Object GET and HEAD now send CSP and nosniff, and force attachment for types the storage view endpoint does not render inline. Query and stored Content-Disposition overrides cannot change that. The S3 init hook applies the same baseline Server, nosniff, and HSTS headers other API routes already send.

Co-authored-by: Jake Barnby <[email protected]>
@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → cursor/s3-object-get-content-headers-fb91 (after).

Metric Before After Change
🚀 Requests/sec 218.95 223.41 ⚪ +2%
⏱️ Latency P50 77.96 ms 78.58 ms ⚪ +0.8%
⏱️ Latency P95 189.91 ms 174.72 ms 🟢 -8%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 78.58 174.72 13,680 223.41 -15.19
Account 146.68 264.17 720 12.53 -24.75
TablesDB 77.13 144.91 7,440 124.57 +10.3
Storage 71.19 160.99 3,600 61.91 -18.66
Functions 106.96 198.52 1,920 33.73 -42.51

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 410.89
account.name.update 396.46
functions.variables.create 321.82
functions.create 308.07
account.get 298.57

@abnegate
abnegate marked this pull request as ready for review October 22, 2026 00:48
@luxor-code-review

luxor-code-review Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Unescaped filename in Content-Disposition header — Get.php:351

This PR hardens the new S3-compatible object GET endpoint so responses always carry safe content headers, and extends the e2e SigV4 helper to sign extra headers plus a test asserting the new behavior.

Files Change
src/Appwrite/Platform/Modules/S3/Http/S3/Get.php Adds applyContentHeaders forcing X-Content-Type-Options: nosniff and an attachment Content-Disposition with the stored object name.
src/Appwrite/Platform/Modules/S3/Http/Init.php Establishes the S3 module header baseline used by the gateway response path.
tests/e2e/Services/Storage/S3CustomServerTest.php Extends the SigV4 signing helper with a headers parameter and adds coverage asserting the enforced content headers on GET.

Reviewed commit: d17f08d

@ghost

ghost commented Oct 22, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The content-type and disposition decisions remain safe across GET, HEAD, 304, and range responses, with no actionable defects found.

The S3 object GET/HEAD responses now apply storage-view security headers and force downloads for SVG and MIME types outside the storage allow-list, while preserving safe-type disposition overrides. The storage view response also emits sanitized, UTF-8-compatible filenames in Content-Disposition.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 5
File Change
src/Appwrite/Platform/Modules/S3/Http/Init.php Adds the shared baseline Server, nosniff, and HTTPS HSTS headers to S3 requests.
src/Appwrite/Platform/Modules/S3/Http/S3/Get.php Applies content security and disposition rules to object responses, including conditional and ranged responses.
src/Appwrite/Platform/Modules/Storage/Http/Buckets/Files/View/Get.php Sanitizes quoted filenames and adds an RFC 5987 UTF-8 filename parameter.
tests/e2e/Services/Storage/S3CustomServerTest.php Covers S3 content headers, overrides, HEAD, conditional and range responses, and stored disposition metadata.
tests/e2e/Services/Storage/StorageBase.php Adds storage-view coverage for quoted and UTF-8 filenames.

Reviewed 94deaba · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds a Content-Disposition/content-type enforcement layer to the S3 gateway GET path with matching e2e coverage, but the forced attachment filename is interpolated into the header unescaped.

Key findings

  • 🟡 Unescaped filename in Content-Disposition header — Get.php:351

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · Looks good to merge. Summary

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

Client sessions cannot update a bucket that only allows create, and the S3 gateway looks objects up by the stored name. Use the project key for the rename and assert the sanitized Content-Disposition on the storage view path.

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

A matching If-None-Match still needs Content-Disposition, CSP, and
nosniff so a revalidated cached response keeps those values.

Co-authored-by: Jake Barnby <[email protected]>
@cursor

cursor Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

@hansi-codes review

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@abnegate
abnegate merged commit ccaaa08 into main Oct 22, 2026
43 checks passed
@abnegate
abnegate deleted the cursor/s3-object-get-content-headers-fb91 branch October 22, 2026 06:52
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…content-headers-fb91

fix(s3): send the same content headers as storage view on object GET

(cherry picked from commit ccaaa08)
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