Validate HTML against a small subset (for example generated by bleach)
Project description
bleached
This is a small HTML checker. It can validate that HTML code is safe.
It does not aim to support the entire HTML spec, rather it focuses on checking HTML that has been run through a sanitizer (such as bleach).
How to use?
$ pip install bleached
$ python3
>>> import bleached
>>> bleached.is_html_bleached('<p>Hello world</p>')
True
>>> bleached.is_html_bleached('<script>alert("Hello world");</script>')
False
>>> bleached.check_html('<p>Hello world</p>')
>>> bleached.check_html('<script>alert("Hello world");</script>')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
bleached.UnsafeInput: Line 1 character 8 (input index 7): Found forbidden opening tag 'script'
Why use this?
bleach is a great library for sanitizing untrusted HTML. You should use it instead of this where possible.
However, it offers no way to check that a piece of HTML has been sanitized. Running the HTML through bleach again will only work if you have the exact same version, as bleach makes no guarantee of stability of their input. This is where bleached is useful.
Warnings
- No validation of attributes is performed. If you choose to allow an attribute, it is up to you to validate the values.
- This accepts a much smaller subset of HTML than web browsers. Be ready for false negatives if you use this to validate HTML documents.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bleached-1.0.0.tar.gz
.
File metadata
- Download URL: bleached-1.0.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2db92a18bdfb8df4b3d0e47ffb3e8a48dd5dc35b0a1b99e88f331da36fd0c6c0 |
|
MD5 | a900dbe92f7ef82573fcb253ef1461b1 |
|
BLAKE2b-256 | 0660c854a64b36bec0f3262b2f346c469dc51ace1fbaddee1936a669036e5682 |
File details
Details for the file bleached-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: bleached-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84c0e737e59ded62f852cccb09b35303a9a6bb29214acb4d893f395c5d963301 |
|
MD5 | e596911de2d14cfa6e4dee1e893fe209 |
|
BLAKE2b-256 | 11cfa0725af201c75d9828e35c0bb4d4d7b60f857964ea142aaeaf5485647ad3 |