Skip to content

Commit cd94460

Browse files
Potential fix for pull request finding 'CodeQL / Incomplete URL substring sanitization'
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 88d4774 commit cd94460

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/lib/markdown/mdxParse.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,18 @@ function handleHTML(html: string, info: TransformerInfo) {
6363
const { url, transformer } = info;
6464

6565
if (transformer.name === "@remark-embedder/transformer-oembed") {
66-
if (url.includes("www.youtube.com")) {
66+
let host = "";
67+
try {
68+
host = new URL(url).hostname.toLowerCase();
69+
} catch {
70+
return html;
71+
}
72+
73+
if (host === "www.youtube.com") {
6774
return `<div class="embed-youtube aspect-w-16 aspect-h-9">${html}</div>`;
6875
}
6976

70-
if (url.includes("twitter.com")) {
77+
if (host === "twitter.com" || host.endsWith(".twitter.com")) {
7178
return `<div class="embed-twitter h-full">${html}</div>`;
7279
}
7380
}

0 commit comments

Comments
 (0)