Repository navigation
Validate region URLs before failing over to them - #1270
Open
xianshijing-lk wants to merge 1 commit into
Open
xianshijing-lk wants to merge 1 commit into
xianshijing-lk wants to merge 1 commit into
Conversation
`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. Add `isTrustedRegionUrl`: the URL must parse, have a host, name a `.livekit.cloud` or `.livekit.run` host, and use `wss` or `https`. Apply it 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. Rejected entries are logged rather than dropped silently. Separately, `isCloudUrl` matched the Cloud domains with `contains`, 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. It now matches on the suffix, like the Rust, Swift and Android SDKs, and lower-cases the host first. The suffix change also tightens `isCloudUrl`'s four other callers: the region gate in `Room`, and the TURN, websocket and cloud-region connection checks. Twelve tests: the two 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 both fail without this change.
xianshijing-lk
requested review from
changt,
cloudwebrtc and
hiroshihorie
as code owners
October 29, 2026 21:04
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| if (uri == null || uri.host.isEmpty) return false; | ||
| final scheme = uri.scheme.toLowerCase(); | ||
| if (scheme != 'wss' && scheme != 'https') return false; | ||
| return isCloudUrl(uri); |
There was a problem hiding this comment.
🟥 Region URLs can redirect bearer tokens
When a region URL points to a Cloud host that redirects elsewhere, isTrustedRegionUrl accepts it before connecting. Redirect-following HTTP requests can forward the participant token to the redirect target.
Was this helpful? React with 👍 or 👎 to provide feedback.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 —fetchRegionSettingsbuilds aRegionInfostraight fromregion['url'], andgetNextBestRegionUrl()hands that to the connect path.Those URLs are not just connected to, they are authenticated to:
fetchRegionSettingssends 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.runhost, and usewssorhttps. Applied to both sources of a region list — the/settings/regionsresponse andsetServerReportedRegions, which takes the regions the server reports over signalling. Both were unvalidated. Rejections are logged, not silent.2.
isCloudUrlmatched withcontains, not a suffix. This one is Flutter-specific — Rust, Swift and Android all match on the suffix:So any host with
.livekit.cloudanywhere inside it counted as LiveKit Cloud.project.livekit.cloud.example.comis 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 inRoom, 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 formatandimport_sorterall clean.🤖 Generated with Claude Code