Angular Unsafe Security Context Bypass
Description
DomSanitizer.bypassSecurityTrust* methods completely disable XSS protection, enabling script injection when used with any user-controllable data.
What Shoulder detects
How to fix
Validate with strict allowlists before using bypassSecurityTrust methods.
```typescript
const ALLOWED_DOMAINS = ['youtube.com', 'vimeo.com'];
embedVideo(urlString: string): SafeResourceUrl | null {
const url = new URL(urlString);
if (url.protocol !== 'https:') return null;
if (!ALLOWED_DOMAINS.some(d => url.hostname.endsWith(d))) return null;
return this.sanitizer.bypassSecurityTrustResourceUrl(urlString);
}
```
Learn more: https://shoulder.dev/learn/typescript/cwe-79/unsafe-pipe
Applies to
Languages
References
Scan for this issue
Detect with Shoulder CLI
npx @shoulderdev/cli trust --rule=angular-unsafe-pipe .
Real-world examples
Known CVEs in the Cross-Site Scripting (XSS) vulnerability class that this rule helps detect.