Skip to content

fix(sites): bind screenshot preview keys to their rule - #15031

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/screenshot-key-binding
Oct 27, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/screenshot-key-binding

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Ephemeral keys that skip preview authorization now carry the hostname and deployment they were issued for. The router ignores their preview grants on any other rule, and hostname overrides are limited to the issued hostname.

Pairs with appwrite/docker-browser#25 (in appwrite/browser:0.3.10), which keeps the key off redirects to other origins.

Lint, PHPStan and the touched unit tests passed locally before rebasing on main; e2e runs in CI.

Part of appwrite-labs/cloud#6857

Ephemeral keys that skip preview authorization now carry the hostname and
deployment they were issued for. The router ignores their preview grants on
any other rule, and hostname overrides are limited to the issued hostname.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change binds ephemeral preview keys to a custom-domain hostname and a specific deployment, tightening authorization for the screenshots preview flow. The Key class carries new optional claims and validates them in isBoundTo; the router in app/controllers/general.php now checks preview-key binding before granting preview routes, and app/init/resources/request.php gates preview hostname resolution. The Screenshots worker mints keys with the new claims, and tests cover both the unit and e2e surfaces.

Files Change
src/Appwrite/Auth/Key.php Adds optional hostname/deploymentId claims to key generation and decoding; isBoundTo requires a non-empty matching claim when the corresponding rule is set.
app/controllers/general.php Router consults the preview-key binding grants only when the key is bound to the requested hostname/deployment.
app/init/resources/request.php Registers the preview hostname resource used to resolve and gate preview requests.
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Worker mints preview keys including the new binding claims for the target deployment.
tests/unit/Auth/KeyTest.php Unit tests for claim round-tripping and isBoundTo binding behavior.
tests/e2e/Services/Sites/SitesCustomServerTest.php E2E test creating a preview key bound to a deployment's domain and asserting the preview authorization path.

Reviewed commit: 5de7d4e

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 27, 2026
@ghost

ghost commented Oct 27, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No actionable defects found; the preview grants are scoped to the issued hostname and deployment, with unit and E2E coverage for the behavior.

Ephemeral screenshot keys now include the hostname and deployment they were issued for. The router applies their preview grants only to the matching rule, and hostname overrides are restricted to the bound hostname; unit and E2E coverage exercise the binding behavior.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 6
File Change
app/controllers/general.php Rejects router preview grants when the key is not bound to the resolved rule.
app/init/resources/request.php Restricts production hostname overrides to the hostname carried by the key.
src/Appwrite/Auth/Key.php Decodes hostname and deployment claims and exposes rule-binding checks.
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Adds rule hostname and deployment claims to screenshot preview keys.
tests/e2e/Services/Sites/SitesCustomServerTest.php Uses bound preview keys and adds E2E checks for cross-rule rejection.
tests/unit/Auth/KeyTest.php Adds unit coverage for matching and mismatched key-to-rule bindings.

Reviewed 5de7d4e · 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/screenshot-key-binding (after).

Metric Before After Change
🚀 Requests/sec 197.71 196.93 ⚪ -0.4%
⏱️ Latency P50 85.81 ms 87.77 ms ⚪ +2.3%
⏱️ Latency P95 205.97 ms 204.45 ms ⚪ -0.7%
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 87.77 204.45 12,540 196.93 -1.52
Account 165.73 295.2 660 11.04 -26.68
TablesDB 84.05 156.21 6,820 109.86 -7.89
Storage 84.19 190.34 3,300 54.47 +4.47
Functions 123.63 241.7 1,760 29.69 +6.12

Top API waits (after)

API request Max wait (ms)
functions.create 508.21
account.name.update 431.57
functions.variables.create 399.65
storage.files.update 373.82
account.prefs.update 373.4

@ChiragAgg5k
ChiragAgg5k merged commit ee83bc1 into main Oct 27, 2026
69 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/screenshot-key-binding branch October 27, 2026 19:19
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