Skip to content

Commit 0826a8c

Browse files
square-tombclaude
andcommitted
fix(mobile): skip hostless URLs when scoping relay media headers
Uri.origin throws StateError for an http(s) URI without a host, and community-controlled image values can be hostless. Treat them as non-relay URLs so no headers are added and reaction details still open. Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Signed-off-by: Tom Brow <[email protected]>
1 parent 528ba08 commit 0826a8c

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

‎mobile/lib/shared/hosted/hosted_relay_auth.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ class HostedRelayAuth extends ChangeNotifier {
154154

155155
static bool _isRelayOrigin(RelayConfig config, Uri url) =>
156156
(url.scheme == 'http' || url.scheme == 'https') &&
157+
// `Uri.origin` throws for a hostless URI, which a community can supply.
158+
url.host.isNotEmpty &&
157159
url.origin == Uri.parse(config.baseUrl).origin;
158160

159161
Future<Map<String, String>> headers(RelayConfig config) async {

‎mobile/test/shared/hosted/native_media_headers_test.dart‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ void main() {
4848
'https://cdn.example/a.png',
4949
'https://team.relay.example/media/a.png',
5050
'http://relay.example/media/a.png',
51+
'https:///media/a.png',
52+
'http:///media/a.png',
53+
'https://',
5154
]) {
5255
expect(headersFor(other), isNot(contains('Nostr-Federated-Identity')));
5356
}

0 commit comments

Comments
 (0)