Comprehensive security guidance for building secure Aurelia 2 applications.
Critical Security Principle
The client cannot be trusted. All security enforcement must happen on the backend. Your Aurelia application's security measures are for user experience and first-line defense only. Always validate, authenticate, and authorize on the server.
What you'll learn...
How Aurelia protects against XSS attacks in templates
Authentication and authorization patterns using the router
Cross-Site Scripting (XSS) is one of the most common web vulnerabilities. Aurelia provides built-in protections, but you must understand when they apply.
Text Interpolation (Safe by Default)
Text interpolation using ${} is automatically escaped and safe from XSS:
How it works: Aurelia sets the textContent property, not innerHTML, so the browser automatically escapes HTML entities.
Attribute Binding (Safe by Default)
Attribute bindings are also safe when using standard binding commands:
URL Injection Risk
While attribute binding escapes HTML, malicious URLs can still be dangerous:
Create custom validators for security-sensitive inputs:
Server-Side Validation (Critical)
Client-side validation is for UX only. Always re-validate on the server:
Never Trust Client Input
An attacker can bypass client-side validation using browser dev tools or by crafting HTTP requests directly. Always validate and sanitize on the server.
Secure Communication
HTTPS Only
Always use HTTPS in production. HTTP transmits data in plaintext, exposing:
Security is an ongoing process, not a one-time task. Subscribe to security advisories for your backend framework and dependencies. Regularly review and update your security measures.
<!-- SAFE: Text interpolation auto-escapes HTML -->
<div>${userInput}</div>
<p>Welcome, ${username}!</p>
<!-- Even if userInput contains: <script>alert('xss')</script>
It will be rendered as text, not executed -->
<!-- DANGEROUS: User input rendered as HTML -->
<div innerHTML.bind="userContent"></div>
<!-- If userContent contains: <img src=x onerror="alert('xss')">
It will execute the malicious script -->
<!-- SAFE: Content is sanitized before rendering -->
<div innerHTML.bind="userContent | sanitize"></div>