Input Sanitization Missing on User-Generated Content (#82)#85
Merged
Conversation
|
@Ayaanshaikh12243 is attempting to deploy a commit to the csxark's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
close #82
Fix: Input Sanitization Missing on User-Generated Content (#82)
Overview
This PR implements comprehensive XSS prevention and input sanitization for all user-generated content across the platform.
Problem
User-generated content (team names, challenge descriptions, team notes) lacked sanitization, allowing:
Solution Implemented
1) Frontend input sanitization + validation
Added file:
src/utils/inputSecurity.tsProvides centralized utilities:
sanitizePlainText(value, maxLength)– strips HTML, control chars, normalizes whitespacesanitizeMultilineText(value, maxLength)– allows newlines, prevents triple newlinessanitizeTeamName(value)– applies regex validation (3-32 chars, alphanumeric/dash/underscore/dot)isValidTeamName(value)– checks format before submissionsafeDisplayText(value, maxLength)– safe render wrapperUpdated files:
src/pages/Profile.tsx– sanitizes profile form inputs before submissionsrc/components/TeamManagement.tsx– sanitizes team names on create, safe display on rendersrc/components/Leaderboard.tsx– safe display of team names in rankings2) Server-side input sanitization in Edge Function
Updated file:
supabase/functions/validate-flag/index.tsAdded:
sanitizePlainText(value, maxLen)– server-side equivalentsanitizeTeamName(value)– validates team name format3) Database-level sanitization triggers
Added migration:
Databases/supabase/migrations/20260303_sanitize_user_generated_content.sqlCreates:
sanitize_plain_text()function – removes HTML tags, control charsvalidate_team_name()function – enforces 3-32 char alphanumeric + dash/underscore/dotprofiles(team_name, leader_name)teams(team_name)team_notes(note_content)leaderboard(team_name, category, difficulty)challenge_submissions(title, description, category, difficulty, hints)4) Content Security Policy (CSP) headers
Updated files:
vite.config.ts– added security header configuration with CSPindex.html– added CSP meta tag in document headCSP policy:
default-src 'self'– only load from same originscript-src 'self'– no inline scriptsstyle-src 'self' 'unsafe-inline'– allow inline CSS (required for Tailwind)img-src 'self' data: https:– images from self or HTTPS/data URLsobject-src 'none'– no pluginsframe-ancestors 'none'– prevent clickjackingSecurity Improvements
Files Changed
package.json– added DOMPurify dependencysrc/utils/inputSecurity.ts– new sanitization utilitiessrc/pages/Profile.tsx– integrated sanitization on form submissionsrc/components/TeamManagement.tsx– integrated sanitization on create, safe displaysrc/components/Leaderboard.tsx– integrated safe displaysupabase/functions/validate-flag/index.ts– server-side sanitizationDatabases/supabase/migrations/20260303_sanitize_user_generated_content.sql– database levelvite.config.ts– CSP headers configindex.html– CSP meta tagTesting Checklist
<script>alert('xss')</script>→ sanitized to plain textDeployment Notes
Follow-up