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 nh3 or the older 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?
nh3 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 nh3 again will only work if you have the exact same version, as nh3 makes no guarantee of stability of their input. This is where bleached is useful.
Warnings
- No validation of attribute valuess 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.
Metadata
Release files for bleached 1.0.1
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 | Actions |
|---|---|---|---|---|
| bleached-1.0.1.tar.gz | 4.5 kB | Without provenance | Details for bleached-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bleached-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for bleached-1.0.1-py3-none-any.whl |
Total release size: 9.7 kB
Release files / bleached-1.0.1.tar.gz
| Download URL | bleached-1.0.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a0946a7fb8b56eb087d93cfbf28f17866a7a1eaad27e176146096fabe507c66a
|
|
BLAKE2b-256 checksum How to use checksums |
ce581e1bd07e8670270fe833680e49ec5d408ccdfc4dc217838ed3b36b997c58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Release files / bleached-1.0.1-py3-none-any.whl
| Download URL | bleached-1.0.1-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e520c0efc94c4682028b03b3df6f2cbf515f3fe517f1ee89c0e6f14b2c870d56
|
|
BLAKE2b-256 checksum How to use checksums |
441e15b854c82f2e75b580b9cc5ddfa89aa1fb232dcb8fde8021a05779e3586f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.12
|
Security for bleached 1.0.1
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.