Skip to content

Commit 07a8d4d

Browse files
Potential fix for pull request finding 'CodeQL / DOM text reinterpreted as HTML'
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 4d91ef1 commit 07a8d4d

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

apps/webapp/app/components/navigation/NotificationCard.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ import { useLayoutEffect, useRef, useState } from "react";
33
import ReactMarkdown from "react-markdown";
44
import { cn } from "~/utils/cn";
55

6+
function sanitizeActionUrl(url?: string): string | undefined {
7+
if (!url) return undefined;
8+
const trimmed = url.trim();
9+
if (!trimmed) return undefined;
10+
11+
try {
12+
const parsed = new URL(trimmed, window.location.origin);
13+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
14+
return parsed.toString();
15+
}
16+
} catch {
17+
return undefined;
18+
}
19+
20+
return undefined;
21+
}
22+
623
export function NotificationCard({
724
title,
825
description,
@@ -23,6 +40,7 @@ export function NotificationCard({
2340
const [isExpanded, setIsExpanded] = useState(false);
2441
const [isOverflowing, setIsOverflowing] = useState(false);
2542
const descriptionRef = useRef<HTMLDivElement>(null);
43+
const safeActionUrl = sanitizeActionUrl(actionUrl);
2644

2745
useLayoutEffect(() => {
2846
const el = descriptionRef.current;
@@ -50,9 +68,9 @@ export function NotificationCard({
5068

5169
return (
5270
<div className="group/card relative overflow-hidden rounded border border-charcoal-650 bg-charcoal-700/50 shadow-lg">
53-
{actionUrl && (
71+
{safeActionUrl && (
5472
<a
55-
href={actionUrl}
73+
href={safeActionUrl}
5674
target="_blank"
5775
rel="noopener noreferrer"
5876
aria-label={title}

0 commit comments

Comments
 (0)