Skip to content

fix(realtime): align origin validation with the HTTP API - #14020

Merged
Meldiron merged 2 commits into
mainfrom
fix/realtime-origins
Sep 30, 2026
Merged

Meldiron merged 2 commits into
mainfrom
fix/realtime-origins

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

What does this PR do?

The realtime handshake validates the Origin header against the platform allowlist, but applied it to regular projects only, while the HTTP API applies one policy to every project. This makes the realtime handshake follow the same rules:

  • The origin check now runs for every project. Connections without an Origin header (non-web clients) are unchanged.
  • The realtime allowlist now includes the _APP_CONSOLE_URL host, as the HTTP allowlist already does, so a console served apart from the API host keeps working alongside _APP_CONSOLE_DOMAIN and _APP_CONSOLE_HOSTNAMES.

Test Plan

  • New RealtimeConsoleClientTest::testConnectionPlatform connects to the console project from an allowed origin and from an unknown one, expecting a connected frame and a policy violation respectively.
  • Existing RealtimeCustomClientTest::testConnectionPlatform keeps covering regular projects.
  • Pint, PHPStan and Rector pass on the changed files.

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?

🤖 Generated with Claude Code

The realtime handshake checked the Origin header against the platform
allowlist for regular projects only. Apply the same check to every
project, and allow the console URL host as the HTTP API already does.

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

ghost commented Sep 30, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The disconnect-wait finding is fixed; the previously reported missing coverage for a distinct console URL host remains unresolved.

Realtime now validates browser origins for console projects as well as regular projects, while retaining the no-Origin exemption. Its allowlist also includes the configured console URL host. A console-client E2E test covers accepted and rejected origins and checks server disconnection.

Latest changes: The latest commit replaces the fixed disconnect sleep with a bounded socket read and disconnection assertion, and checks the error message prefix instead of its exact wording.

Verdict New comments Fixed Still open
✅ Approved 0 1 1
Fix with agent prompt
### Issue 1
tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php:200-203
**Cover a console URL host outside the existing allowlist**

The success case uses localhost, which is already allowed by the platform configuration, so it still passes if the new `consoleUrl` handling is removed. Please add a connection case with `_APP_CONSOLE_URL` on a distinct host not present in `_APP_DOMAIN`, `_APP_CONSOLE_DOMAIN`, or `_APP_CONSOLE_HOSTNAMES` to protect the separate-console deployment fix.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 3
File Change
app/init/realtime/connection.php Adds the configured console URL hostname to the realtime origin allowlist.
app/realtime.php Applies origin validation to console projects as well as regular projects.
tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php Adds console origin acceptance/rejection coverage and waits for socket closure without a fixed sleep.
⏳ Still open from earlier reviews · 1
✅ Fixed since the last review · 1
  • Wait for disconnection instead of sleeping a fixed interval · tests/e2e/Services/Realtime/RealtimeConsoleClientTest.php:228

Reviewed the commits since c847d4e · 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

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical risk] Changes origin validation for real-time WebSocket connections.

The PR appears safe to merge; no outstanding findings or new actionable issues were identified.

Summary

The PR applies origin validation to console-project realtime connections and adds the configured console URL host to the allowlist. It also adds console-connection coverage and replaces a fixed-delay disconnect check with a read of the socket.

Reviews (2) · Last reviewed commit: "test(realtime): wait for the server disc..."

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/realtime-origins (after).

Metric Before After Change
🚀 Requests/sec 197.43 194.64 ⚪ -1.4%
⏱️ Latency P50 87.78 ms 89.91 ms ⚪ +2.4%
⏱️ Latency P95 202.65 ms 203.75 ms ⚪ +0.5%
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 89.91 203.75 12,540 194.64 +1.1
Account 169.42 314.03 660 10.94 +12.21
TablesDB 88.11 160.82 6,820 108.75 -4.77
Storage 81.18 177.71 3,300 54 +0.9
Functions 129.09 236.77 1,760 29.53 -2.28

Top API waits (after)

API request Max wait (ms)
account.name.update 577.7
functions.create 411.93
functions.variables.update 408.93
account.prefs.update 404.69
functions.delete 404.16

@Meldiron
Meldiron merged commit 24beabb into main Sep 30, 2026
64 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.

1 participant