Skip to content

fix(s3): refuse bucket names that are not valid IDs - #15210

Merged
loks0n merged 1 commit into
mainfrom
fix/s3-bucket-name-validation
Nov 2, 2026
Merged

loks0n merged 1 commit into
mainfrom
fix/s3-bucket-name-validation

Conversation

@loks0n

@loks0n loks0n commented Nov 2, 2026

Copy link
Copy Markdown
Member

What

The S3 gateway's CreateBucket (PUT /v1/s3/<bucket>) stored whatever name the URI held as the bucket document $id. Database::createDocument doesn't run the UID check on $id, so names such as .. or .... were accepted.

The bucket ID is a segment of every object's storage path (Base::path(): <root>/<bucketId>/<fileId>.<ext>), and the S3 device resolves .. segments and turns \ into /. So:

  • in bucket .., a new object was written to <uploads>/<fileId>.<ext>, outside app-<project>/
  • in bucket ..\..\builds, it was written under a different storage root

The object name was always a fresh unique ID, so an existing file couldn't be overwritten. Reads go through the file document's own path, so another project's files couldn't be read either.

Fix

  • createBucket() refuses a name that fails UID and returns 400 without writing anything.
  • bucket() treats an existing invalid name as NoSuchBucket, so a bucket created before this fix can't be used to write again.

Test

S3CustomServerTest::testCreateBucketRefusesPathSegments checks .., .... and ..\..\builds. For each name, creating the bucket returns 400, putting an object through it returns 404, and the name is absent from ListBuckets afterwards.

I watched it fail on the current main S3 module (PUT /v1/s3/..%2F returned 200, expected 400) and pass with this change. Both runs were against a local stack.

🤖 Generated with Claude Code

The S3 gateway created a bucket document for any name in the URI, and the
bucket ID is a segment of each object's storage path. A bucket named `..`
put new objects one level above the project's upload directory, and the S3
device also turns `\` into `/`, so `..\..\builds` reached another storage
root. Create now refuses such names, and lookups treat an existing one as
missing so no further object can be written through it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR hardens the S3-compatible gateway by validating the bucketId against the UID validator before resolving a bucket, returning 404 for invalid identifiers instead of letting them flow into path construction.

Files Change
src/Appwrite/Platform/Modules/S3/Http/S3/Base.php Validates the bucket ID in bucket() with the UID validator and rejects invalid IDs early.
tests/e2e/Services/Storage/S3CustomServerTest.php Adds an e2e case asserting traversal-style bucket IDs are rejected on the S3 server path.

The validation follows the existing Appwrite ID rules, so no legitimate bucket created through the REST API is affected.

Reviewed commit: 2295300

@loks0n loks0n self-assigned this Nov 2, 2026
@ghost

ghost commented Nov 2, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The validation blocks path-like IDs at both bucket creation and resolution, and the regression test checks the externally observable outcomes.

The S3 gateway now validates bucket IDs before creating bucket documents and before resolving existing buckets. The E2E test covers rejected path-like IDs, failed object writes through those names, and their absence from bucket listings.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/S3/Http/S3/Base.php Validate bucket IDs on creation and lookup, returning the existing invalid-argument or no-such-bucket errors as appropriate.
tests/e2e/Services/Storage/S3CustomServerTest.php Add coverage for path-segment and backslash bucket names across create, object-put, and list operations.

Reviewed 2295300 · 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 S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Security rules

WARNING (2 new) — review signal only; does not fail the job.

php.appwrite.weak-secret-env-default (2)

Secret-like env var (SECRET, KEY, PASS, PASSWORD, TOKEN) read with a non-empty literal default. If the variable is unset the process silently runs with a shared, guessable value. Default to '' and fail or disable the feature when it is empty.

  • src/Appwrite/Auth/EncryptionKey.php:40 — EncryptionKey::version()
    • What's wrong: _APP_OPENSSL_KEY_CURRENT falls back to '1' when unset, so every install that does not set it shares that value.
    • How to fix: Read System::getEnv('_APP_OPENSSL_KEY_CURRENT', '') and fail or disable the dependent connection when it is empty; keep the example value in .env / app/config/variables.php.
  • src/Appwrite/Auth/EncryptionKey.php:64 — EncryptionKey::accepted()
    • What's wrong: _APP_OPENSSL_KEY_OLDEST falls back to '1' when unset, so every install that does not set it shares that value.
    • How to fix: Read System::getEnv('_APP_OPENSSL_KEY_OLDEST', '') and fail or disable the dependent connection when it is empty; keep the example value in .env / app/config/variables.php.
6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • 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 Nov 2, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/s3-bucket-name-validation (after).

Metric Before After Change
🚀 Requests/sec 186.15 201.34 🟢 +8.2%
⏱️ Latency P50 93.34 ms 85.99 ms 🟢 -7.9%
⏱️ Latency P95 218.35 ms 200.53 ms 🟢 -8.2%
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 85.99 200.53 12,540 201.34 -17.82
Account 159.9 286.42 660 11.41 -42.65
TablesDB 82.55 152.57 6,820 112.32 -17.13
Storage 82.87 192.58 3,300 55.75 -2.89
Functions 122.13 232.93 1,760 30.6 -16.56

Top API waits (after)

API request Max wait (ms)
account.name.update 424.05
functions.create 375.91
storage.buckets.create 352.37
account.prefs.update 347.72
storage.files.create 346.38

@loks0n
loks0n merged commit f8a3fa9 into main Nov 2, 2026
34 checks passed
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