diff --git a/src/components/ItemArticle.test.tsx b/src/components/ItemArticle.test.tsx
index 32ac28e..65a1b5d 100644
--- a/src/components/ItemArticle.test.tsx
+++ b/src/components/ItemArticle.test.tsx
@@ -51,6 +51,26 @@ describe('ItemArticle', () => {
// Text posts render as plain text, not as a clickable link
expect(screen.queryByRole('link', { name: 'A great story' })).not.toBeInTheDocument();
});
+
+ it.each(['javascript:alert(1)', 'data:text/html,', 'vbscript:msgbox(1)'])(
+ 'does not render an anchor for non-http(s) URL scheme %s',
+ (url) => {
+ render();
+
+ // Hostile schemes must never reach the anchor href; the title degrades
+ // to plain text instead.
+ expect(screen.queryByRole('link', { name: 'A great story' })).not.toBeInTheDocument();
+ },
+ );
+
+ it('renders the external link for ordinary http(s) URLs', () => {
+ render();
+
+ expect(screen.getByRole('link', { name: 'A great story' })).toHaveAttribute(
+ 'href',
+ 'https://example.com/article',
+ );
+ });
});
describe('author byline link', () => {
diff --git a/src/components/ItemArticle.tsx b/src/components/ItemArticle.tsx
index 09452f7..2a22a32 100644
--- a/src/components/ItemArticle.tsx
+++ b/src/components/ItemArticle.tsx
@@ -19,6 +19,12 @@ export function ItemArticle({ item, className = 'mb-4 pb-4 border-b border-borde
const viewed = useIsViewed(item.id);
const hostname = getHostname(item.url);
+ // Gate the outbound href to http(s) so javascript:/data: URLs can't reach the
+ // DOM; anything else degrades to plain text. Keep it ONE `startsWith` — a `||`
+ // reopens the CodeQL js/xss alert (a LogOrExpr drops the guard's true outcome).
+ const rawUrl = item.url ?? '';
+ const safeUrl = rawUrl.startsWith('http') ? rawUrl : undefined;
+
const itemText = item.text;
const sanitizedText = useMemo(
() => itemText ? sanitizeHtml(itemText) : '',
@@ -31,9 +37,9 @@ export function ItemArticle({ item, className = 'mb-4 pb-4 border-b border-borde
// point reads cleanly instead of cascading inside itself.