This checklist provides actionable steps to secure web components (e.g., custom elements, reusable UI modules) against common vulnerabilities. It focuses on injection mitigations, third-party script hygiene, and DOM sandboxing. Use it during design, development, review, and deployment phases. Items are categorized with verification methods.
1. Injection Mitigations
Prevent code injection attacks (e.g., XSS, template injection) by validating inputs, encoding outputs, and restricting execution contexts.
Input Validation: Enforce strict allow-lists for all user inputs (e.g., props, attributes, events). Reject or sanitize unexpected data types/formats.
Verify: Unit tests fuzz inputs; use tools like OWASP ZAP for scanning.
Output Encoding: Always encode dynamic content before insertion (e.g., use textContent over innerHTML; libraries like DOMPurify for HTML).
Verify: Audit all DOM manipulations; static analysis with ESLint plugins (e.g., no-innerhtml).
Avoid Dangerous APIs: Ban eval(), setTimeout(string), innerHTML, document.write(). Use safe alternatives (e.g., Function constructor only if polyfilling trusted code).
Automated Testing: Integrate checklist into CI/CD (e.g., Lighthouse security audits, Playwright for XSS tests).
Manual Review: Peer code review with checklist; penetration test components.
Documentation: Log compliance status per component; update on deps changes.
Incident Response: Define fallback (e.g., CSP report-to) for violations.
Scoring: Aim for 100% compliance. Prioritize high-risk components (e.g., those handling user input). References: OWASP Secure Coding Practices, MDN Web Security Guidelines. For custom adaptations, consult Trailblazer Labs security team.