Audit and fix XSS vulnerabilities
✓Works with OpenClaudeYou are a security engineer specializing in web application vulnerabilities. The user wants to identify and remediate Cross-Site Scripting (XSS) vulnerabilities in their codebase.
What to check first
- Run
grep -r "<script>" --include="*.html" --include="*.js" --include="*.jsx"to find inline script tags - Check your framework's template engine settings (e.g.,
autoEscapein Jinja2,escapeExpressionin Handlebars) - Review all user input handlers with
grep -r "innerHTML\|dangerouslySetInnerHTML\|eval\|Function(" --include="*.js" --include="*.jsx"to locate dangerous DOM manipulation
Steps
- Identify input sources by searching for
request.GET,request.POST,location.search,document.referrer,localStorage,sessionStorage, and URL parameters in your codebase - Trace where user input flows into output by mapping variables from input handlers to DOM insertion points or template rendering calls
- Enable template auto-escaping in your framework: set
jinja_env.autoescape = True(Jinja2),Markup()(Flask), or|escapefilter (Django) by default - Replace all
innerHTMLassignments withtextContentfor plain text, or use DOM methods likeappendChild()withdocument.createElement()andtextContent - Replace React's
dangerouslySetInnerHTMLwith standard JSX curly braces{}which auto-escape by default - For legitimate HTML rendering needs, use DOMPurify library to sanitize:
DOMPurify.sanitize(userInput)before insertion - Add Content Security Policy (CSP) headers:
Content-Security-Policy: default-src 'self'; script-src 'self'to prevent inline script execution - Test with XSS payloads like
<img src=x onerror="alert('xss')">and<svg/onload=alert('xss')>in every input field
Code
// XSS vulnerability scanner and fixer
const fs = require('fs');
const path = require('path');
const DANGEROUS_PATTERNS = [
{ regex: /innerHTML\s*=/, type: 'innerHTML assignment' },
{ regex: /dangerouslySetInnerHTML/, type: 'dangerouslySetInnerHTML' },
{ regex: /eval\(/, type: 'eval()' },
{ regex: /new Function\(/, type: 'Function constructor' },
{ regex: /{{\s*\w+\s*}}(?!.*\|escape)/, type: 'unescaped template var' }
];
function scanFile(filePath) {
const content = fs.readFileSync(filePath, 'utf8');
const vulnerabilities = [];
DANGEROUS_PATTERNS.forEach(
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Security Skills
Other Claude Code skills in the same category — free to download.
Dependency Audit
Audit dependencies for known vulnerabilities
Secret Scanner
Scan codebase for leaked secrets and credentials
CSP Generator
Generate Content Security Policy headers
Input Sanitizer
Add input sanitization to prevent injection attacks
Auth Middleware
Create authentication middleware
RBAC Setup
Implement role-based access control
CSRF Protection
Add CSRF protection to forms and APIs
Security Headers
Configure security headers (HSTS, X-Frame-Options, etc.)
Want a Security skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.