Skip to content

fix: stability and formatting#63

Merged
dimyjeannot merged 8 commits intomainfrom
OECO-STABILITY-1
Jul 26, 2025
Merged

fix: stability and formatting#63
dimyjeannot merged 8 commits intomainfrom
OECO-STABILITY-1

Conversation

@dimyjeannot
Copy link
Contributor

No description provided.

@dimyjeannot dimyjeannot merged commit a2ee1df into main Jul 26, 2025
4 of 5 checks passed
@dimyjeannot dimyjeannot deleted the OECO-STABILITY-1 branch July 26, 2025 11:18
link.classList.remove(ACTIVE_CLASS);
last = document.createElement('li') as ListItem;
let text = tmp.lastElementChild.textContent.trim();
last.innerHTML = `<a class="DocsTableOfContents-link" href="#${tmp.id}">${text}</a>`;

Check failure

Code scanning / CodeQL

DOM text reinterpreted as HTML High documentation

DOM text
is reinterpreted as HTML without escaping meta-characters.

Copilot Autofix

AI 7 months ago

To fix the issue, the textContent value should be properly escaped before being interpolated into the HTML string. Escaping ensures that any special characters in the text (e.g., <, >, &) are converted into their corresponding HTML entities, preventing them from being interpreted as HTML or JavaScript. This can be achieved by using a utility function to escape the text before embedding it into the HTML.

The fix involves:

  1. Adding a utility function to escape HTML special characters.
  2. Replacing the direct interpolation of text in line 32 with the escaped version of text.

Suggested changeset 1
apps/web/public/docs/v2alpha/assets/contents.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/web/public/docs/v2alpha/assets/contents.ts b/apps/web/public/docs/v2alpha/assets/contents.ts
--- a/apps/web/public/docs/v2alpha/assets/contents.ts
+++ b/apps/web/public/docs/v2alpha/assets/contents.ts
@@ -5,2 +5,11 @@
 const ACTIVE_CLASS = 'DocsTableOfContents-link-active';
+function escapeHtml(unsafe: string): string {
+    return unsafe
+        .replace(/&/g, "&amp;")
+        .replace(/</g, "&lt;")
+        .replace(/>/g, "&gt;")
+        .replace(/"/g, "&quot;")
+        .replace(/'/g, "&#039;");
+}
+
 export function toc() {
@@ -31,3 +40,3 @@
             let text = tmp.lastElementChild.textContent.trim();
-            last.innerHTML = `<a class="DocsTableOfContents-link" href="#${tmp.id}">${text}</a>`;
+            last.innerHTML = `<a class="DocsTableOfContents-link" href="#${tmp.id}">${escapeHtml(text)}</a>`;
             container.appendChild(last);
EOF
@@ -5,2 +5,11 @@
const ACTIVE_CLASS = 'DocsTableOfContents-link-active';
function escapeHtml(unsafe: string): string {
return unsafe
.replace(/&/g, "&amp;")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
.replace(/"/g, "&quot;")
.replace(/'/g, "&#039;");
}

export function toc() {
@@ -31,3 +40,3 @@
let text = tmp.lastElementChild.textContent.trim();
last.innerHTML = `<a class="DocsTableOfContents-link" href="#${tmp.id}">${text}</a>`;
last.innerHTML = `<a class="DocsTableOfContents-link" href="#${tmp.id}">${escapeHtml(text)}</a>`;
container.appendChild(last);
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant