How to fix: Angular bypassSecurityTrust* Usage
An Angular bypassSecurityTrust* function was found in the page. These functions explicitly opt out of Angular's built-in XSS protection and must only be used with fully sanitized, trusted content.
Why it matters
bypassSecurityTrust* tells Angular 'trust this value completely, do not sanitize it'. If user-controlled data reaches these functions, it results in XSS. Misuse is extremely common in AI-generated and tutorial Angular code.
Angular sanitizes all dynamic HTML, URLs, and styles by default. bypassSecurityTrust* is an escape hatch for embedding trusted HTML (like a CMS-provided rich-text body). It must never be used with user-generated or attacker-influenced content.
How to fix it
- 1Audit every bypassSecurityTrust* call to verify the data is truly from a trusted, sanitized source.
- 2For user-generated rich text: sanitize with DOMPurify first, then bypassSecurityTrustHtml.
- 3Prefer Angular pipes and built-in sanitization over bypassing it.
- 4Remove any bypassSecurityTrust* calls where the data source is user input.
Code examples
Safe usage with DOMPurify
import DOMPurify from 'dompurify';
@Component({
template: `<div [innerHTML]="trustedHtml"></div>`
})
export class RichTextComponent {
constructor(private sanitizer: DomSanitizer) {}
get trustedHtml(): SafeHtml {
// Only bypass AFTER sanitizing with DOMPurify
const clean = DOMPurify.sanitize(this.userContent);
return this.sanitizer.bypassSecurityTrustHtml(clean);
}
}References
Detected automatically by VulnRadar. The check id is angular-bypass-security, stable across every scan so you can filter or diff on it.
More client-side checks
- HighCSP Allows 'unsafe-inline' Scripts
- MediumCSP Allows 'unsafe-eval'
- HighpostMessage Without Origin Validation
- HighSensitive Data Stored in localStorage
- HighDOM XSS via location.hash Assignment
- Highdocument.write() in Page Scripts
- Higheval() in Client-Side JavaScript
- MediumExternal Script Without Subresource Integrity
Questions
- How severe is Angular bypassSecurityTrust* Usage?
- VulnRadar rates this high severity in the client-side category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id angular-bypass-security, which stays the same between runs so you can filter, diff, or gate CI on it.
- Which standards does Angular bypassSecurityTrust* Usage map to?
- It maps to CWE-79. In the OWASP Top 10 it falls under A03:2021.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.