Scope cached ShopinBit attachments by customer key
What changed, and why it matters
This commit fixes a privacy bug in Stack Wallet's image caching. When the app showed customer support attachments from ShopinBit, it cached images using only the web address. Because the same attachment path can return different files for different customers, a later customer could briefly see another customer's cached image without a fresh permission check. The patch adds a 'customer key' to the cache key so each customer's images stay separate, and it makes sure the key is tied to the actual downloaded response rather than the on-screen widget state.
Treat as a privacy/security fix. Verify the patch is included in the next release, confirm no other ImageProvider in the codebase caches authenticated content by URL alone, and consider auditing other customer-keyed network resources for similar cache-key issues.
Security signals we found
Cross-customer cache contamination in authenticated image provider
Missing authorization boundary in shared URL cache key
FutureBuilder stale-snapshot mismatch with changing customer identity
Privacy leak of customer support attachments
Evidence from the diff
TorAwareNetworkImage previously used only url as its ImageProvider/cache key (== and hashCode). For ShopinBit ticket attachments, the proxy path is customer-agnostic but the returned content is customer-specific. Without cache scoping, Flutter’s image cache could serve a previously fetched attachment to a different customerKey without re-issuing an authenticated request. The patch introduces an optional cacheScope field that participates in ==/hashCode, passes widget.customerKey as cacheScope, and bundles customerKey with the FutureBuilder snapshot so stale snapshots are not paired with a newer scope while a new request is pending. A regression test verifies cache key inequality across scopes.
Changed components
lib/networking/tor_aware_network_image.dartlib/pages/shopinbit/shopinbit_ticket_detail.dartShopinBit ticket attachment viewerInspect captured patch +43 / −9
### lib/networking/tor_aware_network_image.dart
@@ -39,14 +39,19 @@ Future<Uint8List> fetchTorAwareBytes(
/// Use with [Image] instead of [Image.network], which always goes clearnet.
@immutable
class TorAwareNetworkImage extends ImageProvider<TorAwareNetworkImage> {
- const TorAwareNetworkImage(this.url, {this.headers});
+ const TorAwareNetworkImage(this.url, {this.headers, this.cacheScope});
final String url;
/// Sent with the request but not part of the cache key, so e.g. a refreshed
/// auth token doesn't cause a refetch.
final Map<String, String>? headers;
+ /// Part of the cache key, unlike [headers]. Set it to a stable identity
+ /// (e.g. a customer key) when the same [url] can serve different content
+ /// depending on who is asking, so one identity never sees another's image.
+ final String? cacheScope;
+
@override
Future<TorAwareNetworkImage> obtainKey(ImageConfiguration configuration) =>
SynchronousFuture<TorAwareNetworkImage>(this);
@@ -94,10 +99,12 @@ class TorAwareNetworkImage extends ImageProvider<TorAwareNetworkImage> {
@override
bool operator ==(Object other) =>
- other is TorAwareNetworkImage && other.url == url;
+ other is TorAwareNetworkImage &&
+ other.url == url &&
+ other.cacheScope == cacheScope;
@override
- int get hashCode => url.hashCode;
+ int get hashCode => Object.hash(url, cacheScope);
@override
String toString() =>
### lib/pages/shopinbit/shopinbit_ticket_detail.dart
@@ -830,6 +830,11 @@ class _AttachmentChip extends StatelessWidget {
/// The request future is built once in [initState] (and only rebuilt when
/// [proxyPath] or [customerKey] actually change) so the surrounding 30s poll
/// can't re-fire `getAttachmentRequest`/re-fetch the image on every rebuild.
+typedef _AttachmentLoad = ({
+ ApiResponse<AttachmentRequest> response,
+ String customerKey,
+});
+
class _ProxyImage extends StatefulWidget {
const _ProxyImage({
required this.client,
@@ -848,12 +853,18 @@ class _ProxyImage extends StatefulWidget {
}
class _ProxyImageState extends State<_ProxyImage> {
- late Future<ApiResponse<AttachmentRequest>> _requestFuture;
+ late Future<_AttachmentLoad> _requestFuture;
// Header auth: a query-auth URL would put the token and customer key into
- // logged HTTP errors.
- Future<ApiResponse<AttachmentRequest>> _buildFuture() => widget.client
- .getAttachmentRequest(widget.proxyPath, customerKey: widget.customerKey);
+ // logged HTTP errors. The customer key travels with the response because
+ // FutureBuilder keeps showing the previous snapshot while a new future is
+ // pending, and that snapshot must not be paired with a newer key.
+ Future<_AttachmentLoad> _buildFuture() {
+ final customerKey = widget.customerKey;
+ return widget.client
+ .getAttachmentRequest(widget.proxyPath, customerKey: customerKey)
+ .then((response) => (response: response, customerKey: customerKey));
+ }
@override
void initState() {
@@ -878,7 +889,7 @@ class _ProxyImageState extends State<_ProxyImage> {
borderRadius: BorderRadius.circular(8),
child: ConstrainedBox(
constraints: const BoxConstraints(maxHeight: _kAttachmentMaxHeight),
- child: FutureBuilder<ApiResponse<AttachmentRequest>>(
+ child: FutureBuilder<_AttachmentLoad>(
future: _requestFuture,
builder: (context, snapshot) {
if (!snapshot.hasData) {
@@ -887,7 +898,7 @@ class _ProxyImageState extends State<_ProxyImage> {
child: LoadingIndicator(width: _kAttachmentLoaderWidth),
);
}
- final resp = snapshot.data!;
+ final resp = snapshot.data!.response;
if (resp.hasError || resp.value == null) {
return widget.fallback();
}
@@ -898,6 +909,7 @@ class _ProxyImageState extends State<_ProxyImage> {
TorAwareNetworkImage(
resp.value!.uri.toString(),
headers: resp.value!.headers,
+ cacheScope: snapshot.data!.customerKey,
),
),
fit: BoxFit.contain,
### test/networking/tor_aware_network_image_test.dart
@@ -39,4 +39,19 @@ void main() {
),
);
});
+
+ test("network image cache is scoped by cacheScope", () {
+ expect(
+ TorAwareNetworkImage(url("/a.png"), cacheScope: "customer-a"),
+ TorAwareNetworkImage(url("/a.png"), cacheScope: "customer-a"),
+ );
+ expect(
+ TorAwareNetworkImage(url("/a.png"), cacheScope: "customer-a"),
+ isNot(TorAwareNetworkImage(url("/a.png"), cacheScope: "customer-b")),
+ );
+ expect(
+ TorAwareNetworkImage(url("/a.png"), cacheScope: "customer-a"),
+ isNot(TorAwareNetworkImage(url("/a.png"))),
+ );
+ });
}Why this scored 60/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.