diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a386fb02..1b97da62 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -30,3 +30,4 @@ updates: open-pull-requests-limit: 0 ignore: - dependency-name: "com.googlecode.owasp-java-html-sanitizer:*" + - dependency-name: "org.owasp:java-html-sanitizer*" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 03a186ad..ba9ebab7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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/java-html-sanitizer-*.jar if [ $# -ne 1 ] || [ ! -f "$1" ]; then echo "::error::expected one packaged jar, found: $*" exit 1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ec68c0c8..defd9cd7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,6 +11,7 @@ on: env: VERSION: ${{ github.event.inputs.version }} NEXT_VERSION: 20000101-SNAPSHOT + EXPECTED_GPG_FINGERPRINT: F6109A4F3F5616E1A7A62099E02DB03BAF6C438C jobs: release: @@ -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 }} @@ -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() @@ -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 diff --git a/.github/workflows/verify-release-signing.yml b/.github/workflows/verify-release-signing.yml index 80dad52b..a8201fcf 100644 --- a/.github/workflows/verify-release-signing.yml +++ b/.github/workflows/verify-release-signing.yml @@ -39,6 +39,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 }} @@ -53,9 +56,9 @@ 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: diff --git a/AGENTS.md b/AGENTS.md index c835e887..a5733975 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -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:java-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: diff --git a/change_log.md b/change_log.md index 10808dc4..e942ba39 100644 --- a/change_log.md +++ b/change_log.md @@ -1,6 +1,18 @@ # OWASP Java HTML Sanitizer Change Log Most recent at top. + * Next release + * Published as `org.owasp:java-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: a dependency that still + names an older release under the old coordinates puts a second copy of + the library on the class path. 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 20261107.1 * Percent-encode NUL, DEL, C1 controls, noncharacters and lone surrogates in event-stream, preprocessor- or policy-supplied URL attribute values, diff --git a/empiricism/pom.xml b/empiricism/pom.xml index 91d391d4..493a2928 100644 --- a/empiricism/pom.xml +++ b/empiricism/pom.xml @@ -1,11 +1,11 @@ 4.0.0 - empiricism + java-html-sanitizer-empiricism 20000101-SNAPSHOT jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp + java-html-sanitizer-parent 20000101-SNAPSHOT @@ -22,13 +22,13 @@ - com.googlecode.owasp-java-html-sanitizer - owasp-java-html-sanitizer + org.owasp + java-html-sanitizer ${project.version} - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp + java-html-sanitizer-java8-shim ${project.version} diff --git a/examples/pom.xml b/examples/pom.xml index 7cd6e009..6efcb0cc 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - examples + java-html-sanitizer-examples jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp + java-html-sanitizer-parent 20000101-SNAPSHOT @@ -29,8 +29,8 @@ - com.googlecode.owasp-java-html-sanitizer - owasp-java-html-sanitizer + org.owasp + java-html-sanitizer ${project.version} - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp + java-html-sanitizer-java8-shim ${project.version} runtime - com.googlecode.owasp-java-html-sanitizer - java10-shim + org.owasp + java-html-sanitizer-java10-shim ${project.version} runtime diff --git a/java10-shim/pom.xml b/java10-shim/pom.xml index ed8e07dc..732efd23 100644 --- a/java10-shim/pom.xml +++ b/java10-shim/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - java10-shim + java-html-sanitizer-java10-shim jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp + java-html-sanitizer-parent 20000101-SNAPSHOT @@ -59,8 +59,8 @@ - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp + java-html-sanitizer-java8-shim diff --git a/java8-shim/pom.xml b/java8-shim/pom.xml index 085ef17b..413f5a75 100644 --- a/java8-shim/pom.xml +++ b/java8-shim/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - java8-shim + java-html-sanitizer-java8-shim jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp + java-html-sanitizer-parent 20000101-SNAPSHOT diff --git a/legacy-relocation/pom.xml b/legacy-relocation/pom.xml new file mode 100644 index 00000000..0fbf4b5a --- /dev/null +++ b/legacy-relocation/pom.xml @@ -0,0 +1,34 @@ + + + + + 4.0.0 + + org.owasp + java-html-sanitizer-parent + 20000101-SNAPSHOT + + + com.googlecode.owasp-java-html-sanitizer + owasp-java-html-sanitizer + pom + + OWASP Java HTML Sanitizer (relocated) + + Relocation to org.owasp:java-html-sanitizer. Releases from this version + on are published only under the new coordinates. + + https://github.com/OWASP/java-html-sanitizer + + + + org.owasp + java-html-sanitizer + The OWASP Java HTML Sanitizer is now published as org.owasp:java-html-sanitizer. See https://github.com/OWASP/java-html-sanitizer/blob/main/docs/maven.md + + + diff --git a/owasp-java-html-sanitizer/README.md b/owasp-java-html-sanitizer/README.md index f05f9ef3..19cb3d8e 100644 --- a/owasp-java-html-sanitizer/README.md +++ b/owasp-java-html-sanitizer/README.md @@ -2,8 +2,11 @@ # Core Library Module -This module builds the published -`com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer` artifact. +This module builds the published `org.owasp:java-html-sanitizer` artifact. +Releases before issue #531 were published as +`com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer`, where +the [relocation module](../legacy-relocation/pom.xml) now publishes a POM with +each release that points to the new coordinates. It combines HTML parsing, tag balancing, allowlist policy enforcement, and rendering to produce sanitized HTML. See the [getting-started guide](../docs/getting_started.md) for using the public API. diff --git a/owasp-java-html-sanitizer/pom.xml b/owasp-java-html-sanitizer/pom.xml index 706b7179..09ff14a9 100644 --- a/owasp-java-html-sanitizer/pom.xml +++ b/owasp-java-html-sanitizer/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - owasp-java-html-sanitizer + java-html-sanitizer bundle - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp + java-html-sanitizer-parent 20000101-SNAPSHOT @@ -119,6 +119,12 @@ maven-bundle-plugin + + com.googlecode.owasp-java-html-sanitizer org.owasp.html - com.googlecode.owasp-java-html-sanitizer:java8-shim - com.googlecode.owasp-java-html-sanitizer:java10-shim + org.owasp:java-html-sanitizer-java8-shim + org.owasp:java-html-sanitizer-java10-shim @@ -199,8 +205,13 @@ *:* - META-INF/maven/com.googlecode.owasp-java-html-sanitizer/java*/** + pom.properties / pom.xml entries in the JAR. Name + the shim directories in full: a looser pattern such + as java*/** also matches java-html-sanitizer/ and + strips this artifact's own metadata, which + dependency scanners use to identify the JAR. --> + META-INF/maven/org.owasp/java-html-sanitizer-java8-shim/** + META-INF/maven/org.owasp/java-html-sanitizer-java10-shim/** - com.googlecode.owasp-java-html-sanitizer:java10-shim + org.owasp:java-html-sanitizer-java10-shim META-INF/versions/** @@ -338,13 +349,13 @@ - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp + java-html-sanitizer-java8-shim true - com.googlecode.owasp-java-html-sanitizer - java10-shim + org.owasp + java-html-sanitizer-java10-shim true diff --git a/owasp-java-html-sanitizer/src/test/resources/packaging-verification.xml b/owasp-java-html-sanitizer/src/test/resources/packaging-verification.xml index 6eb4be9a..7ced33ad 100644 --- a/owasp-java-html-sanitizer/src/test/resources/packaging-verification.xml +++ b/owasp-java-html-sanitizer/src/test/resources/packaging-verification.xml @@ -6,6 +6,12 @@ target/classes/META-INF/MANIFEST.MF Export-Package: org.owasp.html + + + target/classes/META-INF/MANIFEST.MF + Bundle-SymbolicName: com.googlecode.owasp-java-html-sanitizer + ALWAYS true + COMMAND + + + --digest-algo + SHA512 + + diff --git a/scripts/check-staged-release.sh b/scripts/check-staged-release.sh new file mode 100755 index 00000000..536e9603 --- /dev/null +++ b/scripts/check-staged-release.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause + +# Checks that a release staging repository holds exactly the components a +# release publishes: the library and its parent under org.owasp, and a +# relocation POM at the coordinates used before issue #531. + +set -euo pipefail + +repository=${1:?staging repository required} +version=${2:?release version required} +if [[ ! $version =~ ^[0-9]{8}\.[0-9]+$ ]]; then + echo 'Invalid release version' >&2 + exit 1 +fi + +library=org/owasp/java-html-sanitizer/$version/java-html-sanitizer-$version +parent=org/owasp/java-html-sanitizer-parent/$version/java-html-sanitizer-parent-$version +legacy=com/googlecode/owasp-java-html-sanitizer/owasp-java-html-sanitizer/$version/owasp-java-html-sanitizer-$version +expected=$(printf '%s\n' "$library.jar" "$library.pom" "$library-javadoc.jar" \ + "$library-sources.jar" "$parent.pom" "$legacy.pom" | sort) +actual=$(cd "$repository" && find . -type f ! -name '*.md5' ! -name '*.sha1' \ + ! -name '*.sha256' ! -name '*.sha512' ! -name '*.asc' ! -name 'maven-metadata*' | + sed 's#^\./##' | sort) +if [[ $actual != "$expected" ]]; then + echo 'Staged artifacts differ from the expected release components:' >&2 + diff <(echo "$expected") <(echo "$actual") >&2 || true + exit 1 +fi + +relocation=$(tr -d ' \n\r\t' < "$repository/$legacy.pom") +for element in 'org.owaspjava-html-sanitizer' \ + 'pom'; do + if [[ $relocation != *"$element"* ]]; then + echo "Relocation POM lacks $element" >&2 + exit 1 + fi +done +if [[ $relocation == *''* || $relocation == *''* ]]; then + echo 'Relocation POM must have no dependencies and no pinned target version' >&2 + exit 1 +fi + +entries=$(unzip -Z1 "$repository/$library.jar") +if ! grep -qx 'META-INF/maven/org.owasp/java-html-sanitizer/pom.properties' <<<"$entries"; then + echo 'Library JAR lacks its own Maven metadata' >&2 + exit 1 +fi +if grep -q '^META-INF/maven/.*shim' <<<"$entries"; then + echo 'Library JAR carries shim Maven metadata' >&2 + exit 1 +fi +if ! unzip -p "$repository/$library.jar" META-INF/MANIFEST.MF | + grep -q '^Bundle-SymbolicName: com\.googlecode\.owasp-java-html-sanitizer'; then + echo 'Library JAR has an unexpected OSGi symbolic name' >&2 + exit 1 +fi +echo "Staged release $version has the expected components" diff --git a/scripts/verify-artifact-signatures.sh b/scripts/verify-artifact-signatures.sh index e783d2b1..5bc6899f 100755 --- a/scripts/verify-artifact-signatures.sh +++ b/scripts/verify-artifact-signatures.sh @@ -40,10 +40,13 @@ while IFS= read -r -d '' artifact; do echo "Missing signature for ${artifact#"$repository"/}" >&2 exit 1 fi - signer=$(gpg --batch --status-fd 1 --verify "$artifact.asc" "$artifact" 2>/dev/null | - awk '$1 == "[GNUPG:]" && $2 == "VALIDSIG" { print $NF; exit }') || true - if [[ $signer != "$EXPECTED_GPG_FINGERPRINT" ]]; then - echo "Bad or unexpected signature on ${artifact#"$repository"/}" >&2 + status=$(gpg --batch --status-fd 1 --verify "$artifact.asc" "$artifact" 2>/dev/null) || true + # VALIDSIG ends with the primary key fingerprint; its eighth field is the + # hash algorithm, which must be SHA-256 (8), SHA-384 (9) or SHA-512 (10). + read -r signer digest < <(awk '$1 == "[GNUPG:]" && $2 == "VALIDSIG" { print $NF, $10; exit }' <<<"$status") || true + if [[ ${signer:-} != "$EXPECTED_GPG_FINGERPRINT" || ! ${digest:-} =~ ^(8|9|10)$ ]]; then + echo "Bad, weak or unexpected signature on ${artifact#"$repository"/}:" >&2 + grep '^\[GNUPG:\] \(VALIDSIG\|BADSIG\|ERRSIG\|FAILURE\|NO_PUBKEY\|ERROR\)' <<<"$status" >&2 || true exit 1 fi echo "Verified ${artifact#"$repository"/}" diff --git a/scripts/with-release-key.sh b/scripts/with-release-key.sh new file mode 100755 index 00000000..ea7c0133 --- /dev/null +++ b/scripts/with-release-key.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause + +# Runs a command, normally JReleaser, with the release key alone in a +# temporary GnuPG home, and points JReleaser's gpg command signer at it. + +set -euo pipefail + +if (($# == 0)); then + echo 'Command required' >&2 + exit 1 +fi +: "${GPG_SECRET_KEY:?GPG_SECRET_KEY required}" +: "${GPG_PUBLIC_KEY:?GPG_PUBLIC_KEY required}" +: "${EXPECTED_GPG_FINGERPRINT:?EXPECTED_GPG_FINGERPRINT required}" +if [[ ! $EXPECTED_GPG_FINGERPRINT =~ ^[0-9A-F]{40}$ ]]; then + echo 'Invalid expected release signing fingerprint' >&2 + exit 1 +fi + +signing_home=$(mktemp -d) +trap 'gpgconf --kill gpg-agent >/dev/null 2>&1 || true; rm -rf "$signing_home"' EXIT +chmod 700 "$signing_home" +export GNUPGHOME=$signing_home +public_fingerprint=$(printf '%s\n' "$GPG_PUBLIC_KEY" | + gpg --batch --show-keys --with-colons | + awk -F: '$1 == "fpr" { print $10; exit }') +if [[ $public_fingerprint != "$EXPECTED_GPG_FINGERPRINT" ]]; then + echo 'Release public key fingerprint does not match the configured key' >&2 + exit 1 +fi +printf '%s\n' "$GPG_PUBLIC_KEY" | gpg --batch --quiet --import +printf '%s\n' "$GPG_SECRET_KEY" | gpg --batch --quiet --import + +fingerprint=$(gpg --batch --with-colons --list-secret-keys | + awk -F: '$1 == "sec" { primary = 1; next } $1 == "fpr" && primary { print $10; primary = 0 }') +if [[ $fingerprint != "$EXPECTED_GPG_FINGERPRINT" ]]; then + echo 'Expected exactly one release signing key, the configured one' >&2 + exit 1 +fi + +export JRELEASER_GPG_HOMEDIR=$signing_home +export JRELEASER_GPG_KEYNAME=$fingerprint +"$@"