Skip to content

Commit 89a4187

Browse files
fix(website): sanitize result markdown rendering
1 parent c73bf9d commit 89a4187

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

website/result.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<link rel="icon" type="image/x-icon" href="favicon.svg" />
66
<link rel="stylesheet" href="result.css" />
77
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
8+
<script src="https://cdn.jsdelivr.net/npm/dompurify@3.2.6/dist/purify.min.js"></script>
89
</head>
910
<body>
1011
<div id="markdown-container"></div>
@@ -21,7 +22,8 @@
2122
);
2223
}
2324
const markdownText = await response.text();
24-
markdownContainer.innerHTML = marked.parse(markdownText);
25+
const renderedMarkdown = marked.parse(markdownText);
26+
markdownContainer.innerHTML = DOMPurify.sanitize(renderedMarkdown);
2527
addHeadingAnchors();
2628
} catch (error) {
2729
console.error("Error loading markdown:", error);
@@ -37,6 +39,7 @@
3739
.replaceAll(" ", "-")
3840
.replaceAll("&", "")
3941
.replaceAll("/", "");
42+
4043
const anchor = document.createElement("a");
4144
anchor.id = anchorId;
4245
anchor.href = "#" + anchorId;
@@ -48,7 +51,11 @@
4851
const hash = window.location.hash;
4952
if (hash) {
5053
const decodedHash = decodeURIComponent(hash);
51-
const target = document.querySelector(decodedHash);
54+
const targetId = decodedHash.startsWith("#")
55+
? decodedHash.slice(1)
56+
: decodedHash;
57+
const target = document.getElementById(targetId);
58+
5259
if (target) {
5360
target.scrollIntoView();
5461
}

0 commit comments

Comments
 (0)