Skip to content

Add security hardening: URL validation, input sanitization, and JSON parsing guards#3

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/check-security-issues
Draft

Add security hardening: URL validation, input sanitization, and JSON parsing guards#3
Copilot wants to merge 4 commits intomainfrom
copilot/check-security-issues

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

Addressed missing security controls that left the app vulnerable to XSS, phishing, prompt injection, and cache poisoning attacks.

Changes

URL Validation (utils/url-validator.ts)

  • Protocol whitelist enforcement (http/https only)
  • Localhost/private IP blocking
  • Phishing pattern detection (@ in hostname)
  • Applied to ExternalLink component

Input Sanitization (utils/event-generation.ts)

  • Strips control chars, quotes, backticks, JSON delimiters from location inputs
  • Prevents prompt injection into AI event generation
  • Length capped at 200 chars

JSON Parsing Guards (utils/event-cache.ts, utils/storage.ts)

  • Type validation and timestamp bounds checking
  • Auto-purges malformed cache entries
  • Extracts magic numbers to constants

Web Security Headers (app/+html.tsx)

  • X-Frame-Options, X-Content-Type-Options, X-XSS-Protection, Referrer-Policy
  • Documents safe use of dangerouslySetInnerHTML for static CSS

Example

// Before: URLs opened without validation
WebBrowser.openBrowserAsync(props.href);

// After: Validated before opening
if (!isValidUrl(props.href)) {
  console.error('[ExternalLink] Invalid or unsafe URL:', props.href);
  return;
}
WebBrowser.openBrowserAsync(props.href);

Audit Results

  • npm audit: 0 vulnerabilities
  • CodeQL: 0 alerts
  • Test suite: 25+ cases for URL validator
Original prompt

Check for security issues


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

Copilot AI and others added 3 commits October 30, 2025 00:35
Co-authored-by: DaInfernalCoder <111019954+DaInfernalCoder@users.noreply.github.com>
Co-authored-by: DaInfernalCoder <111019954+DaInfernalCoder@users.noreply.github.com>
Co-authored-by: DaInfernalCoder <111019954+DaInfernalCoder@users.noreply.github.com>
Copilot AI changed the title [WIP] Check for security issues in the codebase Add security hardening: URL validation, input sanitization, and JSON parsing guards Oct 30, 2025
Copilot AI requested a review from DaInfernalCoder October 30, 2025 00:42
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