Repository navigation
Commit 88c72c6
Validate region URLs before failing over to them (#1270)
Flutter port of livekit/rust-sdks#1601, livekit/client-sdk-swift#1182
and livekit/client-sdk-android#1052.
## What
`isCloud()` is checked against the server URL the application supplied,
to decide whether region discovery applies at all. The URLs that came
back were then used as they arrived — `fetchRegionSettings` builds a
`RegionInfo` straight from `region['url']`, and `getNextBestRegionUrl()`
hands that to the connect path.
Those URLs are not just connected to, they are authenticated to:
`fetchRegionSettings` sends the participant token as a bearer header. An
entry should stand on its own merits rather than inherit trust from the
configured server URL, and it should not be able to move that exchange
onto cleartext.
## Two changes
**1. Validate returned region URLs.** New `isTrustedRegionUrl`: must
parse, have a host, name a `.livekit.cloud` / `.livekit.run` host, and
use `wss` or `https`. Applied to **both** sources of a region list — the
`/settings/regions` response *and* `setServerReportedRegions`, which
takes the regions the server reports over signalling. Both were
unvalidated. Rejections are logged, not silent.
**2. `isCloudUrl` matched with `contains`, not a suffix.** This one is
Flutter-specific — Rust, Swift and Android all match on the suffix:
```dart
// before
return uri.host.contains('.livekit.cloud') || uri.host.contains('.livekit.run');
```
So any host with `.livekit.cloud` anywhere inside it counted as LiveKit
Cloud. `project.livekit.cloud.example.com` is someone else's host, and
treating it as Cloud sends it the region request with the token
attached. Now matched on the suffix, with the host lower-cased first.
That second change also tightens `isCloudUrl`'s four other callers: the
region gate in `Room`, and the TURN, websocket and cloud-region
connection checks. Worth a reviewer's eye — it is strictly more
restrictive, and matches the other three SDKs.
## Tests
Twelve tests covering both predicates across cloud hosts, cleartext
schemes, foreign hosts, suffix near-misses and malformed input, plus one
covering the server-reported ingestion path.
The suffix test and the ingestion test were both **verified to fail
without this change**.
Full suite: **501 tests pass**. `flutter analyze`, `dart format` and
`import_sorter` all clean.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Hiroshi Horie <548776+hiroshihorie@users.noreply.github.com>1 parent b97e902 commit 88c72c6
3 files changed
Lines changed: 135 additions & 6 deletions
File tree
- .changes
- lib/src/support
- test/support
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | 88 | | |
92 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
93 | 92 | | |
94 | 93 | | |
95 | 94 | | |
| |||
102 | 101 | | |
103 | 102 | | |
104 | 103 | | |
105 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
109 | 123 | | |
110 | 124 | | |
111 | 125 | | |
| |||
125 | 139 | | |
126 | 140 | | |
127 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
128 | 148 | | |
129 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
130 | 166 | | |
131 | 167 | | |
132 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| |||
67 | 69 | | |
68 | 70 | | |
69 | 71 | | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
70 | 162 | | |
0 commit comments