Skip to content

[Security] Replace Insufficient HTML Tag Removal Regex with Robust XSS Sanitization #29

@mrwebwork

Description

@mrwebwork

Problem

The current HTML tag removal regex (/\u003c[^\u003e]*\u003e/g) is insufficient for XSS prevention. It does not account for:

  • Encoded HTML entities
  • Malformed or nested tags
  • JavaScript protocol injection (e.g., javascript:)

This allows for potential bypasses and XSS vulnerabilities in user input.

Suggested Solution

  • Do not rely on regex for sanitization.
  • Integrate a well-maintained HTML sanitization library (e.g., DOMPurify) or a similar vetted package.
  • Ensure the solution neutralizes encoded entities, malformed tags, and script-based protocol injections.
  • Add automated tests for various XSS payloads and edge cases.

References


Labels: bug, good first issue
Assignees: @app/copilot-swe-agent, @mrwebwork

Metadata

Metadata

Labels

bugSomething isn't workinggood first issueGood for newcomers

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions