Skip to content

fix: Resolve CodeQL security findings (CSRF, regex, dynamic method call)#107

Merged
rdmueller merged 3 commits into
LLM-Coding:mainfrom
raifdmueller:main
Feb 20, 2026
Merged

fix: Resolve CodeQL security findings (CSRF, regex, dynamic method call)#107
rdmueller merged 3 commits into
LLM-Coding:mainfrom
raifdmueller:main

Conversation

@raifdmueller

@raifdmueller raifdmueller commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 5 CodeQL security findings discovered after enabling CodeQL SAST.

Findings fixed

File Rule Severity Fix
anchor-modal.js (3x) js/client-side-request-forgery error Validate anchorId before use in fetch()
router.js js/unvalidated-dynamic-method-call warning Validate anchorId from URL hash
website.spec.js js/regex/missing-regexp-anchor warning Anchor GitHub URL regex

Test plan

  • npm run lint — 0 errors
  • npm run format:check — clean
  • npm run test — 70 unit tests pass
  • E2E tests pass (28 tests)
  • CodeQL — 0 findings (verified on fork)

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Verbesserte Validierung von Anker-Verweisen für erhöhte Stabilität
    • Automatisches Fallback auf englische Inhalte, wenn sprachspezifische Versionen nicht verfügbar sind
  • Tests

    • Strengere Validierung von URL-Formaten in Testfällen

raifdmueller and others added 3 commits February 20, 2026 12:52
- anchor-modal.js: Validate anchorId against safe pattern before use
  in fetch() URLs (fixes js/client-side-request-forgery x3)
  Also validate lang code before use in URL
- router.js: Validate anchorId from URL hash before passing to
  showAnchorDetails (fixes js/unvalidated-dynamic-method-call)
- website.spec.js: Anchor GitHub URL regex to prevent partial host
  matching (fixes js/regex/missing-regexp-anchor)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Der Pull Request fügt Input-Validierung für Anchor-IDs und Sprachbehandlung hinzu. In anchor-modal.js werden anchorId und Sprache validiert mit Fallbacks zu Englisch. In router.js wird die Anchor-ID vor der Weiterverarbeitung überprüft. In website.spec.js wird eine Test-Assertion für GitHub-URLs verschärft.

Changes

Cohort / File(s) Summary
Anchor-Validierung
website/src/components/anchor-modal.js, website/src/utils/router.js
Fügt Input-Validierung für anchorId mit Regex-Überprüfung hinzu und normalisiert Sprachbehandlung mit Fallback zu Englisch.
Test-Assertion
website/tests/e2e/website.spec.js
Verschärft GitHub-URL-Pattern von lockerem Regex zu striktem HTTPS-Format mit vollständigem Pfad-Match.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Der Titel bezieht sich direkt auf die Hauptänderung: Behebung von CodeQL-Sicherheitsfunden (CSRF, Regex, dynamischer Methodenaufruf). Dies entspricht dem Kern der Änderungen in drei Dateien.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
website/src/components/anchor-modal.js (1)

170-181: Defense-in-Depth: Optional anchorId-Validierung für Cross-References.

Die anchorId aus internen AsciiDoc-Cross-References (Zeile 174) wird ohne Validierung in window.location.hash eingefügt. Obwohl router.js die ID später validiert, könnte eine zusätzliche Prüfung hier schädliche Cross-References früher abfangen.

🛡️ Vorgeschlagene Änderung
     contentEl.querySelectorAll('a[href^="#"]').forEach((link) => {
       const href = link.getAttribute('href')
       // Only process simple hash links (cross-references), not hash routes
       if (href && href.startsWith('#') && !href.startsWith('#/')) {
         const anchorId = href.substring(1) // Remove the '#'
+        if (!SAFE_ANCHOR_ID.test(anchorId)) return
         link.addEventListener('click', (e) => {
           e.preventDefault()
           // Navigate to the linked anchor
           window.location.hash = `#/anchor/${anchorId}`
         })
       }
     })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/src/components/anchor-modal.js` around lines 170 - 181, Validate the
extracted anchorId before writing it into window.location.hash to provide
defense-in-depth: inside the contentEl.querySelectorAll('a[href^="#"]') loop
(where anchorId is set and link.addEventListener is added), check anchorId
against a safe pattern (e.g. allow only alphanumerics and a limited set of safe
punctuation like - _ : .) and skip or ignore the click (after
e.preventDefault()) if the anchorId fails validation; keep router.js validation
but do not forward unsafe values into window.location.hash and optionally
log/console.warn when rejecting an invalid anchorId for debugging.
website/src/utils/router.js (1)

54-54: Optional: Regex-Duplikation extrahieren.

Dieselbe Regex /^[a-z0-9]+(?:-[a-z0-9]+)*$/ wird sowohl hier als auch in anchor-modal.js (Zeile 109 als SAFE_ANCHOR_ID) definiert. Falls weitere Validierungsstellen hinzukommen, könnte ein gemeinsames Modul (z.B. utils/validation.js) die Wartbarkeit verbessern.

Die aktuelle Duplikation ist jedoch als Defense-in-Depth-Ansatz vertretbar.

Also applies to: 109-109

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@website/src/utils/router.js` at line 54, Duplizierte Regex-Validierung für
Anchor-IDs: extrahiere die Regex `/^[a-z0-9]+(?:-[a-z0-9]+)*$/` in ein
gemeinsames Utility (z.B. export const SAFE_ANCHOR_ID or isValidAnchorId) und
ersetze die inline-Checks in router.js (variable safeAnchorId) und
anchor-modal.js (SAFE_ANCHOR_ID) durch einen Import aus utils/validation.js;
stelle sicher, dass der Export sowohl die Regex als Konstanten als auch eine
kleine Helferfunktion (isValidAnchorId) zur Verfügung stellt, damit zukünftige
Validierungsstellen dieselbe Referenz nutzen.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@website/src/components/anchor-modal.js`:
- Around line 170-181: Validate the extracted anchorId before writing it into
window.location.hash to provide defense-in-depth: inside the
contentEl.querySelectorAll('a[href^="#"]') loop (where anchorId is set and
link.addEventListener is added), check anchorId against a safe pattern (e.g.
allow only alphanumerics and a limited set of safe punctuation like - _ : .) and
skip or ignore the click (after e.preventDefault()) if the anchorId fails
validation; keep router.js validation but do not forward unsafe values into
window.location.hash and optionally log/console.warn when rejecting an invalid
anchorId for debugging.

In `@website/src/utils/router.js`:
- Line 54: Duplizierte Regex-Validierung für Anchor-IDs: extrahiere die Regex
`/^[a-z0-9]+(?:-[a-z0-9]+)*$/` in ein gemeinsames Utility (z.B. export const
SAFE_ANCHOR_ID or isValidAnchorId) und ersetze die inline-Checks in router.js
(variable safeAnchorId) und anchor-modal.js (SAFE_ANCHOR_ID) durch einen Import
aus utils/validation.js; stelle sicher, dass der Export sowohl die Regex als
Konstanten als auch eine kleine Helferfunktion (isValidAnchorId) zur Verfügung
stellt, damit zukünftige Validierungsstellen dieselbe Referenz nutzen.

@rdmueller rdmueller merged commit 42371c8 into LLM-Coding:main Feb 20, 2026
7 checks passed
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.

2 participants