Skip to content

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Description

The application uses `dangerouslySetInnerHTML` which may lead to Cross Site Scripting (XSS). By default, React components will encode the data properly before rendering. Calling `dangerouslySetInnerHTML` disables this encoding and allows raw markup and JavaScript to be executed.

Examples

Insecure Code

typescript
<div dangerouslySetInnerHTML={{ __html: user_input }} />

Secure Code

typescript
<div>{sanitize(user_input)}</div>

Remediation

Remove the call to `dangerouslySetInnerHTML` or ensure that the data used in this call does not come from user-supplied input.

Rule Details

FieldValue
IDCODE-0198
CategoryInjection
SeverityHIGH
CWECWE-79
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
TagsXSS, Cross-site Scripting
OWASPA7:2017-Cross-Site Scripting (XSS), A03:2021-Injection