Extra DOM Clobbering protection via SANITIZE_NAMED_PROPS config #710
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new opt-in configuration option
SANITIZE_NAMED_PROPS
that offers full DOM Clobbering protection by complementing the already-existingSANITIZE_DOM
config.When enabled, it isolates the namespace of named properties (i.e.,
id
andname
attributes) and JavaScript variables by prefixing their value with a constant string (i.e.,user-content-
).Background & Context
The current version of DOMPurify offers protection only from selected cases of DOM Clobbering attacks (against web applications). In particular, it does not mitigate cases that clobber JavaScript variables for which no reference exists in the DOM tree.
PoC Example:
In this example, the variable
CONF
can be clobbered if an attacker injects the payload<a id=CONF href=malicious.js>
, whose value is used as thesrc
of a dynamically loaded script, which results in arbitrary client-side code execution.A developer using DOMPurify would attempt to sanitize this markup before adding it to the DOM tree. However, DOMPurify currently does not isolate/remove
id=CONF
since it does not detect any DOM collisions for such a markup.Tasks
id
andname
attributes with a constant for namespace isolation.Dependencies
N/A