DraftJS Sanitizer
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.
Installation
pip install draftjs-sanitizer
Usage
Remove known exploits
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"
}
}
})
Dump JSON for HTML Usage
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>"})
Example 1: attribute bypass
<div data-draft-js-json='{"block": "'<script>alert('Oopsie!');</script>"}'></div>
Example 2: bypass inner HTML
<div>
{"block": "</div><script>alert('Oopsie!');</script>"}
</div>
Supported Checks
| 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: ", ', <, >. |
Development
./setup.py develop
pip install -r requirements_dev.txt
You can easily extend the behaviors through:
draftjs_sanitizer.encoder.DraftJSSafeEncoderdraftjs_sanitizer.sanitizer.DraftJSSanitizer
Dependencies
urllib3for RFC 3986 parsing and validation of URLs.
Metadata
Release files for draftjs-sanitizer 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| draftjs-sanitizer-1.0.0.tar.gz | 6.1 kB | Without provenance | Details |
Release files / draftjs-sanitizer-1.0.0.tar.gz
| Download URL | draftjs-sanitizer-1.0.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4603a9296153cd06d5a1d76a45a1ff0295363516af983d8dde28cafc5cd67583
|
|
BLAKE2b-256 checksum How to use checksums |
586cba91295b18cf371cab6e7f93f2117eea802ab8e1e491f78ab1361575d07a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2
|
Security for draftjs-sanitizer 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.