DeXSS -- Java program for removing JavaScript from HTML

A common approach taken to mitigate this risk is to allow
some HTML content, but block content that is potentially
harmful. One problem with a straightforward approach to blocking such
content is that HTML parsing in browsers differs from the ideal,
and nefarious individuals can take advantage of these differences
to obscure content.

DeXSS uses TagSoup, an
open-source HTML parser that attempts to mimic how web browsers
work. TagSoup reads wild HTML and generates SAX2 events. DeXSS invokes
TagSoup and follows it with a pipeline of SAX2 filters to remove HTML
tags such as script and attribute values containing such
scripts.

Status

DeXSS 1.2 is an Alpha release. You should be aware of the following issues:

This release implements a blacklist approach, which has advantages over a whitelist approach, but also has inherent risks. There are still a number of known XSS attacks that DeXSS does not yet detect.

DeXSS is agressive about removing style attributes that fail the CSS analyzer. There are probably other CSS attacks that DeXSS does not protect against.

Elements that TagSoup thinks should be in the head are discarded by the default settings; changing the BODY_ONLY flag to allow head content will reduce effectiveness greatly. Consequently, DeXSS should not be used to parse entire user-provided HTML files, but only parts that are destined for inclusion.

The output of DeXSS is intended for browsers, not for storage. As a result, some constructs may be overly verbose.

Configurability and test suites are lacking.

DeXSS does not specially handle any HTML5 elements or attributes not present in HTML4.

If you have an interest in working on these issues, please consider contributing to the project.