Skip to content

Fix XSS in Project.js createLinks() via innerHTML#6534

Open
dmetzner wants to merge 2 commits intomainfrom
feature/6510-xss-createlinks
Open

Fix XSS in Project.js createLinks() via innerHTML#6534
dmetzner wants to merge 2 commits intomainfrom
feature/6510-xss-createlinks

Conversation

@dmetzner
Copy link
Copy Markdown
Collaborator

@dmetzner dmetzner commented Apr 2, 2026

Summary

  • Fixed XSS vulnerability in createLinks() (assets/Project/Project.js) where innerHTML with regex replacement allowed script injection through crafted project descriptions
  • Replaced unsafe innerHTML replacement with safe DOM API: reads text via textContent, builds anchor elements with document.createElement('a'), and assembles output using DocumentFragment
  • Preserves existing behavior: URLs (http, https, ftp) in project descriptions are still converted to clickable links

Test plan

  • Verify project descriptions with URLs still render as clickable links
  • Verify project descriptions with <script> tags or HTML are safely escaped
  • Run web-project-details Behat suite

Closes #6510

🤖 Generated with Claude Code

…nerHTML

Replace regex-based innerHTML replacement with safe DOM manipulation using
textContent, document.createElement('a'), and DocumentFragment to prevent
XSS injection via malicious project descriptions.

Closes #6510

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comment thread assets/Project/Project.js Fixed
Use setAttribute with explicit protocol check to prevent CodeQL
"DOM text reinterpreted as HTML" false positive on the href assignment.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Comment thread assets/Project/Project.js
}
const url = match[0]
const a = document.createElement('a')
a.setAttribute('href', /^(https?|ftp):\/\//i.test(url) ? url : '#')

Check failure

Code scanning / CodeQL

DOM text reinterpreted as HTML High

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

Copilot Autofix

AI 13 days ago

Copilot could not generate an autofix suggestion

Copilot could not generate an autofix suggestion for this alert. Try pushing a new commit or if the problem persists contact support.

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.

Security: XSS in Project.js createLinks() via innerHTML regex replacement

2 participants