Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: fail closed to null on a malformed redirect Location (#2046)

Adam Eivy7ed6f62a11ae
diff --git a/server/lib/safeUrlFetch.js b/server/lib/safeUrlFetch.js
index c741bc8eea..254497eda2 100644
--- a/server/lib/safeUrlFetch.js
+++ b/server/lib/safeUrlFetch.js
@@ -195,7 +195,11 @@ async function fetchGuarded(url, { timeoutMs = DEFAULT_TIMEOUT_MS, headers, bloc
if (res && res.status >= 300 && res.status < 400) {
const location = res.headers.get('location');
if (!location) return null;
- const redirectUrl = new URL(location, url).href;
+ // A malformed Location must fail closed to null (not throw) so the
+ // throwOnUnsafe:false contract holds for the redirect hop too — same
+ // guarded-parse pattern as isSafeIngestUrl.
+ let redirectUrl;
+ try { redirectUrl = new URL(location, url).href; } catch { return null; }
const hop = await resolvePublicHttpUrl(redirectUrl, { blockPrivate });
if (!hop.safe) return null;
return pinnedFetch(redirectUrl, hop, { redirect: 'error', headers }, timeoutMs);
diff --git a/server/lib/safeUrlFetch.test.js b/server/lib/safeUrlFetch.test.js
index c000e6fde2..344b8cbb0b 100644
--- a/server/lib/safeUrlFetch.test.js
+++ b/server/lib/safeUrlFetch.test.js
@@ -144,6 +144,11 @@ describe('fetchPublicText', () => {
expect(await fetchPublicText('https://example.com/feed.rss')).toBeNull();
expect(fetchMock).toHaveBeenCalledTimes(1);
});
+ it('returns null (no throw) on a malformed redirect Location', async () => {
+ fetchMock.mockResolvedValueOnce(res({ status: 301, headers: { location: 'http://[bad' } }));
+ expect(await fetchPublicText('https://example.com/feed.rss')).toBeNull();
+ expect(fetchMock).toHaveBeenCalledTimes(1);
+ });
});
describe('connect-time IP pinning (DNS-rebinding TOCTOU, #1859)', () => {