Skip to content

Commit b4b4c4a

Browse files
fix for code scanning alert no. 13: DOM text reinterpreted as HTML
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent ddac7b1 commit b4b4c4a

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

saltgui/static/scripts/Documentation.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import {Utils} from "./Utils.js";
1010

1111
export class Documentation {
1212

13+
static _escapeHtml(unsafe) {
14+
return unsafe
15+
.replace(/&/g, "&amp;")
16+
.replace(/</g, "&lt;")
17+
.replace(/>/g, "&gt;")
18+
.replace(/"/g, "&quot;")
19+
.replace(/'/g, "&#039;");
20+
}
21+
1322
// formatting of the documentation is done as a regular output type
1423
// that is therefore in output.js
1524

@@ -412,8 +421,8 @@ export class Documentation {
412421

413422
if (cmd.length >= 3 && cmd[0] === "modules" && cmd[1] === "beacons" && ["add", "modify"].indexOf(cmd[2]) >= 0 && argsArray.length >= 2 && typeof argsArray[1] === "string") {
414423
const beaconName = argsArray[1];
415-
html += "<p>Beacon-name '" + beaconName + "' cannot be verified. We'll just assume it actually exists. The link below might not work.</p>";
416-
html += "<p><a href='" + Documentation.DOCUMENTATION_URL + "beacons/all/salt.beacons." + beaconName + ".html' target='_blank' rel='noopener'>Beacon Module '" + beaconName + "'</a>" + Documentation.EXTERNAL_LINK + "</p>";
424+
html += "<p>Beacon-name '" + Documentation._escapeHtml(beaconName) + "' cannot be verified. We'll just assume it actually exists. The link below might not work.</p>";
425+
html += "<p><a href='" + Documentation.DOCUMENTATION_URL + "beacons/all/salt.beacons." + Documentation._escapeHtml(beaconName) + ".html' target='_blank' rel='noopener'>Beacon Module '" + Documentation._escapeHtml(beaconName) + "'</a>" + Documentation.EXTERNAL_LINK + "</p>";
417426
}
418427

419428
const output = document.querySelector(".run-command pre");

0 commit comments

Comments
 (0)