fix: secure widget navigation links

This commit is contained in:
Thomas Camlong authored and ajnart committed 2026-08-13 19:54:37 +02:00
1 parent 2344896ba9
commit a9f1293077
3 files changed
+30 -6

No files matched your search

@@ -14,9 +14,20 @@ describe("RSS feed display helpers", () => {
expect(getHostname("https://example.com/feed.xml")).toBe("example.com");
});
test("only exposes HTTP links from untrusted feed entries", () => {
test("only exposes credential-free HTTP links from untrusted feed entries", () => {
expect(getSafeExternalUrl("https://example.com/story")).toBe("https://example.com/story");
expect(getSafeExternalUrl("/story", "https://example.com/feed.xml")).toBe("https://example.com/story");
expect(getSafeExternalUrl("/story", "https://user:password@example.com/feed.xml")).toBe(
"https://example.com/story",
);
expect(getSafeExternalUrl("https://user:password@example.com/story")).toBe("https://example.com/story");
expect(getSafeExternalUrl(undefined, "https://example.com/feed?token=secret")).toBeUndefined();
expect(getSafeExternalUrl("#story", "https://example.com/feed?token=secret#old")).toBe(
"https://example.com/feed#story",
);
expect(getSafeExternalUrl("?story=1", "https://example.com/feed?token=secret")).toBe(
"https://example.com/feed?story=1",
);
expect(getSafeExternalUrl("javascript:alert(1)")).toBeUndefined();
expect(getSafeExternalUrl("not a URL")).toBeUndefined();
});