Skip to content

Commit 699f85e

Browse files
committed
fix(mobile): reject unvalidated community icon fallbacks
Signed-off-by: kenny lopez <[email protected]>
1 parent 6f6d71d commit 699f85e

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎mobile/lib/shared/community/community_icon_provider.dart‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ final communityIconProvider = FutureProvider.autoDispose
6868
}
6969
}
7070
if (disposed) return saved;
71-
if (artwork == null) return saved ?? icon;
71+
// Never expose rejected remote URLs to the avatar renderer: doing so
72+
// would bypass the bounded download above.
73+
if (artwork == null) return saved;
7274
await cache.remember(key, artwork);
7375
return artwork;
7476
} catch (_) {

‎mobile/test/shared/community/community_icon_provider_test.dart‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,45 @@ void main() {
179179
);
180180
});
181181

182+
for (final saved in [false, true]) {
183+
for (final rejection in ['oversized', 'invalid MIME', 'HTTP failure']) {
184+
test('$rejection never exposes an unchecked URL, saved=$saved', () async {
185+
final container = containerFor((request) async {
186+
if (request.url.path == '/') {
187+
return http.Response(
188+
'{"icon":"https://relay.example.com/rejected.png"}',
189+
200,
190+
);
191+
}
192+
return http.Response.bytes(
193+
List.filled(rejection == 'oversized' ? 256 * 1024 + 1 : 4, 0),
194+
rejection == 'HTTP failure' ? 503 : 200,
195+
headers: {
196+
'content-type': rejection == 'invalid MIME'
197+
? 'text/html'
198+
: 'image/png',
199+
},
200+
);
201+
});
202+
if (saved) {
203+
await container
204+
.read(communityIconCacheProvider.notifier)
205+
.remember(key, artwork);
206+
}
207+
final presentation = communityIconPresentationProvider(relay);
208+
final subscription = container.listen(presentation, (_, _) {});
209+
addTearDown(subscription.close);
210+
final expected = saved ? artwork : null;
211+
expect(
212+
await container.read(communityIconProvider(relay).future),
213+
expected,
214+
);
215+
expect(container.read(presentation), expected);
216+
expect(container.read(communityIconCacheProvider)[key], expected);
217+
});
218+
}
219+
}
220+
182221
test('oversized downloads do not replace a usable saved image', () async {
183222
final container = containerFor(
184223
(request) async => request.url.path == '/'

0 commit comments

Comments
 (0)