Serialize the LogEvent message delegate through the filtered wrapper - #4271
Open
ppkarwasz wants to merge 1 commit into
Open
Serialize the LogEvent message delegate through the filtered wrapper#4271ppkarwasz wants to merge 1 commit into
LogEvent message delegate through the filtered wrapper#4271ppkarwasz wants to merge 1 commit into
Conversation
`Log4jLogEvent.LogEventProxy` used `java.rmi.MarshalledObject` to transport its `Message` delegate. `MarshalledObject.get()` deserializes its embedded bytes on a private, unfiltered `ObjectInputStream`, so the delegate escaped the deserialization allow-list entirely. The message is now written with the same `SerializationUtil.writeWrappedObject`/`readWrappedObject` mechanism used by `ObjectMessage`, which re-applies the allow-list to the nested stream, and `java.rmi.MarshalledObject` is removed from the allow-list. Compatibility: log events serialized by Log4j 2.8.2-2.25.x are rejected by newer readers, since `MarshalledObject` no longer passes the filter. Events serialized by this version remain readable by older versions, with the message downgraded to a `SimpleMessage`. The serialized-event fixture in `Log4jLogEventTest` is regenerated accordingly, and the stale, unused `serializedEvent.dat` resource is removed (`SerializedLayoutTest` always rewrites it before reading). Part of the hardening series from #4168. Assisted-By: Claude Fable 5 <noreply@anthropic.com>
ppkarwasz
force-pushed
the
feat/2.x/log-event-proxy-wrapped-message
branch
from
August 31, 2026 21:25
3b05d04 to
3df4199
Compare
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.
Since 2.8.2,
Log4jLogEvent.LogEventProxytransported itsMessagedelegate inside ajava.rmi.MarshalledObject.MarshalledObject.get()deserializes its embedded bytes on a private, unfilteredObjectInputStream, so the nested message bypassed bothFilteredObjectInputStreamand the JEP 290 filter.The message is now written with the same
SerializationUtil.writeWrappedObject/readWrappedObjectmechanism already used byObjectMessage, which re-applies the deserialization filter to the nested stream, andjava.rmi.MarshalledObjectis removed from the allowlist. A message that is rejected or unreadable on the receiving side degrades to aSimpleMessagebuilt from the formatted message string, as before.Compatibility: this changes the serialized form of
LogEventProxy.MarshalledObjectno longer passes the filter.SimpleMessage.ObjectMessagesemantics, such a failure now propagates to the caller as anIOException.The serialized-event fixture in
Log4jLogEventTestpredatednanoOfMillisecondand the trace-context fields and has been regenerated; the staleserializedEvent.dattest resource was unused (SerializedLayoutTestalways rewrites it before reading) and is removed.Stacked on #4270.