Bezpieczeństwo

security/raw-html-sink

Never pass user or remote data to a raw HTML sink (innerHTML, dangerouslySetInnerHTML, v-html, {@html}) without sanitizing it.

poważnastatycznefe-security

W projekcie raport i explain zastępują przykład w nawiasach klamrowych własnym narzędziem projektu.

Dlaczego

Frameworks escape text for you; these escape hatches switch that off. A comment, a profile field or a CMS value that contains <img src=x onerror=…> then runs script in your users' sessions: it can read data on the page, act as the user and steal tokens that script can reach.

Poprawka

Render data as text ({value}, {{ value }}, textContent). When the content must be HTML (CMS rich text, Markdown output), sanitize it on the way in with DOMPurify (DOMPurify.sanitize(html)) and do not modify it afterwards; better, sanitize on the server too. In Angular keep [innerHTML] (it sanitizes) and treat every bypassSecurityTrust* call as a security review item.

Przykłady

// bad
<div dangerouslySetInnerHTML={{ __html: comment.body }} />
// good
<p>{comment.body}</p>
<div dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(article.html) }} />

Źródła

Fakty

Identyfikator
security/raw-html-sink
Waga
poważna
Sprawdzanie
statyczne sprawdzane w kodzie źródłowym przez audit
Dotyczy plików
html jsx vue svelte astro
Uczy jej skill
fe-security Front-end security
Od wersji
0.1.0

Plik reguły na GitHubie

Przeczytaj w terminalu

npx github:dawidolko/frontend-skills explain security/raw-html-sink