Potential fix for code scanning alert no. 44: DOM text reinterpreted as HTML

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Xin Jin
2025-07-09 11:20:20 -07:00
committed by GitHub
co-authored by Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
parent 63eb9865c7
commit 0135af8d67
2 changed files with 7 additions and 9 deletions
+5 -8
View File
@@ -25,15 +25,12 @@ j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
try {
let rawContent = markdownScript.textContent;
// HTML entity decoding function
function decodeHtmlEntities(text) {
const tempDiv = document.createElement('div');
tempDiv.innerHTML = text;
return tempDiv.textContent || tempDiv.innerText || '';
}
// Import a library for decoding HTML entities
import { decode } from 'he';
// Always decode HTML entities using a safe library
rawContent = decode(rawContent);
// Always decode HTML entities since the browser might encode them
rawContent = decodeHtmlEntities(rawContent);
const data = JSON.parse(rawContent);
const content = `# ${data.title}\n\nSource: ${window.location.href}\n\n${data.markdown}`;
+2 -1
View File
@@ -9,7 +9,8 @@
"@langchain/core": "^0.3.38",
"@langchain/openai": "^0.4.2",
"msgpack-lite": "^0.1.26",
"nock": "^14.0.1"
"nock": "^14.0.1",
"he": "^1.2.0"
},
"devDependencies": {
"@tsconfig/recommended": "^1.0.8",