fix(desktop): use IPv4 loopback for media proxy URLs (#1245)

Signed-off-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
Co-authored-by: npub1mprnacetjua2xx3p5eddmhxyk6wv929ymm5py8kd2xfxurxahspqqlgyta <d8473ee32b973aa31a21a65adddcc4b69cc2a8a4dee8121ecd51926e0cddbc02@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
Tyler
2026-06-24 20:20:27 -04:00
committed by GitHub
parent 856815994c
commit cee2c5f263
4 changed files with 30 additions and 8 deletions

View File

@@ -0,0 +1,13 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { mediaProxyUrl } from "./mediaUrl.ts";
const HASH = "a".repeat(64);
test("mediaProxyUrl: uses the IPv4 loopback literal for the localhost proxy", () => {
assert.equal(
mediaProxyUrl(54321, `${HASH}.png`),
`http://127.0.0.1:54321/media/${HASH}.png`,
);
});

View File

@@ -80,9 +80,18 @@ export function resetMediaCaches(): void {
cachedRelayOrigin = null;
}
/**
* Build the local proxy URL with an IPv4 literal. The Rust proxy binds
* `127.0.0.1:0`, not `::1`, and some WebViews resolve `localhost` to IPv6
* first. Matching the bind address avoids machine-dependent image failures.
*/
export function mediaProxyUrl(port: number, mediaPath: string): string {
return `http://127.0.0.1:${port}/media/${mediaPath}`;
}
/**
* If `url` is a Blossom media URL hosted on the Buzz relay, rewrite it
* to go through the localhost streaming proxy. External Blossom URLs and
* to go through the local streaming proxy. External Blossom URLs and
* non-Blossom URLs are returned unchanged.
*
* Falls back to buzz-media:// if the proxy port isn't available yet.
@@ -100,7 +109,7 @@ export function rewriteRelayUrl(url: string): string {
}
if (cachedPort && cachedPort > 0) {
return `http://localhost:${cachedPort}/media/${m[1]}`;
return mediaProxyUrl(cachedPort, m[1]);
}
// Kick off fetch if we haven't yet.