diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a386fb02..c5461d10 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -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:*" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 03a186ad..b01abab6 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/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..9211e0b8 100644 --- a/.github/workflows/verify-release-signing.yml +++ b/.github/workflows/verify-release-signing.yml @@ -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 @@ -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 }} @@ -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" diff --git a/AGENTS.md b/AGENTS.md index db10c11b..e48018b0 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.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: diff --git a/README.md b/README.md index 5b2e28e4..5b33f575 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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); @@ -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() @@ -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 @@ -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() @@ -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. diff --git a/change_log.md b/change_log.md index 62be53a7..5d07786e 100644 --- a/change_log.md +++ b/change_log.md @@ -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 diff --git a/docs/getting_started.md b/docs/getting_started.md index a69cb9b9..6b8a029b 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -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 @@ -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 diff --git a/docs/maven.md b/docs/maven.md index f4c4b887..df9716f9 100644 --- a/docs/maven.md +++ b/docs/maven.md @@ -1,20 +1,25 @@ # Using with Maven The HTML Sanitizer is available from -[Maven Central](https://search.maven.org/#browse%7C84770979) +[Maven Central](https://central.sonatype.com/artifact/org.owasp.html-sanitizer/html-sanitizer) Including among your POMs `` this snippet of XML... ```Java - com.googlecode.owasp-java-html-sanitizer - owasp-java-html-sanitizer + org.owasp.html-sanitizer + html-sanitizer 20261110.1 ``` ...will make the sanitizer available. +Releases up to 20261110.1 were published as +`com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer`. If +your build names those coordinates, see +[Migrating from the old coordinates](#migrating-from-the-old-coordinates). + The sanitizer JAR is self-contained: the `java8-shim` and `java10-shim` artifacts are bundled inside it and do **not** need to be declared as separate dependencies, including when using the JPMS module path. @@ -44,9 +49,98 @@ Bigger numbers are more recent and the [change log](../change_log.md) can shed light on the salient differences. You should be able to build with the HTML sanitizer. You can read 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), and if you have questions that aren't answered by these pages, you can ask in [GitHub Discussions](https://github.com/OWASP/java-html-sanitizer/discussions/categories/q-a). Happy sanitizing... + +## Migrating from the old coordinates + +Releases up to 20261110.1 were published as +`com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer`. Later +releases are published as `org.owasp.html-sanitizer:html-sanitizer`. Only +the coordinates changed: the Java package is still `org.owasp.html`, the JPMS +module is still `owasp.java.html.sanitizer`, the OSGi bundle symbolic name is +still `com.googlecode.owasp-java-html-sanitizer`, version numbers continue +the same sequence, and the JAR still runs on Java 8. + +Replace the old coordinates with the new ones wherever your build names +them: + + * dependency declarations and `` entries, BOMs and + Gradle version catalogs; + * exclusions, which match on coordinates: an exclusion of the old + coordinates does not exclude the new ones; + * lock files and dependency verification files, which need regenerating; + * allowlists in repository managers and license or security scanners. + +The old coordinates keep getting a relocation POM with each release. It +contains no code. A build that asks for a later release under the old +coordinates gets the JAR from the new ones, and Maven prints a warning that +the artifact has been relocated. This keeps dependency update tools working, +but it is a bridge, not a place to stay. + +**A build pinned to 20261110.1 or earlier does not migrate by itself, and +gets no further fixes.** Those releases are unchanged and carry no +relocation. + +### Two copies on the class path + +Maven and Gradle treat the old and new coordinates as unrelated artifacts. +If your build depends on the new coordinates while another dependency still +brings in 20261110.1 or earlier under the old ones, both JARs are resolved. +They contain the same classes, and the JVM uses whichever comes first on the +class path or module path, so an older sanitizer can silently be the one +that runs. Check for this after migrating: + +``` +mvn dependency:tree -Dincludes=com.googlecode.owasp-java-html-sanitizer +gradle dependencyInsight --dependency owasp-java-html-sanitizer +``` + +If either shows the old coordinates at 20261110.1 or earlier, do one of +these. Each leaves a single JAR, the new one. The old coordinates at a +later version are only the relocation, which Gradle still lists, and are +harmless. + +Maven, manage the old coordinates to a relocated version, the one you use +under the new coordinates: + +```Java + + + + com.googlecode.owasp-java-html-sanitizer + owasp-java-html-sanitizer + 20261110.1 + + + +``` + +Maven, or exclude them from the dependency that brings them in: + +```Java + + + com.googlecode.owasp-java-html-sanitizer + owasp-java-html-sanitizer + + +``` + +Gradle, substitute the new module for the old one in every configuration, +with the version you use in place of `VERSION`: + +``` +configurations.all { + resolutionStrategy.dependencySubstitution { + substitute module('com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer') using module('org.owasp.html-sanitizer:html-sanitizer:VERSION') + } +} +``` + +A Gradle dependency constraint on the old coordinates at a relocated +version, or an `exclude`, works as well. diff --git a/empiricism/pom.xml b/empiricism/pom.xml index 91d391d4..72f68289 100644 --- a/empiricism/pom.xml +++ b/empiricism/pom.xml @@ -1,11 +1,11 @@ 4.0.0 - empiricism + html-sanitizer-empiricism 20000101-SNAPSHOT jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp.html-sanitizer + html-sanitizer-parent 20000101-SNAPSHOT @@ -22,13 +22,13 @@ - com.googlecode.owasp-java-html-sanitizer - owasp-java-html-sanitizer + org.owasp.html-sanitizer + html-sanitizer ${project.version} - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp.html-sanitizer + html-sanitizer-java8-shim ${project.version} diff --git a/examples/pom.xml b/examples/pom.xml index 7cd6e009..b63853aa 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - examples + html-sanitizer-examples jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp.html-sanitizer + html-sanitizer-parent 20000101-SNAPSHOT @@ -29,8 +29,8 @@ - com.googlecode.owasp-java-html-sanitizer - owasp-java-html-sanitizer + org.owasp.html-sanitizer + html-sanitizer ${project.version} - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp.html-sanitizer + html-sanitizer-java8-shim ${project.version} runtime - com.googlecode.owasp-java-html-sanitizer - java10-shim + org.owasp.html-sanitizer + html-sanitizer-java10-shim ${project.version} runtime diff --git a/java10-shim/pom.xml b/java10-shim/pom.xml index ed8e07dc..b626b054 100644 --- a/java10-shim/pom.xml +++ b/java10-shim/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - java10-shim + html-sanitizer-java10-shim jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp.html-sanitizer + html-sanitizer-parent 20000101-SNAPSHOT @@ -18,7 +18,7 @@ 10 - + true @@ -59,8 +59,8 @@ - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp.html-sanitizer + html-sanitizer-java8-shim diff --git a/java8-shim/pom.xml b/java8-shim/pom.xml index 085ef17b..b1ec15dc 100644 --- a/java8-shim/pom.xml +++ b/java8-shim/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - java8-shim + html-sanitizer-java8-shim jar - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp.html-sanitizer + html-sanitizer-parent 20000101-SNAPSHOT @@ -12,7 +12,7 @@ https://github.com/OWASP/java-html-sanitizer - + true diff --git a/legacy-relocation/pom.xml b/legacy-relocation/pom.xml new file mode 100644 index 00000000..d7e0b506 --- /dev/null +++ b/legacy-relocation/pom.xml @@ -0,0 +1,35 @@ + + + + + 4.0.0 + + org.owasp.html-sanitizer + 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.html-sanitizer:html-sanitizer. + Releases from this version on are published only under the new + coordinates. + + https://github.com/OWASP/java-html-sanitizer + + + + org.owasp.html-sanitizer + html-sanitizer + The OWASP Java HTML Sanitizer is now published as org.owasp.html-sanitizer: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..cb6d1d90 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.html-sanitizer: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..4dd366da 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 + html-sanitizer bundle - com.googlecode.owasp-java-html-sanitizer - parent + org.owasp.html-sanitizer + 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.html-sanitizer:html-sanitizer-java8-shim + org.owasp.html-sanitizer:html-sanitizer-java10-shim @@ -199,8 +205,14 @@ *:* - 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 pattern loose + enough to match both shims can also match this + artifact's own directory and strip the metadata + that dependency scanners use to identify the + JAR. --> + META-INF/maven/org.owasp.html-sanitizer/html-sanitizer-java8-shim/** + META-INF/maven/org.owasp.html-sanitizer/html-sanitizer-java10-shim/** - com.googlecode.owasp-java-html-sanitizer:java10-shim + org.owasp.html-sanitizer:html-sanitizer-java10-shim META-INF/versions/** @@ -338,13 +350,13 @@ - com.googlecode.owasp-java-html-sanitizer - java8-shim + org.owasp.html-sanitizer + html-sanitizer-java8-shim true - com.googlecode.owasp-java-html-sanitizer - java10-shim + org.owasp.html-sanitizer + 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..db1baf06 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,13 @@ 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..c9c6602f --- /dev/null +++ b/scripts/check-staged-release.sh @@ -0,0 +1,91 @@ +#!/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.html-sanitizer, 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/html-sanitizer/html-sanitizer/$version/html-sanitizer-$version +parent=org/owasp/html-sanitizer/html-sanitizer-parent/$version/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) +# A checksum or signature counts as the file it belongs to, so one that sits +# beside no expected component is reported instead of being uploaded. The +# repository metadata is the only thing JReleaser leaves out of the bundle, +# and it follows symbolic links, so they are listed too. +actual=$(cd "$repository" && find . ! -type d ! -name 'maven-metadata.xml*' | + sed -E 's#^\./##; s#(\.asc)?(\.(md5|sha1|sha256|sha512))?$##' | sort -u) +if [[ $actual != "$expected" ]]; then + echo 'Staged artifacts differ from the expected release components:' >&2 + diff <(echo "$expected") <(echo "$actual") >&2 || true + exit 1 +fi +while IFS= read -r component; do + if [[ ! -f $repository/$component ]]; then + echo "Staged release lacks $component" >&2 + exit 1 + fi +done <<<"$expected" + +relocation=$(tr -d ' \n\r\t' < "$repository/$legacy.pom") +for element in 'org.owasp.html-sanitizerhtml-sanitizer' \ + 'pom'; do + if [[ $relocation != *"$element"* ]]; then + echo "Relocation POM lacks $element" >&2 + exit 1 + fi +done +target=${relocation#*} +target=${target%%*} +if [[ $relocation == *''* || $target == *''* ]]; then + echo 'Relocation POM must have no dependencies and no pinned target version' >&2 + exit 1 +fi + +# The library has no runtime dependencies and the shims are not published, +# so a dependency in its POM that is neither test nor provided scope would +# reach every consumer, and one on a shim would not resolve. +pom=$(tr -d ' \n\r\t' < "$repository/$library.pom") +# The count below takes every dependency outside as one a consumer +# gets. A profile or dependency management would put others among them, +# and the POM has neither, so refuse one that does rather than misread it. +if [[ $pom == *''* || $pom == *''* ]]; then + echo 'Library POM has profiles or dependency management, which this check does not read' >&2 + exit 1 +fi +if [[ $pom == *''* ]]; then + pom=${pom%%*}${pom##*} +fi +declared=$({ grep -o '' <<<"$pom" || true; } | wc -l | tr -d ' ') +scoped=$({ grep -o -E '(test|provided)' <<<"$pom" || true; } | wc -l | tr -d ' ') +if [[ $declared -eq 0 || $declared -ne $scoped ]]; then + echo "Library POM must declare only test and provided dependencies: $declared declared, $scoped so scoped" >&2 + exit 1 +fi + +entries=$(unzip -Z1 "$repository/$library.jar") +if ! grep -qx 'META-INF/maven/org.owasp.html-sanitizer/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/validate-central-bundle.sh b/scripts/validate-central-bundle.sh new file mode 100755 index 00000000..acec34dd --- /dev/null +++ b/scripts/validate-central-bundle.sh @@ -0,0 +1,120 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 OR BSD-2-Clause + +# Uploads a deployment bundle to the Maven Central Publisher Portal so that +# Central validates it, reports the result, and drops the deployment. It +# never publishes: the upload is USER_MANAGED, which Central holds until a +# separate publish request, and this script makes none. Use it with a +# bundle built at a placeholder version to learn, before a real release, +# whether the publishing token may deploy every namespace in the bundle. + +set -euo pipefail + +bundle=${1:?deployment bundle required} +api=${2:-https://central.sonatype.com/api/v1/publisher} +poll_seconds=${3:-10} +: "${SONATYPE_USERNAME:?SONATYPE_USERNAME required}" +: "${SONATYPE_PASSWORD:?SONATYPE_PASSWORD required}" +if [[ ! -f $bundle ]]; then + echo "Deployment bundle $bundle does not exist" >&2 + exit 1 +fi + +portal=https://central.sonatype.com/publishing/deployments +auth_file=$(mktemp) +deployment= +finish() { + rm -f "$auth_file" + if [[ -n $deployment ]]; then + echo "::warning::Deployment $deployment was not dropped; drop it, and do not publish it, at $portal" >&2 + fi +} +trap finish EXIT +chmod 600 "$auth_file" +# Keep the token out of the process list. +printf 'header = "Authorization: Bearer %s"\n' \ + "$(printf '%s:%s' "$SONATYPE_USERNAME" "$SONATYPE_PASSWORD" | base64 | tr -d '\n')" > "$auth_file" +# Prints the response body. When Central refuses, the body says why, so it +# goes to the log before the script stops. +call() { + local body + if ! body=$(curl --silent --show-error --fail-with-body --max-time 300 --config "$auth_file" "$@"); then + printf '%s\n' "$body" >&2 + return 1 + fi + printf '%s\n' "$body" +} + +# JReleaser asks Central whether each POM's coordinates are already +# published before it uploads, so ask the same question with the same token. +poms=$(unzip -Z1 "$bundle" | grep '\.pom$') || true +if [[ -z $poms ]]; then + echo "Deployment bundle $bundle cannot be read or holds no POM" >&2 + exit 1 +fi +while IFS= read -r pom; do + artifact_version=${pom%/*} + artifact_path=${artifact_version%/*} + group_path=${artifact_path%/*} + namespace=${group_path//\//.} + name=${artifact_path##*/} + version=${artifact_version##*/} + published=$(call --get --data-urlencode "namespace=$namespace" --data-urlencode "name=$name" \ + --data-urlencode "version=$version" "$api/published") + if ! jq -e '.published == false' <<<"$published" > /dev/null 2>&1; then + echo "Central does not report $namespace:$name:$version as unpublished: $published" >&2 + exit 1 + fi + echo "Not yet published, as expected: $namespace:$name:$version" +done <<<"$poms" + +# If the request fails part-way, Central may still have taken the bundle. +if ! uploaded=$(call --request POST --form "bundle=@$bundle" \ + "$api/upload?name=validation-only-DO-NOT-PUBLISH&publishingType=USER_MANAGED") || + [[ ! $uploaded =~ ^[0-9a-f-]{36}$ ]]; then + echo "::warning::The upload may have left a deployment; look at $portal and drop it without publishing" >&2 + echo 'Central did not return a deployment identifier' >&2 + exit 1 +fi +deployment=$uploaded +echo "Uploaded as deployment $deployment; waiting for validation" + +state=PENDING +status= +failures=0 +for _ in $(seq 60); do + # An answer that is not JSON counts as no answer. + if status=$(call --request POST "$api/status?id=$deployment") && + parsed=$(jq -r '.deploymentState // "UNKNOWN"' <<<"$status" 2> /dev/null); then + failures=0 + state=$parsed + if [[ $state != PENDING && $state != VALIDATING ]]; then + break + fi + elif ((++failures >= 3)); then + printf '%s\n' "$status" >&2 + echo 'Central gave no usable answer to three status requests in a row' >&2 + exit 1 + fi + sleep "$poll_seconds" +done +echo "Deployment state: $state" +jq '{deploymentState, purls, errors}' <<<"$status" 2> /dev/null || printf '%s\n' "$status" + +# Central drops only deployments that have finished validating. One that +# is left behind stays unpublished, and the exit handler says so. +if [[ $state == VALIDATED || $state == FAILED ]] && + call --request DELETE "$api/deployment/$deployment" > /dev/null; then + echo "Dropped deployment $deployment" + deployment= +fi + +if [[ $state != VALIDATED ]]; then + echo 'Central did not validate the bundle' >&2 + exit 1 +fi +if [[ -n $deployment ]]; then + echo 'Central validated the bundle, but the deployment could not be dropped' >&2 + exit 1 +fi +echo 'Central validated the bundle; nothing was published' 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..c4d98864 --- /dev/null +++ b/scripts/with-release-key.sh @@ -0,0 +1,46 @@ +#!/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 +# The key is in the keyring now; the command has no use for the armored copy. +unset GPG_SECRET_KEY GPG_PUBLIC_KEY +"$@"