Apply the deserialization filter in test helpers on Java 9+ - #4270
Open
ppkarwasz wants to merge 1 commit into
Open
Apply the deserialization filter in test helpers on Java 9+#4270ppkarwasz wants to merge 1 commit into
ppkarwasz wants to merge 1 commit into
Conversation
The `SerialUtil` test helper returned a plain, unfiltered `ObjectInputStream` on Java 9 and later, so the deserialization allowlist was only ever exercised by tests running on a Java 8 toolchain. It now installs `DefaultObjectInputFilter` (reflectively, since the class must still compile and run on Java 8), combined with an `ObjectInputFilter.Config.createFilter` delegate built from the caller-supplied extra allowed classes, reproducing the `FilteredObjectInputStream` semantics on modern JDKs. When `DefaultObjectInputFilter` is absent (it only exists in the packaged multi-release JAR), the helper falls back to `FilteredObjectInputStream` on any Java version. `SerializationTestHelper` in `log4j-1.2-api` now delegates to `SerialUtil`, so its `org.apache.log4j.*` extras are honored on all Java versions as well. Part of the hardening series from #4168. Assisted-By: Claude Fable 5 <[email protected]>
ppkarwasz
force-pushed
the
feat/2.x/serial-util-java9-filter
branch
from
August 31, 2026 21:21
513e55a to
c245cf5
Compare
ppkarwasz
changed the base branch from
2.x
to
feat/2.x/filtered-stream-reject-proxies
August 31, 2026 21:23
Contributor
|
I checked the Java 9+ branch with a packaged Nothing tests it though. On |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
This PR is part of the deserialization hardening work tracked in #4168. The Logging Services PMC does not use nor recommend Java serialization/deserialization, and our security FAQ has long documented this position. This work is submitted solely to reduce the false-positive "vulnerability" reports that keep being filed regardless of that FAQ. Its utility for end users is close to zero.
The
SerialUtiltest helper returned a plain, unfilteredObjectInputStreamon Java 9 and later, so our test suite only exercised the deserialization allowlist when running on a Java 8 toolchain. This made it possible for a change to the serialized forms to pass CI while being rejected by the filter at runtime.SerialUtilnow installsDefaultObjectInputFilteron Java 9+ (reflectively, since the helper must still compile and run on Java 8), combined with anObjectInputFilter.Config.createFilterdelegate built from the caller-supplied extra allowed classes — reproducingFilteredObjectInputStream's semantics on modern JDKs. WhenDefaultObjectInputFilteris unavailable — it only exists in the packaged multi-releaselog4j-apijar, not in classes-dir reactor builds — the helper falls back toFilteredObjectInputStream, which enforces the same allowlist on any Java version.SerializationTestHelperinlog4j-1.2-apinow delegates toSerialUtil, so itsorg.apache.log4j.*extras are honored on all Java versions as well.Test-only change; no user-visible behavior is affected.