Fix: prevent XSS in createModal by building modal via DOM APIs (avoid… #138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes a cross-site scripting (XSS) vulnerability in the modal helper. The modal was previously constructed
using string templates and
innerHTML, which allowed injected HTML (for example<script>tags oronerrorattributes) to execute. This change refactors the modal to build its DOM using the existingelem()helper anddocument.createTextNode, so user-supplied strings are inserted as plain text andcannot execute as HTML.
Files changed:
javascript/UI/modal.js— refactored to removeinnerHTMLand build modal via DOM APIs.Motivation and context:
Using
innerHTMLwith untrusted input opened the app to XSS when titles or content included maliciousmarkup. The refactor eliminates that attack vector while preserving the modal API. If callers require
rich HTML rendering, they should sanitize input first (e.g. DOMPurify) and pass a trusted DOM node.
Dependencies:
Please delete options that are not relevant.
How Has This Been Tested?
Manual testing on the local development server (
npm run server) athttp://localhost:8000.Verification performed by creating modals with safe strings and with known malicious payloads; observed that
malicious markup is rendered as inert text and no injected scripts or event handlers executed.
Before test

After test

Testing Checklist
Checklist