You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The original Identity Server 4 code base has several medium impact security bugs detected by CodeQL scanning.
Description:
Sanitizing untrusted input for HTML meta-characters is a common technique for preventing cross-site scripting attacks. But even a sanitized input can be dangerous to use if it is modified further before a browser treats it as HTML. A seemingly innocent transformation that expands a self-closing HTML tag from <div attr="{sanitized}"/> to <div attr="{sanitized}"></div> may in fact cause cross-site scripting vulnerabilities.
// Deserialize a standard representationtag=(rtagName.exec(elem)||["",""])[1].toLowerCase();wrap=wrapMap[tag]||wrapMap._default;tmp.innerHTML=wrap[1]+elem.replace(rxhtmlTag,"<$1></$2>")+wrap[2];
This self-closing HTML tag expansion invalidates prior sanitization as this regular expression may match part of an attribute value.
CodeQL
// Descend through wrappers to the right contentj=wrap[0];
Sanitizing untrusted input for HTML meta-characters is a common technique for preventing cross-site scripting attacks. But even a sanitized input can be dangerous to use if it is modified further before a browser treats it as HTML. A seemingly innocent transformation that expands a self-closing HTML tag from <div attr="{sanitized}"/> to <div attr="{sanitized}"></div> may in fact cause cross-site scripting vulnerabilities.
Use a well-tested sanitization library if at all possible, and avoid modifying sanitized values further before treating them as HTML.
An even safer alternative is to design the application so that sanitization is not needed, for instance by using HTML templates that are explicit about the values they treat as HTML.
Example
The following function transforms a self-closing HTML tag to a pair of open/close tags. It does so for all non-img and non-area tags, by using a regular expression with two capture groups. The first capture group corresponds to the name of the tag, and the second capture group to the content of the tag.
While it is generally known regular expressions are ill-suited for parsing HTML, variants of this particular transformation pattern have long been considered safe.
However, the function is not safe. As an example, consider the following string:
Unsafe expansion of self-closing HTML tag
The original Identity Server 4 code base has several medium impact security bugs detected by CodeQL scanning.
Description:
Sanitizing untrusted input for HTML meta-characters is a common technique for preventing cross-site scripting attacks. But even a sanitized input can be dangerous to use if it is modified further before a browser treats it as HTML. A seemingly innocent transformation that expands a self-closing HTML tag from
<div attr="{sanitized}"/>
to<div attr="{sanitized}"></div>
may in fact cause cross-site scripting vulnerabilities.This self-closing HTML tag expansion invalidates prior sanitization as this regular expression may match part of an attribute value.
CodeQL
Sanitizing untrusted input for HTML meta-characters is a common technique for preventing cross-site scripting attacks. But even a sanitized input can be dangerous to use if it is modified further before a browser treats it as HTML. A seemingly innocent transformation that expands a self-closing HTML tag from
<div attr="{sanitized}"/>
to<div attr="{sanitized}"></div>
may in fact cause cross-site scripting vulnerabilities.Examples
Issues
Issues
Recommendation
Use a well-tested sanitization library if at all possible, and avoid modifying sanitized values further before treating them as HTML.
An even safer alternative is to design the application so that sanitization is not needed, for instance by using HTML templates that are explicit about the values they treat as HTML.
Example
The following function transforms a self-closing HTML tag to a pair of open/close tags. It does so for all non-
img
and non-area
tags, by using a regular expression with two capture groups. The first capture group corresponds to the name of the tag, and the second capture group to the content of the tag.While it is generally known regular expressions are ill-suited for parsing HTML, variants of this particular transformation pattern have long been considered safe.
However, the function is not safe. As an example, consider the following string:
When the above function transforms the string, it becomes a string that results in an alert when a browser treats it as HTML.
References
The text was updated successfully, but these errors were encountered: