
Security Fundamentals
Turtles, Clams, and Cyber Threat Actors: Shell Usage
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
This package contains several handy python methods to cleanup HTML markup
or perform other common changes. The cleanup is strict enough to be able
to clean HTML pasted from MS Word or Apple Pages. This package also contains
integration code for z3c.form
_ to provide fields that automatically
sanitize HTML on save.
The implementation is based on the Cleaner
class from lxml
_.
All cleanup routines can be invoked through the single sanitize
function.
This functions takes an input string as input and will return a cleaned up
version of that string. Here is a simple example::
from htmllaundry import sanitize sanitize('Hello, world') '
Hello, world
'
The sanitize method takes an extra optional parameter with a lxml Cleaner instance, which can be used to use different filtering rules. htmllaundry includes three cleaners:
htmllaundry.cleaners.DocumentCleaner
, which is the default cleaner. This
cleaner will allow most safe tags, while stripping out inline styles and
insecure markup.
htmllaundry.cleaners.LineCleaner
is a more strict cleaner which only
allows a few inline elements. This is useful in places where you only
want to accept single-line input, for example in document titles.
htmllaundry.cleaners.CommentCleaner
only allows a very limited set of
HTML elements, and is designed to be useful for user provided comments. It
will also force all external links to open in a new browser window.
If you want to go all the way you can also use strip_markup
to strip
all markup from your input::
from htmllaundry import strip_markup strip_markup('Hello, world') 'Hello, world'
If you want to use the z3c.form
integration you should use the z3cform
extra for this package::
install_requires=[ .... htmllaundry [z3cform] ... ],
In addition you will need to load the ZCML. In your configure.zcml
add
a line like this::
You can then use the HtmlText
field type in your schemas. For example::
from zope.interface import Interface from zope import schema from htmllaundry.z3cform import HtmlText
class IDocument(Interface): title = schema.TextLine( title = _(u"Title"), required = True)
description = HtmlText(
title = _(u"Description"),
required = True)
Please note that using HtmlText
will not automatically give you a WYSYWIG
widget.
.. _z3c.form: http://pypi.python.org/pypi/z3c.form .. _lxml: http://lxml.de/
<a>
tags that could be used as anchors.When wrapping unwrapped text do not create separate wrappers for inline elements.
Use PEP8 naming for all functions. The old names for public methods will continue to work for backwards compatibility.
Add support for Python 3.
sanitize
to specify a different wrap element or
skip wrapping completely.Add MANIFEST.in to faciliate releases not made from subversion.
Fix all cleaners to strip javascript. This fixes issue 1 <https://github.com/wichert/htmllaundry/issues/1>
_.
sanitize
.
This makes it possible to use the new link_target
cleaner option.link_target
option in the cleaners. Only enable this option for
the CommentCleaner
.Small code cleanup.
Strip leading breaks.
Fix a typo in the documentation.
Strip trailing breaks.
Add a simple StripMarkup method.
Add ZCML necessary for z3c.form integration.
FAQs
Simple HTML cleanup utilities
We found that htmllaundry demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers 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 Fundamentals
The Socket Threat Research Team uncovers how threat actors weaponize shell techniques across npm, PyPI, and Go ecosystems to maintain persistence and exfiltrate data.
Security News
At VulnCon 2025, NIST scrapped its NVD consortium plans, admitted it can't keep up with CVEs, and outlined automation efforts amid a mounting backlog.
Product
We redesigned our GitHub PR comments to deliver clear, actionable security insights without adding noise to your workflow.