Angular
angular/no-bypass-security-trust
DomSanitizer bypassSecurityTrust* calls never receive user or server data; each one is a reviewed exception.
poważnaręcznefe-angular
Dlaczego
Angular sanitizes every value bound into [innerHTML], [href], [src] and [style]. bypassSecurityTrustHtml, …Url, …ResourceUrl, …Script and …Style switch that off for one value: if any part of it comes from a user, a URL or an API, it is cross-site scripting.
Poprawka
Bind the value without bypassing ([innerHTML]="html" is sanitized and keeps safe markup). Bypass only constants you wrote (an embed URL built from a fixed origin and a validated id), keep the call in one small function with a comment that says why it is safe, and never pass ElementRef.nativeElement.innerHTML raw strings either. Manual because the engine does not read .ts files: search for bypassSecurityTrust and review each call.
Przykłady
// bad
this.body = this.sanitizer.bypassSecurityTrustHtml(comment.html)
// good
body = computed(() => this.comment().html) // bound with [innerHTML], which sanitizesŹródła
Fakty
- Identyfikator
angular/no-bypass-security-trust- Waga
- poważna
- Sprawdzanie
- ręczne ocenia człowiek; raport podaje to jako listę kontrolną
- Dotyczy plików
angular- Tylko w projektach z
angular- Uczy jej skill
fe-angularAngular components- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain angular/no-bypass-security-trust