askrobots / dbbasic-browser
Public
A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.
danq9
site icons (favicons) in tabs, address bar suggestions and the bookmarks panel
7249579
15 hours, 50 minutes ago
History
urls.test.ts · 916 bytes · 19 lines
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { safeExternalUrl } from "../src/urls.js"; |
| 3 | |
| 4 | describe("safeExternalUrl", () => { |
| 5 | it("allows http(s) and normalizes", () => { |
| 6 | expect(safeExternalUrl("https://www.ebay.com/itm/1?x=2")).toBe("https://www.ebay.com/itm/1?x=2"); |
| 7 | expect(safeExternalUrl("http://127.0.0.1:8899")).toBe("http://127.0.0.1:8899/"); |
| 8 | }); |
| 9 | it("refuses everything that could launch something else", () => { |
| 10 | for (const bad of ["file:///etc/passwd", "javascript:alert(1)", "data:text/html,x", "vscode://open", "ssh://host", "about:blank", "", "not a url"]) { |
| 11 | expect(safeExternalUrl(bad)).toBeNull(); |
| 12 | } |
| 13 | }); |
| 14 | it("refuses embedded credentials and non-strings", () => { |
| 15 | expect(safeExternalUrl("https://user:pw@example.com/")).toBeNull(); |
| 16 | expect(safeExternalUrl(undefined)).toBeNull(); |
| 17 | expect(safeExternalUrl({ href: "https://a.test" })).toBeNull(); |
| 18 | }); |
| 19 | }); |