Skip to content

fix(cdn): refuse cache paths with dot segments - #14887

Merged
Meldiron merged 1 commit into
mainfrom
fix/cdn-cache-path-dot-segments
Oct 23, 2026
Merged

Meldiron merged 1 commit into
mainfrom
fix/cdn-cache-path-dot-segments

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

Summary

Domain::validatePaths (used by Cache::purgePaths() and by every adapter's purgePaths()) now refuses a cache path that has a . or .. segment, including the percent-encoded forms (%2e, %2E, .%2e, …).

Fastly purges a path by appending it to its API route (/purge/{domain}{path}), and HTTP clients resolve dot segments before sending, so such a segment would move the request, with its Fastly-Key, off the purge route. No cached URL contains a dot segment, so refusing them changes nothing for real paths. Dots inside a segment (/app.js, /.well-known/…, /..png) and anything in the query or fragment are still accepted.

Tests

  • DomainTest: dot-segment paths (plain, at start/middle/end, before a query, encoded and half-encoded) are refused; dotted names, query strings and fragments are accepted. These cases fail without the change.
  • FastlyTest: a traversal path is refused before any request is sent.
  • Package suite (116 tests), pint, PHPStan and Rector with the package configs pass.

🤖 Generated with Claude Code

Purge paths are joined onto provider API routes, and HTTP clients resolve
`.` and `..` segments before sending, so a path carrying one could move a
token-bearing request off the purge route. No cached URL contains such a
segment, so Domain::validatePaths refuses them, percent-encoded or not;
dots elsewhere in a path, query or fragment are unaffected.

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

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR hardens the CDN package against path traversal by rejecting . and .. path segments (raw, percent-encoded, or mixed-case) in Domain::validatePaths() before paths are joined onto provider API routes, with unit coverage added for the validator and the Fastly adapter.

Files Change
packages/cdn/src/Domain.php Normalizes encoded dot segments and rejects raw or encoded ./.. segments during path validation.
packages/cdn/tests/DomainTest.php Adds unit cases covering accepted and rejected dot-segment path variants.
packages/cdn/tests/Cache/Adapter/FastlyTest.php Extends Fastly adapter tests to exercise the new path validation.
packages/cdn/README.md Documents the path validation behavior.

Reviewed commit: db2cbfa

@ghost

ghost commented Oct 23, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The validator blocks the described traversal inputs, preserves the documented valid path cases, and has focused regression coverage.

Domain::validatePaths() now rejects literal and percent-encoded . and .. path segments while leaving dots in other segments and query/fragment data alone. The README documents the path restriction, and regression coverage checks both the validator and Fastly's pre-request rejection behavior.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
packages/cdn/README.md Documents that purge paths cannot contain dot segments.
packages/cdn/src/Domain.php Adds dot-segment detection to cache path validation.
packages/cdn/tests/Cache/Adapter/FastlyTest.php Checks that traversal paths are rejected before a request is sent.
packages/cdn/tests/DomainTest.php Adds coverage for literal and encoded dot segments and valid dotted paths.

Reviewed db2cbfa · 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

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

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

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/cdn-cache-path-dot-segments (after).

Metric Before After Change
🚀 Requests/sec 206.25 214.62 ⚪ +4.1%
⏱️ Latency P50 82.33 ms 79.94 ms ⚪ -2.9%
⏱️ Latency P95 198.69 ms 191.08 ms ⚪ -3.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 79.94 191.08 13,623 214.62 -7.61
Account 155.35 289.38 717 11.94 -12.83
TablesDB 76.42 138.25 7,409 120.04 -30.17
Storage 76.31 176.33 3,585 59.61 +4.2
Functions 117.46 243.39 1,912 32.43 +24.56

Top API waits (after)

API request Max wait (ms)
account.prefs.update 475.03
account.name.update 441.64
functions.create 439.51
functions.variables.update 411.75
tablesdb.rows.create 355.43

@Meldiron
Meldiron merged commit c3af82f into main Oct 23, 2026
120 of 122 checks passed
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…t-segments

fix(cdn): refuse cache paths with dot segments

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