Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra DOM Clobbering protection via SANITIZE_NAMED_PROPS config #710

Merged
merged 1 commit into from Aug 17, 2022

Conversation

SoheilKhodayari
Copy link
Contributor

Summary

This PR adds a new opt-in configuration option SANITIZE_NAMED_PROPS that offers full DOM Clobbering protection by complementing the already-existing SANITIZE_DOM config.

When enabled, it isolates the namespace of named properties (i.e., id and name 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:

let script = document.createElement('script');
let config = window.CONF || {href: 'malicious.js'}
script.src = config.href;
document.body.appendChild(script);

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 the src 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

  • Prefix id and name attributes with a constant for namespace isolation.

Dependencies

N/A

@cure53 cure53 merged commit b49ee90 into cure53:main Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants