Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 9, 2025

Addresses XSS vulnerability in Discogs markup parsing where unsanitized user content from the Discogs API could be injected into the DOM through [url] tags and link text.

Changes

Added DOMPurify dependency

  • Provides trusted HTML sanitization for user-provided content

Implemented sanitizeUrl() function

  • Validates URL format using native URL API
  • Restricts protocols to http:, https:, ftp: only
  • Returns safe placeholder # for invalid/malicious URLs (e.g., javascript:, data:)
  • Decodes HTML entities before validation

Sanitized all user-controlled strings

  • Link text in [url=...]text[/url] tags stripped of HTML
  • Display names in [a=name] search links stripped of HTML
  • Display URLs in [url]...[/url] tags use validated URL

Example

Before:

// Vulnerable to XSS
result.replace(/\[url=(.*?)\](.*?)\[\/url\]/gi, 
  '<a href="$1">$2</a>');

After:

// Sanitized and validated
result.replace(/\[url=(.*?)\](.*?)\[\/url\]/gi, (_, url, text) => {
  const sanitizedUrl = sanitizeUrl(url);  // Protocol validation
  const sanitizedText = DOMPurify.sanitize(text, { ALLOWED_TAGS: [] });
  return `<a href="${sanitizedUrl}">${sanitizedText}</a>`;
});

Blocks: javascript:alert(1), data:text/html,<script>..., <img onerror=alert(1)>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: BeardedBear <7188702+BeardedBear@users.noreply.github.com>
@socket-security
Copy link

socket-security bot commented Dec 9, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​dompurify@​3.0.51001007180100
Addeddompurify@​3.3.1981001009070

View full report

Co-authored-by: BeardedBear <7188702+BeardedBear@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on Discogs and Wikipedia/Wikidata support Add URL validation and DOMPurify sanitization to Discogs markup parser Dec 9, 2025
Copilot AI requested a review from BeardedBear December 9, 2025 22:18
@BeardedBear BeardedBear marked this pull request as ready for review December 9, 2025 22:36
@BeardedBear BeardedBear merged commit c3bf7e8 into add-discogs-support Dec 9, 2025
2 checks passed
@BeardedBear BeardedBear deleted the copilot/sub-pr-180-another-one branch December 9, 2025 22:36
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