Security and Privacy
Security and Privacy Patterns
Frontends handle sensitive data, tokens, and business logic. These patterns layer defensive controls that keep attackers out while preserving trusted user experiences.
Frontends handle sensitive data, tokens, and business logic. These patterns layer defensive controls that keep attackers out while preserving trusted user experiences.
Framework-level thinking before you pick a pattern.
Specific, reusable techniques you can drop into production.
Define allowed sources for scripts, styles, and resources through HTTP headers to prevent XSS and injection attacks.
Implement anti-CSRF tokens or SameSite cookies to prevent cross-site request forgery attacks.
Clean and validate user-provided data before rendering or processing to prevent injection attacks.
Escape data properly when rendering to prevent XSS by ensuring user input is treated as data, not executable code.
Remove or mask personally identifiable information systematically from logs, analytics, and error reports.
Configure cookie SameSite attributes to control cross-site cookie behavior and prevent CSRF attacks.
Store authentication tokens safely using httpOnly cookies, secure flags, or encrypted storage to prevent token theft.
Use integrity hashes on external scripts and stylesheets to ensure resources haven't been tampered with.
Use browser APIs to enforce type checking on dangerous sinks like innerHTML to eliminate DOM-based XSS vulnerabilities.
Join thousands of developers receiving weekly insights on frontend architecture patterns