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.ts · 500 bytes · 16 lines
| 1 | /** |
| 2 | * Which URLs may be handed to the operating system. Only plain http(s): never file:, a |
| 3 | * custom-scheme app launcher, javascript:, or a URL with embedded credentials. |
| 4 | */ |
| 5 | export function safeExternalUrl(input: unknown): string | null { |
| 6 | if (typeof input !== "string") return null; |
| 7 | let u: URL; |
| 8 | try { |
| 9 | u = new URL(input); |
| 10 | } catch { |
| 11 | return null; |
| 12 | } |
| 13 | if (u.protocol !== "https:" && u.protocol !== "http:") return null; |
| 14 | if (u.username || u.password) return null; |
| 15 | return u.href; |
| 16 | } |