Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ updates:
- "/owasp-java-html-sanitizer"
- "/examples"
- "/empiricism"
- "/legacy-relocation"
schedule:
interval: "weekly"
open-pull-requests-limit: 0
ignore:
- dependency-name: "com.googlecode.owasp-java-html-sanitizer:*"
- dependency-name: "org.owasp.html-sanitizer:*"
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

- name: Run the Java 8 consumer check on Java 8
run: |
set -- owasp-java-html-sanitizer/target/owasp-java-html-sanitizer-*.jar
set -- owasp-java-html-sanitizer/target/html-sanitizer-*.jar
if [ $# -ne 1 ] || [ ! -f "$1" ]; then
echo "::error::expected one packaged jar, found: $*"
exit 1
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
env:
VERSION: ${{ github.event.inputs.version }}
NEXT_VERSION: 20000101-SNAPSHOT
EXPECTED_GPG_FINGERPRINT: F6109A4F3F5616E1A7A62099E02DB03BAF6C438C

jobs:
release:
Expand Down Expand Up @@ -106,9 +107,12 @@ jobs:
id: build
run: ./mvnw -ntp -B -Ppublication

- name: Check staged release
id: check_staged
run: scripts/check-staged-release.sh target/staging-deploy "$VERSION"

- name: Sign release tag
env:
EXPECTED_GPG_FINGERPRINT: F6109A4F3F5616E1A7A62099E02DB03BAF6C438C
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
Expand All @@ -121,13 +125,13 @@ jobs:
JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
JRELEASER_MAVENCENTRAL_SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
JRELEASER_MASTODON_ACCESS_TOKEN: ${{ secrets.MASTODON_ACCESS_TOKEN }}
JRELEASER_BLUESKY_HOST: ${{ secrets.BLUESKY_HOST }}
JRELEASER_BLUESKY_HANDLE: ${{ secrets.BLUESKY_HANDLE }}
JRELEASER_BLUESKY_PASSWORD: ${{ secrets.BLUESKY_PASSWORD }}
run: ./mvnw -ntp -B -N -Ppublication jreleaser:full-release
run: scripts/with-release-key.sh ./mvnw -ntp -B -N -Ppublication jreleaser:full-release

- name: Release log
if: always()
Expand All @@ -147,9 +151,10 @@ jobs:
git push origin main

- name: Undo the release commit after a build failure
if: failure() && steps.set_version.outputs.bumped == 'true' && steps.build.outcome == 'failure'
if: failure() && steps.set_version.outputs.bumped == 'true' && (steps.build.outcome == 'failure' || steps.check_staged.outcome == 'failure')
run: |
# The build failed before JReleaser ran, so nothing was published.
# The build or the staging check failed before JReleaser ran, so
# nothing was published.
# A failure during or after JReleaser needs manual review because
# the release may already have been published or tagged.
if [ "$(git log -1 --format=%s)" != "Release version $VERSION" ]; then
Expand Down
33 changes: 30 additions & 3 deletions .github/workflows/verify-release-signing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@ name: Verify release signing
# Exercises the release signing path with the repository's release key
# without publishing anything: the tag is created and deleted on the runner,
# and JReleaser deploys in dry-run mode with placeholder Central credentials.
#
# With central_upload, the bundle JReleaser built is also uploaded to Maven
# Central with the real publishing token, validated there, and dropped. That
# is the only way to learn before a release whether the token may deploy
# both the new namespace and the relocation POM's. The upload is never
# published.

on:
workflow_dispatch:
inputs:
central_upload:
description: 'Also have Maven Central validate the placeholder bundle, then drop it (never published)'
type: boolean
default: false

permissions:
contents: read
Expand Down Expand Up @@ -39,6 +50,9 @@ jobs:
- name: Build staged artifacts
run: ./mvnw -ntp -B -Ppublication

- name: Check staged release
run: scripts/check-staged-release.sh target/staging-deploy "$VERSION"

- name: Check signed tag without publishing it
env:
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
Expand All @@ -53,11 +67,24 @@ jobs:
JRELEASER_MAVENCENTRAL_SONATYPE_USERNAME: dry-run-only
JRELEASER_MAVENCENTRAL_SONATYPE_PASSWORD: dry-run-only
JRELEASER_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
JRELEASER_GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
JRELEASER_GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
run: ./mvnw -ntp -B -N -Ppublication -Djreleaser.dry.run=true jreleaser:deploy
GPG_SECRET_KEY: ${{ secrets.GPG_SECRET_KEY }}
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
run: scripts/with-release-key.sh ./mvnw -ntp -B -N -Ppublication -Djreleaser.dry.run=true jreleaser:deploy

- name: Check artifact signatures
env:
GPG_PUBLIC_KEY: ${{ secrets.GPG_PUBLIC_KEY }}
run: scripts/verify-artifact-signatures.sh target/staging-deploy

- name: Have Maven Central validate the bundle, then drop it
if: ${{ inputs.central_upload }}
env:
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
run: |
set -- target/jreleaser/deploy/mavenCentral/sonatype/*-bundle.zip
if [ $# -ne 1 ] || [ ! -f "$1" ]; then
echo "::error::expected one deployment bundle, found: $*"
exit 1
fi
scripts/validate-central-bundle.sh "$1"
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Guidance for AI-assisted work in this repository. This is a security-critical li

## Project

OWASP Java HTML Sanitizer (`com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer`). Takes attacker-controlled HTML and produces HTML that is safe to embed in a web page. Allowlist policies are built with `HtmlPolicyBuilder` and compiled into thread-safe `PolicyFactory` instances.
OWASP Java HTML Sanitizer (`org.owasp.html-sanitizer:html-sanitizer`; releases before issue #531 were `com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer`, where `legacy-relocation/` now publishes a relocation POM with each release). Takes attacker-controlled HTML and produces HTML that is safe to embed in a web page. Allowlist policies are built with `HtmlPolicyBuilder` and compiled into thread-safe `PolicyFactory` instances.

This is a multi-module Maven build:

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OWASP Java HTML Sanitizer

[![Build](https://github.com/OWASP/java-html-sanitizer/actions/workflows/build.yml/badge.svg)](https://github.com/OWASP/java-html-sanitizer/actions/workflows/build.yml) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/2602/badge)](https://www.bestpractices.dev/projects/2602) [![Maven Central](https://img.shields.io/maven-central/v/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer.svg)](https://search.maven.org/artifact/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer)
[![Build](https://github.com/OWASP/java-html-sanitizer/actions/workflows/build.yml/badge.svg)](https://github.com/OWASP/java-html-sanitizer/actions/workflows/build.yml) [![OpenSSF Best Practices](https://www.bestpractices.dev/projects/2602/badge)](https://www.bestpractices.dev/projects/2602) [![Maven Central](https://img.shields.io/maven-central/v/org.owasp.html-sanitizer/html-sanitizer.svg)](https://central.sonatype.com/artifact/org.owasp.html-sanitizer/html-sanitizer)


A fast and easy to configure HTML Sanitizer written in Java which lets
Expand Down Expand Up @@ -60,7 +60,7 @@ with `-pl`, also use `-am` so Maven builds the modules it depends on.
## Prepackaged Policies

You can use
[prepackaged policies](https://www.javadoc.io/doc/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/Sanitizers.html):
[prepackaged policies](https://www.javadoc.io/doc/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/Sanitizers.html):

```Java
PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
Expand All @@ -72,7 +72,7 @@ String safeHTML = policy.sanitize(untrustedHTML);
The
[tests](https://github.com/OWASP/java-html-sanitizer/blob/main/owasp-java-html-sanitizer/src/test/java/org/owasp/html/HtmlPolicyBuilderTest.java)
show how to configure your own
[policy](https://www.javadoc.io/doc/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/HtmlPolicyBuilder.html):
[policy](https://www.javadoc.io/doc/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/HtmlPolicyBuilder.html):

```Java
PolicyFactory policy = new HtmlPolicyBuilder()
Expand All @@ -87,7 +87,7 @@ String safeHTML = policy.sanitize(untrustedHTML);
## Custom Policies

You can write
[custom policies](https://www.javadoc.io/doc/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/ElementPolicy.html)
[custom policies](https://www.javadoc.io/doc/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/ElementPolicy.html)
to do things like changing `h1`s to `div`s with a certain class:

```Java
Expand All @@ -110,7 +110,7 @@ need to be explicitly whitelisted using the `allowWithoutAttributes()`
method if you want them to be allowed through the filter when these
elements do not include any attributes.

[Attribute policies](https://www.javadoc.io/doc/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/AttributePolicy.html) allow running custom code too. Adding an attribute policy will not water down any default policy like `style` or URL attribute checks.
[Attribute policies](https://www.javadoc.io/doc/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/AttributePolicy.html) allow running custom code too. Adding an attribute policy will not water down any default policy like `style` or URL attribute checks.

```Java
PolicyFactory myPolicy = new HtmlPolicyBuilder()
Expand Down Expand Up @@ -179,7 +179,7 @@ of the output.

## Telemetry

When a policy rejects an element or attribute it notifies an [HtmlChangeListener](https://www.javadoc.io/doc/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/HtmlChangeListener.html).
When a policy rejects an element or attribute it notifies an [HtmlChangeListener](https://www.javadoc.io/doc/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/HtmlChangeListener.html).

You can use this to keep track of policy violation trends and find out when someone
is making an effort to breach your security.
Expand Down
15 changes: 15 additions & 0 deletions change_log.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# OWASP Java HTML Sanitizer Change Log

Most recent at top.
* Next release
* Published as `org.owasp.html-sanitizer:html-sanitizer`. The
previous coordinates,
`com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer`,
get a relocation POM with each release that points to the new ones;
releases already published there are unchanged. Java packages, the
JPMS module name and the OSGi bundle symbolic name are unchanged.
Replace the old coordinates with the new ones. If another dependency
still brings in an older release under the old coordinates, the build
resolves both JARs and the older one can be the one that loads: manage
the old coordinates to the new version, or exclude them.
`docs/maven.md` has the steps. See issue #531.
* Release artifacts and tags are signed with the project release key,
fingerprint `F6109A4F3F5616E1A7A62099E02DB03BAF6C438C`, and artifact
signatures use SHA-512 instead of SHA-1.
* Release 20261110.1
* The renderer writes `xmp`, `listing` and `plaintext` as `pre`, and a
browser ends SVG and MathML content at `pre` although not at `xmp` or
Expand Down
16 changes: 8 additions & 8 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

If you are using Maven then follow the [maven](maven.md) directions to
add a dependency. Otherwise,
[download prebuilt jars](https://search.maven.org/artifact/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/)
[download prebuilt jars](https://central.sonatype.com/artifact/org.owasp.html-sanitizer/html-sanitizer)
or `git clone git@github.com:OWASP/java-html-sanitizer.git` and build
the latest source.

Unless maven is managing your CLASSPATH for you, you need to add `owasp-java-html-sanitizer.jar`.
Unless maven is managing your CLASSPATH for you, you need to add `html-sanitizer.jar`.

Once you have your CLASSPATH set up correctly with the relevant JARs
you should be able to add
Expand All @@ -29,18 +29,18 @@ project, not classes in the jar: there is nothing under
`org.owasp.html.examples` to import.

The
[javadoc](https://static.javadoc.io/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/index.html)
[javadoc](https://static.javadoc.io/org.owasp.html-sanitizer/html-sanitizer/latest/index.html)
covers more detailed topics, including
[customization](https://static.javadoc.io/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/HtmlPolicyBuilder.html).
[customization](https://static.javadoc.io/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/HtmlPolicyBuilder.html).

Important classes are:

* [Sanitizers](https://static.javadoc.io/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/Sanitizers.html) contains combinable pre-packaged policies.
* [HtmlPolicyBuilder](https://static.javadoc.io/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/HtmlPolicyBuilder.html) lets you easily build custom policies.
* [Sanitizers](https://static.javadoc.io/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/Sanitizers.html) contains combinable pre-packaged policies.
* [HtmlPolicyBuilder](https://static.javadoc.io/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/HtmlPolicyBuilder.html) lets you easily build custom policies.

For advanced use, see:
* [AttributePolicy](https://static.javadoc.io/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/AttributePolicy.html) and [ElementPolicy](https://static.javadoc.io/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/ElementPolicy.html) allow complex customization.
* [HtmlStreamEventReceiver](https://static.javadoc.io/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer/latest/org/owasp/html/HtmlStreamEventReceiver.html) if you don't just want a `String` as output.
* [AttributePolicy](https://static.javadoc.io/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/AttributePolicy.html) and [ElementPolicy](https://static.javadoc.io/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/ElementPolicy.html) allow complex customization.
* [HtmlStreamEventReceiver](https://static.javadoc.io/org.owasp.html-sanitizer/html-sanitizer/latest/org/owasp/html/HtmlStreamEventReceiver.html) if you don't just want a `String` as output.

## Asking Questions

Expand Down
Loading
Loading