
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
draftjs-sanitizer
Advanced tools
Sanitizes a DraftJS JSON format from a dict to allow saving. Allows safe dumping into a string in order to prevent injection of quotes and HTML entities.
pip install draftjs-sanitizer
This removes any URLs that could be used for XSS attacks by linking raw javascript code.
from draftjs_sanitizer import clean_draft_js
clean_draft_js({
"blocks": [
{
"key": "an6ci",
"data": {},
"text": "Get Saleor today!",
"type": "unstyled",
"depth": 0,
"entityRanges": [
{
"key": 0,
"length": 17,
"offset": 0
}
],
"inlineStyleRanges": []
}
],
"entityMap": {
"0": {
"data": {
"url": "javascript:alert('Oopsie!');"
},
"type": "LINK",
"mutability": "MUTABLE"
}
}
})
This allows to run it as a filter in order to prevent any injection or bypass when putting the JSON into HTML code.
from draftjs_sanitizer import to_string
dumped_json = to_string({"block": "</div><script>alert('Oopsie!');</script>"})
<div data-draft-js-json='{"block": "'<script>alert('Oopsie!');</script>"}'></div>
<div>
{"block": "</div><script>alert('Oopsie!');</script>"}
</div>
| Type | Entities | Description |
|---|---|---|
| Javascript URL | IMAGE, LINK | Prevent injecting javascript through the javascript protocol into a URL. |
| Invalid URL | IMAGE, LINK | Removes any invalid URL from the JSON content. |
| Dangerous Characters | any | Removes any sensible character for HTML incorporation: ", ', <, >. |
./setup.py develop
pip install -r requirements_dev.txt
You can easily extend the behaviors through:
draftjs_sanitizer.encoder.DraftJSSafeEncoderdraftjs_sanitizer.sanitizer.DraftJSSanitizerurllib3 for RFC 3986 parsing and validation of URLs.FAQs
Convert basic HTML into DraftJS JSON format.
We found that draftjs-sanitizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.