Skip to content

fix(sites): bind the screenshot key to its project - #14977

Merged
ChiragAgg5k merged 8 commits into
mainfrom
fix/domains-org-hardening
Nov 3, 2026
Merged

ChiragAgg5k merged 8 commits into
mainfrom
fix/domains-org-hardening

Conversation

@lohanidamodar

@lohanidamodar lohanidamodar commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Scopes the screenshot worker's ephemeral key to the project it was minted for. This complements #15031, which binds the key's preview grants to its rule in the router.

  • The worker adds projectId and projectSequence claims, drops projectCheckDisabled, and sends x-appwrite-project, so the key decodes only for its own project.
  • The worker captures only rules on Appwrite-owned domains (owner=Appwrite), never a custom domain. (Not filtering on trigger: V22 backfilled legacy rules as manual.)

Test Plan

  • SitesCustomServerTest::createPreviewKey now mints keys the way the worker does (project-bound, no projectCheckDisabled), and every keyed request sends x-appwrite-project. The preview-branding, rule-binding and deployment-status tests still pass with these keys.
  • Screenshot capture itself is exercised by the existing Sites E2E screenshot assertions.
  • Local: pint, phpstan on changed files, composer refactor:check.

Related PRs and Issues

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? (No API metadata changes.)

The screenshot worker's ephemeral key now carries the project ID and
sequence and is sent with the project header, instead of skipping the
project check. The router honours a key's preview, status and banner
bypasses only for the rule's own project, and the worker captures only
Appwrite-generated deployment rules.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Screenshots query excludes legacy rules migrated as manual · Screenshots.php:123–129 · unchanged line

// src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
123	                Query::equal('trigger', ['deployment']),
124	                Query::equal('owner', ['Appwrite']),
125	            ]);
126	
127	            if ($rule->isEmpty()) {
128	                throw new PermanentFailure('Rule for deployment not found');
129	            }

The rule lookup in the Screenshots worker now requires trigger = 'deployment' and owner = 'Appwrite' (src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php:123-124). The V22 migration backfills every legacy rule with trigger = 'manual' (src/Appwrite/Migration/Version/V22.php:332), while setting owner = 'Appwrite' only for domains ending in the functions/sites domain (line 357). A legacy Appwrite-owned deployment rule therefore has owner='Appwrite' but trigger='manual', which the narrowed query can never match, so the worker throws PermanentFailure('Rule for deployment not found') and screenshots for existing sites silently stop after migration.


The change hardens the preview key flow: ephemeral JWT keys now carry a projectId claim, the router rejects keys whose project doesn't match the resolved rule, and the Screenshots worker sends x-appwrite-project on its requests so projectCheckDisabled is no longer needed. The rule lookup in the worker was also narrowed to trigger/owner filters, which breaks resolution for rules backfilled by the V22 migration with trigger='manual'.

Files Change
app/controllers/general.php Adds a projectId-mismatch check that nulls $apiKey so foreign-project preview keys fall through to the /auth/preview redirect.
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Issues a project-scoped JWT, sends x-appwrite-project, drops projectCheckDisabled, and narrows the rule query with trigger/owner filters.
tests/e2e/Services/Sites/SitesCustomServerTest.php Adds negative assertions that a projectId-bound key unlocks the site preview and foreign/claim-less keys redirect.

Reviewed commit: cddb2bc

@ghost

ghost commented Oct 27, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The screenshot worker captures only Appwrite-owned deployment rules and sends a project-bound ephemeral key with the project header; the key is signed with the active configured encryption key. The Sites E2E tests use project-bound preview keys and cover preview branding, rule binding, unbound-key rejection, and canceled deployments.

Latest changes: The new commits switch screenshot-key signing from the hard-coded V1 secret to EncryptionKey::current(), allowing captures to use the active key during key rotation.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php Restricts screenshot rule selection to Appwrite-owned domains, sends project-bound ephemeral-key headers, and signs keys with the active encryption key.
tests/e2e/Services/Sites/SitesCustomServerTest.php Creates project-bound preview keys and exercises preview branding, rule binding, unbound-key rejection, and canceled-deployment behavior.

Reviewed the commits since 7e2c909 · 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 Oct 27, 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 Oct 27, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/domains-org-hardening (after).

Metric Before After Change
🚀 Requests/sec 216.93 219.55 ⚪ +1.2%
⏱️ Latency P50 78.39 ms 77.66 ms ⚪ -0.9%
⏱️ Latency P95 185.63 ms 190.93 ms ⚪ +2.9%
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 77.66 190.93 13,680 219.55 +5.3
Account 165.48 306.8 720 12.33 +29.56
TablesDB 74.35 147.36 7,440 122.69 +8.48
Storage 72.31 159.81 3,600 60.7 -26.09
Functions 116.66 222.22 1,920 33.2 +6.55

Top API waits (after)

API request Max wait (ms)
account.name.update 445.75
account.prefs.update 410.06
functions.variables.create 349.1
functions.create 332.55
functions.delete 328.93

@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

@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

Copy link
Copy Markdown
Member

@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

…ning

# Conflicts:
#	src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
#	tests/e2e/Services/Sites/SitesCustomServerTest.php
lohanidamodar and others added 3 commits November 1, 2026 07:19
…ning

# Conflicts:
#	src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
…ning

# Conflicts:
#	src/Appwrite/Platform/Modules/Functions/Workers/Screenshots.php
@ChiragAgg5k
ChiragAgg5k merged commit 8dce088 into main Nov 3, 2026
39 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/domains-org-hardening branch November 3, 2026 07:40
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.

3 participants