Skip to main content

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 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bleached-1.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bleached-1.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file bleached-1.0.1.tar.gz.

File metadata

  • Download URL: bleached-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for bleached-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a0946a7fb8b56eb087d93cfbf28f17866a7a1eaad27e176146096fabe507c66a
MD5 1935b08b5272a65806b2f8e0a5fe4e4b
BLAKE2b-256 ce581e1bd07e8670270fe833680e49ec5d408ccdfc4dc217838ed3b36b997c58

See more details on using hashes here.

File details

Details for the file bleached-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: bleached-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for bleached-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e520c0efc94c4682028b03b3df6f2cbf515f3fe517f1ee89c0e6f14b2c870d56
MD5 b0272100019f44fc9d92bf028e1a49de
BLAKE2b-256 441e15b854c82f2e75b580b9cc5ddfa89aa1fb232dcb8fde8021a05779e3586f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page