Skip to content

Normalize redirect URL authority before host matching - #14348

Merged
abnegate merged 2 commits into
mainfrom
fix/redirect-url-authority-parsing
Oct 15, 2026
Merged

abnegate merged 2 commits into
mainfrom
fix/redirect-url-authority-parsing

Conversation

@abnegate

Copy link
Copy Markdown
Member

What does this PR do?

parse_url() and browser URL parsers can split an http(s) authority differently when the authority contains \. Host matching then sees a different host than the one a browser would use.

This change requires a normalized host[:port] authority on http(s) URLs before comparing the host to the project's platform list:

  • Reject \ in the authority
  • Reject userinfo (@ in the authority)
  • Reject tab, newline, and other control characters in the authority

Ordinary platform URLs stay accepted, including ports, paths, query strings, and custom schemes used by mobile platforms.

Test Plan

  • Unit tests in tests/unit/Network/Validators/OriginTest.php cover backslash forms (\@, \\, /\), userinfo forms, control characters, and accepted platform URLs
  • E2E coverage on POST /account/recovery rejects a backslash authority and a userinfo URL
  • Run composer lint on the touched PHP files and vendor/bin/phpunit tests/unit/Network/Validators/OriginTest.php

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?
Open in Web Open in Cursor 

Require a host[:port] authority on http(s) URLs so parse_url() and
browser URL parsers agree on the host before platform matching.

Co-authored-by: Jake Barnby <[email protected]>
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • 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 11, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/redirect-url-authority-parsing (after).

Metric Before After Change
🚀 Requests/sec 208.31 217.39 ⚪ +4.4%
⏱️ Latency P50 83.83 ms 81.16 ms ⚪ -3.2%
⏱️ Latency P95 187.66 ms 180.16 ms ⚪ -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 81.16 180.16 13,680 217.39 -7.5
Account 151.58 275.21 720 12.07 -6.67
TablesDB 78.66 142.41 7,440 120.53 -17.84
Storage 75.22 157.92 3,600 60.26 +3.52
Functions 114.2 211.26 1,920 32.79 +0.75

Top API waits (after)

API request Max wait (ms)
account.prefs.update 390.89
account.name.update 381.86
functions.variables.update 358.18
storage.files.create 338.07
functions.variables.create 332.04

@abnegate
abnegate marked this pull request as ready for review October 11, 2026 20:58
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR hardens origin/redirect URL validation by rejecting backslashes, userinfo (@), and control characters inside the http(s) authority before host matching, closing parser-divergence bypasses where browsers would resolve a different host than parse_url. The rule applies only to http/https schemes, preserving custom app schemes, IPv6 hosts, and ports; unit tests and e2e 400-assertions for /account/recovery pin the new behavior.

Files Change
src/Appwrite/Network/Validator/Origin.php Adds hasNormalizedAuthority() gate that fails closed on hostile characters in the authority segment.
tests/unit/Network/Validators/OriginTest.php New testHttpAuthority cases for backslash, userinfo, and control-character bypasses.
tests/e2e/Services/Account/AccountCustomClientTest.php E2e assertions that recovery URLs with \@ and userinfo authorities return 400.
.github/ci/e2e.json Registers the covered Account e2e lane.

The validator is shared by the CSRF origin check and all url-taking endpoints (recovery, verification, magic URL, OAuth callbacks, team invites), so the fix is global by construction. Note: userinfo in http(s) redirect URLs is now rejected entirely, a deliberate behavioral tightening worth a changelog mention.

Reviewed commit: 4329a56

@ghost

ghost commented Oct 11, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The authority checks preserve ordinary platform URLs while closing the host-parsing mismatch, and the changed behavior has unit and E2E coverage.

The Origin validator now rejects HTTP(S) URLs with backslashes, userinfo, or control characters in the authority before matching the host against allowed platforms. The change adds unit and account recovery E2E coverage and maps the validator files to the Account E2E lane.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
.github/ci/e2e.json Adds the Origin and Redirect validators to Account E2E path matching.
src/Appwrite/Network/Validator/Origin.php Rejects HTTP(S) authorities containing backslashes, userinfo, or control characters.
tests/e2e/Services/Account/AccountCustomClientTest.php Checks that recovery rejects backslash-authority and userinfo URLs.
tests/unit/Network/Validators/OriginTest.php Covers accepted URL forms and rejected malformed HTTP(S) authorities.

Merged main (939fa5e); no changes to this PR's code since 4329a56 · 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

@abnegate
abnegate merged commit ca35312 into main Oct 15, 2026
67 checks passed
@abnegate
abnegate deleted the fix/redirect-url-authority-parsing branch October 15, 2026 07:58
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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