fix: resolve the open CodeQL alerts (#156)

Strip HTML tags and XML comments until the text no longer changes, so that
nested input cannot reassemble a tag or comment after a single pass
(js/incomplete-multi-character-sanitization in website/.eleventy.js and
website/scripts/validate-version-info.js).

Limit the GITHUB_TOKEN of the PR compile check and the test version-XML
workflow to read access (actions/missing-workflow-permissions).

Claude-Session: https://claude.ai/code/session_01FJBfPYm6rCH4zD6T7bcC7Y
This commit is contained in:
Rsclub2_2 authored and GitHub committed 2026-10-26 10:13:10 +01:00
1 parent f165f7d303
commit 8fc3b9f424
4 files changed
+43 -6

No files matched your search

+3
View File
@@ -6,6 +6,9 @@ on:
- main - main
workflow_dispatch: workflow_dispatch:
permissions:
contents: read
env: env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
@@ -3,6 +3,10 @@ name: TEST publish-version-xml (local only)
on: on:
workflow_dispatch: workflow_dispatch:
permissions:
contents: read
issues: read
jobs: jobs:
publish-version-xml: publish-version-xml:
name: Publish Version Info XML via WebDAV name: Publish Version Info XML via WebDAV
+18 -3
View File
@@ -32,11 +32,26 @@ const MANUAL_PAGE_ORDER = {
] ]
}; };
// Removes HTML tags until none are left, so that nested input such as
// "<<b>script>" cannot reassemble a tag after a single pass.
function stripHtmlTags(value) {
let previous;
let current = value;
do {
previous = current;
current = current.replace(/<[^>]+>/g, "");
} while (current !== previous);
return current;
}
function markdownToPlainText(value) { function markdownToPlainText(value) {
return (value || "") const withoutLinks = (value || "")
.replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1") .replace(/!\[([^\]]*)\]\([^)]+\)/g, "$1")
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") .replace(/\[([^\]]+)\]\([^)]+\)/g, "$1");
.replace(/<[^>]+>/g, "")
return stripHtmlTags(withoutLinks)
.replace(/[*_~`]/g, "") .replace(/[*_~`]/g, "")
.replace(/\s+/g, " ") .replace(/\s+/g, " ")
.trim(); .trim();
+18 -3
View File
@@ -28,14 +28,29 @@ function extractTag(xml, tagName) {
return match ? match[1].trim() : null; return match ? match[1].trim() : null;
} }
// Applies the removal until nothing changes, so that nested input such as
// "<!-<!---->-->" cannot leave a fresh comment behind after a single pass.
function removeUntilStable(value, pattern) {
let previous;
let current = value;
do {
previous = current;
current = current.replace(pattern, "");
} while (current !== previous);
return current;
}
function assertWellFormedStructure(xml) { function assertWellFormedStructure(xml) {
if (/&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9a-f]+;)/i.test(xml)) { if (/&(?!amp;|lt;|gt;|quot;|apos;|#\d+;|#x[0-9a-f]+;)/i.test(xml)) {
fail("the XML contains an unescaped ampersand"); fail("the XML contains an unescaped ampersand");
} }
const withoutCommentsAndDeclaration = xml const withoutCommentsAndDeclaration = removeUntilStable(
.replace(/<!--[\s\S]*?-->/g, "") xml,
.replace(/<\?[\s\S]*?\?>/g, ""); /<!--[\s\S]*?-->|<\?[\s\S]*?\?>/g
);
const tagPattern = const tagPattern =
/<\/?([A-Za-z_][\w:.-]*)(?:\s[^<>]*?)?\s*\/?>/g; /<\/?([A-Za-z_][\w:.-]*)(?:\s[^<>]*?)?\s*\/?>/g;