Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Browser.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChevronLeft, ChevronRight, Home, Lock, Maximize2, Menu, MoreVertical, Plus, RotateCw, Star, X } from "lucide-react";
import { useEffect, useMemo, useRef, useState } from "react";
import { actionBarClass, addressInputClass, classNames, closeButtonClass, encodeProxyUrl, formatUrl, getActualUrl, getDefaultUrl, type Tab, tabButtonClass } from "@/lib/tabs";
import { actionBarClass, addressInputClass, classNames, closeButtonClass, encodeProxyUrl, formatUrl, getActualUrl, getDefaultUrl, type Tab, tabButtonClass, sanitizeUrl } from "@/lib/tabs";

const IconButton = ({ onClick, icon: Icon, className = "", disabled = false, title = "" }: { onClick?: () => void; icon: React.ComponentType<{ className?: string }>; className?: string; disabled?: boolean; title?: string }) => (
<button
Expand Down Expand Up @@ -450,7 +450,7 @@ export default function Browser() {
iframeRefs.current[tab.id] = el;
}}
title={tab.title}
src={encodeProxyUrl(tab.url)}
src={encodeProxyUrl(sanitizeUrl(tab.url))}
className={classNames("absolute inset-0 h-full w-full border-0", tab.active ? "block" : "hidden")}
sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox"
/>
Expand Down
15 changes: 15 additions & 0 deletions src/lib/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ export const getDefaultUrl = () => {
}
};

// Only allow 'about:blank' and HTTP(S) URLs. All others are replaced with 'about:blank'.
export function sanitizeUrl(url: string): string {
if (!url || url === "about:blank") return "about:blank";
try {
// This throws for invalid URLs, so fallback to 'about:blank'
const parsed = new URL(url, "https://example.com");
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
return parsed.href;
}
} catch {
// Malformed URL, fallback
}
return "about:blank";
}

export const encodeProxyUrl = (url: string): string => {
if (!url || url === "about:blank") return "about:blank";
if (typeof window === "undefined") return url;
Expand Down
Loading