Skip to content

fix(previews): validate authorize parameters - #14013

Merged
Meldiron merged 2 commits into
mainfrom
fix/preview-authorize-params
Sep 30, 2026
Merged

Meldiron merged 2 commits into
mainfrom
fix/preview-authorize-params

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

The preview /_appwrite/authorize route appended its path query parameter to the host origin without checking its shape, and derived the scheme from the Referer/Origin header rather than from the request itself.

  • Require path to be root-relative. The proxy builds it from request_uri (+ query string), so that is the only shape it ever legitimately has; an empty value defaults to /, anything else is rejected with 400 general_argument_invalid.
  • Take the protocol from $request->getProtocol(), the same source the proxy uses when it builds the origin it hands to the console, so the cookie's Secure flag and the redirect match the request that actually arrived.
  • e2e: assert the exact location on the success path and cover the rejected shapes.

Test Plan

  • composer lint on both files, composer analyze app/controllers/general.php and composer refactor:check pass locally.
  • tests/e2e/Services/Sites/SitesCustomServerTest::testPreviewDomain extended with the success location assertion and a set of rejected path values; runs in CI.

Related PRs and Issues

  • None

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? — not applicable, internal route outside the SDK spec.

🤖 Generated with Claude Code

`/_appwrite/authorize` appended the `path` query parameter to the host
origin as-is and took the scheme from the referer. Require the path to be
root-relative, matching what the proxy builds it from, default it to `/`,
and use the request protocol so the cookie flags and the redirect agree
with the request that reached the host.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@ghost

ghost commented Sep 30, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The new guard resolves the previously reported server-error case, and the added tests exercise the fix and default behavior.

The preview authorization route validates redirect paths as root-relative strings, defaults empty paths to /, and derives the redirect scheme and cookie security flag from the request protocol. The e2e coverage checks exact redirect locations and rejection of malformed paths without setting cookies or redirect headers.

Latest changes: The newest commits add a string-type guard for array-valued paths and e2e cases for array rejection and missing or empty path defaults.

Verdict New comments Fixed Still open
✅ Approved 0 1 0
📂 Walkthrough · 2
File Change
app/controllers/general.php Use the request protocol and validate root-relative, single-line string paths before setting cookies and redirecting.
tests/e2e/Services/Sites/SitesCustomServerTest.php Assert exact success redirects, missing and empty path defaults, and rejection of malformed strings and array-valued paths.
✅ Fixed since the last review · 1
  • Reject array-valued paths before calling string functions · app/controllers/general.php:1650

Reviewed the commits since 81b1874 · 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 · Looks good to merge. Summary

Comment thread app/controllers/general.php Resolved
@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical risk] Validates path parameter in preview authorization endpoint.

The PR appears safe to merge.

Summary

The PR validates preview authorization paths, uses the request protocol for redirects, and extends e2e coverage for accepted and rejected paths.

Reviews (2) · Last reviewed commit: "fix(previews): reject non-string authori..."

Comment thread app/controllers/general.php Resolved
A `path[]=` query hands `getParam()` an array, which the string checks
would trip over; reject it with the same 400 as any other invalid path.
Also assert that a missing or empty path redirects to the site root.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

@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

✨ Benchmark results

Comparing main (before) → fix/preview-authorize-params (after).

Metric Before After Change
🚀 Requests/sec 198.17 200.07 ⚪ +1%
⏱️ Latency P50 87.27 ms 85.48 ms ⚪ -2.1%
⏱️ Latency P95 201.73 ms 200.86 ms ⚪ -0.4%
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.48 200.86 12,540 200.07 -0.88
Account 156.24 303.53 660 11.17 -15.21
TablesDB 82.18 158.26 6,820 111.52 -11.24
Storage 81.4 182.73 3,300 55.59 +12.62
Functions 124.19 241.38 1,760 30.19 +3.15

Top API waits (after)

API request Max wait (ms)
account.name.update 491.99
functions.variables.create 425.33
storage.buckets.create 408.56
tablesdb.rows.list 403.49
functions.variables.update 361.55

@Meldiron
Meldiron merged commit 1029c55 into main Sep 30, 2026
52 checks passed
abnegate added a commit that referenced this pull request Sep 30, 2026
Brings in main's OAuth2 state and nonce validation (#14012), which cloud
needs, along with the realtime origin alignment (#14020), subscriber
target ownership (#14019), GitLab primary email (#14010), impersonation
MFA (#14017), write-only webhook passwords (#14016), chunked-upload
resume ownership (#14014), preview authorize validation (#14013),
nightly forcing (#14015) and scheduled-function enqueue checks (#14011).

The merge had no textual conflicts, and main left composer.json and
composer.lock unchanged. So the lock keeps the branch's database and
async pins.

Main's assertResumeAllowed() in Storage Buckets/Files/Create checks
Input(Database::PERMISSION_UPDATE, ...). utopia-php/database 8 has no
PERMISSION_* constants, so every chunked resume would fail with an
undefined-constant error. It now passes PermissionType::Update, as the
rest of that action already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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