Skip to content

feat: support capacitor:// as an allowed origin - #13514

Merged
Meldiron merged 1 commit into
mainfrom
feat-capacitor-origin
Sep 7, 2026
Merged

Meldiron merged 1 commit into
mainfrom
feat-capacitor-origin

Conversation

@Meldiron

@Meldiron Meldiron commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds capacitor to the schemes Appwrite recognises as web platforms, so origins such as capacitor://app.tycko.cz are accepted.

Capacitor's iOS webview serves the app from capacitor://<hostname> — capacitor://localhost by default, or the configured server.hostname. Appwrite did not know the scheme, so Origin skipped hostname matching and fell through to the custom-scheme allow list, where capacitor is absent. Every request from a Capacitor iOS app was rejected with Invalid Scheme. The scheme used (capacitor) ... is not supported.

The origin is now matched by host against the project's registered Web platform hostnames, exactly like tauri:// and the browser-extension schemes. capacitor://app.tycko.cz is accepted once app.tycko.cz is registered as a Web platform, and nothing else is — an unregistered host still fails.

Cors already matched by host regardless of scheme, so it needed no change; a test pins that behaviour.

Test Plan

vendor/bin/phpunit tests/unit/Network/CorsTest.php tests/unit/Network/Validators/OriginTest.php — 23 tests, 135 assertions, passing.

Added coverage:

  • capacitor://localhost and capacitor://appwrite.io are valid against a matching allow list.
  • capacitor://example.com is rejected, with the Web (Capacitor) platform hint in the error.
  • Cors::headers() echoes capacitor://app.example.com when app.example.com is allowed.

Related PRs and Issues

Reported by a customer using Capacitor with a custom server.hostname (capacitor://app.tycko.cz).

Have you read the Contributing Guidelines on issues?

Yes.

🤖 Generated with Claude Code

Capacitor's iOS webview serves the app from `capacitor://<hostname>`
(`capacitor://localhost` by default, or the configured `server.hostname`,
e.g. `capacitor://app.tycko.cz`). Those requests were rejected with an
unknown-origin error because `capacitor` was not a recognised scheme, so
the validator fell through to the custom-scheme allow list.

Treat it like the other webview/extension schemes: match the origin's
host against the project's registered Web platform hostnames, so
`capacitor://app.tycko.cz` is accepted once `app.tycko.cz` is registered
and nothing else is. Follows the same shape as `tauri://`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR recognizes capacitor:// as a hostname-validated Web platform origin, allowing Capacitor applications only when their origin hostname is registered on the project.

  • Adds the Capacitor scheme and its user-facing platform label.
  • Routes Capacitor origins through the existing registered-hostname validation path.
  • Adds positive and negative Origin coverage and confirms CORS echoes an allowed Capacitor origin.

Confidence Score: 5/5

The PR appears safe to merge; Capacitor support remains constrained by the existing registered-hostname checks.

No actionable failures remain: the new scheme reaches the same fail-closed hostname validation used by analogous Web platform schemes, request and realtime wiring already provide the required hostnames, and the tests cover both acceptance and rejection.

Important Files Changed

Filename Overview
src/Appwrite/Network/Platform.php Defines the Capacitor scheme and maps it to the Web (Capacitor) platform label.
src/Appwrite/Network/Validator/Origin.php Validates Capacitor origins against registered Web platform hostnames using the established web-scheme path.
tests/unit/Network/CorsTest.php Confirms an allowed hostname is echoed for a Capacitor custom-scheme origin.
tests/unit/Network/Validators/OriginTest.php Covers acceptance of registered Capacitor hosts, rejection of an unregistered host, and the resulting platform hint.

Reviews (1): Last reviewed commit: "feat: support capacitor:// as an allowed..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat-capacitor-origin (after).

Metric Before After Change
🚀 Requests/sec 213.66 207.45 ⚪ -2.9%
⏱️ Latency P50 85.75 ms 85.57 ms ⚪ -0.2%
⏱️ Latency P95 176.13 ms 188.17 ms 🔴 +6.8%
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.57 188.17 12,882 207.45 +12.04
Account 158.85 301.13 678 11.24 +42.6
TablesDB 86.03 158.91 7,006 114.7 +8.64
Storage 71.99 159.57 3,390 57.7 +4.71
Functions 115.25 220.51 1,808 31.42 +23.27

Top API waits (after)

API request Max wait (ms)
tablesdb.rows.increment 523.67
tablesdb.rows.create 448.14
account.prefs.update 438.92
account.name.update 416.02
account.get 388.35

@Meldiron
Meldiron merged commit e80162f into main Sep 7, 2026
45 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 10, 2026
2 of 4 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.

1 participant