From 5611a641f95651b8dd26bb9233f12fd1e7a88558 Mon Sep 17 00:00:00 2001 From: luen Date: Tue, 3 Nov 2026 09:08:16 +1000 Subject: [PATCH 1/2] Fix Snyk critical/high dependency issues and harden media hrefs. Pin undici to ^7.30.1 (cheerio transitive), document the unfixed picomatch ReDoS in .snyk, and route media links through toAbsoluteHttpUrl. Co-authored-by: Cursor --- .snyk | 9 +++++++++ app/media/MediaCoverageList.tsx | 30 ++++++++++++------------------ app/media/MediaSourceTags.tsx | 18 ++++-------------- lib/external-url.ts | 3 ++- package.json | 4 ++-- pnpm-lock.yaml | 10 +++++----- 6 files changed, 34 insertions(+), 40 deletions(-) diff --git a/.snyk b/.snyk index 84de3ac..07c99c6 100644 --- a/.snyk +++ b/.snyk @@ -9,4 +9,13 @@ ignore: limit); no npm release yet expires: 2027-09-30T00:00:00.000Z created: 2026-09-30T04:41:26.228Z + SNYK-JS-PICOMATCH-21248802: + - '*': + reason: >- + No npm release yet for CVE-2026-112366 (open upstream PRs only). + picomatch is reached only via next-sitemap / fast-glob / micromatch + at build time with developer-controlled patterns; no untrusted glob + input is accepted at runtime + expires: 2027-05-03T00:00:00.000Z + created: 2026-11-03T00:00:00.000Z patch: {} diff --git a/app/media/MediaCoverageList.tsx b/app/media/MediaCoverageList.tsx index 347d62d..854ab49 100644 --- a/app/media/MediaCoverageList.tsx +++ b/app/media/MediaCoverageList.tsx @@ -1,6 +1,7 @@ "use client"; import { useMemo, useState } from "react"; +import { toAbsoluteHttpUrl } from "@/lib/external-url"; import { DEFAULT_SCHOLAR_ID } from "@/lib/news"; import { getMediaSources, type MediaItem } from "@/types/media"; import { ArticleImage } from "./ArticleImage"; @@ -15,18 +16,6 @@ const MEDIA_TYPE_LABELS: Record = { press: "Press release", }; -const hasValidUrl = (url?: string): boolean => { - if (!url || typeof url !== "string") return false; - const trimmed = url.trim(); - if (!trimmed) return false; - try { - const parsed = new URL(trimmed); - return parsed.protocol === "http:" || parsed.protocol === "https:"; - } catch { - return false; - } -}; - type Props = { initialItems: MediaItem[]; initialTotal: number; @@ -34,10 +23,15 @@ type Props = { initialOffset?: number; }; +const sanitizeMediaItem = (item: MediaItem): MediaItem => ({ + ...item, + url: toAbsoluteHttpUrl(item.url) ?? undefined, +}); + export function MediaCoverageList(props: Props) { const { initialItems, initialTotal, initialLimit = DEFAULT_LIMIT, initialOffset = 0 } = props; - const [items, setItems] = useState(initialItems); + const [items, setItems] = useState(() => initialItems.map(sanitizeMediaItem)); const [total, setTotal] = useState(initialTotal); const [limit, setLimit] = useState(initialLimit); const [offset, setOffset] = useState(initialOffset); @@ -74,7 +68,7 @@ export function MediaCoverageList(props: Props) { media?: MediaItem[]; }; - const newItems = Array.isArray(data.media) ? data.media : []; + const newItems = Array.isArray(data.media) ? data.media.map(sanitizeMediaItem) : []; if (newItems.length === 0) { return; } @@ -92,11 +86,11 @@ export function MediaCoverageList(props: Props) {
{sortedItems.map((article, index) => { const outlets = getMediaSources(article); - const urlOk = hasValidUrl(article.url); + const safeUrl = toAbsoluteHttpUrl(article.url); return (
@@ -110,9 +104,9 @@ export function MediaCoverageList(props: Props) {

- {urlOk ? ( + {safeUrl ? ( { - if (!url || typeof url !== "string") return false; - const trimmed = url.trim(); - if (!trimmed) return false; - try { - const parsed = new URL(trimmed); - return parsed.protocol === "http:" || parsed.protocol === "https:"; - } catch { - return false; - } -}; - interface SourceTagProps { outlet: MediaSource; } @@ -25,14 +14,15 @@ interface SourceTagProps { function SourceTag({ outlet }: SourceTagProps) { const { bgColor, textColor } = getSourceTagColors(outlet.name); const tagClassName = `inline-block px-2 py-1 text-sm font-medium ${bgColor} ${textColor} rounded-sm`; + const safeUrl = toAbsoluteHttpUrl(outlet.url); - if (!hasValidUrl(outlet.url)) { + if (!safeUrl) { return {outlet.name}; } return ( =20.18.1'} unified@11.0.5: @@ -4314,7 +4314,7 @@ snapshots: parse5: 7.3.0 parse5-htmlparser2-tree-adapter: 7.1.0 parse5-parser-stream: 7.1.2 - undici: 7.30.0 + undici: 7.30.1 whatwg-mimetype: 4.0.0 client-only@0.0.1: {} @@ -6229,7 +6229,7 @@ snapshots: undici-types@8.9.0: {} - undici@7.30.0: {} + undici@7.30.1: {} unified@11.0.5: dependencies: From 592c0b7a34fe261cc2fdfe0bfc720f90122c9b6e Mon Sep 17 00:00:00 2001 From: luen Date: Tue, 3 Nov 2026 09:20:52 +1000 Subject: [PATCH 2/2] Reject cross-origin same-origin paths in toAbsoluteHttpUrl Paths like `/\evil.com` or `//evil.com` were returned raw, but browsers resolve them to another origin. Resolve same-origin paths against a sentinel base and return only pathname/search/hash when the origin is unchanged. Drop the redundant sanitizeMediaItem pass; the href sink already sanitises. Co-Authored-By: Claude Opus 5.5 --- app/media/MediaCoverageList.tsx | 9 ++------- lib/external-url.test.ts | 10 ++++++++++ lib/external-url.ts | 13 +++++++++++-- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/media/MediaCoverageList.tsx b/app/media/MediaCoverageList.tsx index 854ab49..00f70a1 100644 --- a/app/media/MediaCoverageList.tsx +++ b/app/media/MediaCoverageList.tsx @@ -23,15 +23,10 @@ type Props = { initialOffset?: number; }; -const sanitizeMediaItem = (item: MediaItem): MediaItem => ({ - ...item, - url: toAbsoluteHttpUrl(item.url) ?? undefined, -}); - export function MediaCoverageList(props: Props) { const { initialItems, initialTotal, initialLimit = DEFAULT_LIMIT, initialOffset = 0 } = props; - const [items, setItems] = useState(() => initialItems.map(sanitizeMediaItem)); + const [items, setItems] = useState(initialItems); const [total, setTotal] = useState(initialTotal); const [limit, setLimit] = useState(initialLimit); const [offset, setOffset] = useState(initialOffset); @@ -68,7 +63,7 @@ export function MediaCoverageList(props: Props) { media?: MediaItem[]; }; - const newItems = Array.isArray(data.media) ? data.media.map(sanitizeMediaItem) : []; + const newItems = Array.isArray(data.media) ? data.media : []; if (newItems.length === 0) { return; } diff --git a/lib/external-url.test.ts b/lib/external-url.test.ts index c37d2f4..24f3b54 100644 --- a/lib/external-url.test.ts +++ b/lib/external-url.test.ts @@ -16,6 +16,16 @@ describe('toAbsoluteHttpUrl', () => { it('preserves same-origin paths', () => { expect(toAbsoluteHttpUrl('/papers/example.pdf')).toBe('/papers/example.pdf'); + expect(toAbsoluteHttpUrl('/media/a.pdf?x=1#p2')).toBe('/media/a.pdf?x=1#p2'); + }); + + it('rejects paths that browsers resolve to another origin', () => { + expect(toAbsoluteHttpUrl('/\\evil.com')).toBeNull(); + expect(toAbsoluteHttpUrl('/\t/evil.com')).toBeNull(); + }); + + it('drops credentials when rebuilding absolute URLs', () => { + expect(toAbsoluteHttpUrl('https://user:pass@example.com/a')).toBe('https://example.com/a'); }); it('rejects empty, javascript, and mailto values', () => { diff --git a/lib/external-url.ts b/lib/external-url.ts index e969925..afdda13 100644 --- a/lib/external-url.ts +++ b/lib/external-url.ts @@ -1,3 +1,5 @@ +const SAME_ORIGIN_BASE = 'https://same-origin.invalid'; + /** * Turn a website field into an absolute http(s) URL. * Bare domains like `sharkmeasurements.com` become `https://sharkmeasurements.com`. @@ -15,8 +17,15 @@ export const toAbsoluteHttpUrl = (value: string | undefined | null): string | nu if (candidate.startsWith('//')) { candidate = `https:${candidate}`; } else if (candidate.startsWith('/')) { - // Same-origin path — leave for callers that need internal links. - return candidate; + // Same-origin path for internal links. Browsers read `/\host` or `//host` + // as protocol-relative, so resolve it and reject anything that leaves the origin. + try { + const parsed = new URL(candidate, SAME_ORIGIN_BASE); + if (parsed.origin !== SAME_ORIGIN_BASE) return null; + return `${parsed.pathname}${parsed.search}${parsed.hash}`; + } catch { + return null; + } } else { candidate = `https://${candidate.replace(/^\/+/, '')}`; }