Skip to content

Commit 7cf0dec

Browse files
FuturMixclaude
andcommitted
fix: escape URL in href attribute and display text in url-link-converter
The convertUrlsToLinks function places matched URLs directly into HTML without escaping. While the regex excludes most HTML metacharacters, the & character can appear in query strings and should be escaped as &amp; for valid HTML. Apply escapeHtml() to both the href attribute value and the display text for defense-in-depth. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cba49e7 commit 7cf0dec

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/lib/utils/url-link-converter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ export function convertUrlsToLinks(text) {
6262
const beforeUrl = textWithPlaceholders.slice(lastIndex, match.index);
6363
result += escapeHtml(beforeUrl);
6464

65-
// Add the URL as a clickable link
65+
// Add the URL as a clickable link (escape in both href and display text)
6666
const url = match[0];
67-
result += `<a href="${url}" target="_blank" rel="noopener noreferrer">${url}</a>`;
67+
const escapedUrl = escapeHtml(url);
68+
result += `<a href="${escapedUrl}" target="_blank" rel="noopener noreferrer">${escapedUrl}</a>`;
6869

6970
lastIndex = httpsUrlRegex.lastIndex;
7071
}

0 commit comments

Comments
 (0)