Harden ZookeeperDistributedQueue deserialization against insecure deserialization (CWE-502)#51
Open
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
… deserialization (CWE-502) Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
A Brief Overview
ZookeeperDistributedQueue.deserialize()calledObjectInputStream.readObject()on bytes read back from Zookeeper with no class filtering. Any actor able to influence the data stored in the queue's Zookeeper nodes could supply a serialized "gadget chain" payload and achieve arbitrary class instantiation / remote code execution (CWE-502).This PR applies a JDK
ObjectInputFilterallowlist before any object in the stream is resolved, so only known-safe classes can be deserialized; everything else is rejected.What changed
DEFAULT_DESERIALIZATION_ALLOWLIST, anObjectInputFilterpattern that permits only standard JDK value/collection types (java.lang.*,java.util.*+ concurrent,java.time.*,java.math.*,java.net.*,java.sql.*) andorg.broadleafcommerce.**, ending in!*to reject everything else. It also caps stream size, graph depth, array length, and reference count to limit resource-exhaustion attacks.deserialize(byte[])now delegates to a newdeserialize(byte[], ObjectInputFilter)that callsois.setObjectInputFilter(filter)beforereadObject(). A rejected class surfaces asInvalidClassException, which is wrapped in the existingDistributedQueueException(no behavior change for callers).getDeserializationAllowlist()/getDeserializationFilter()so subclasses that store custom serializable payloads can extend the allowlist while keeping the trailing!*.Note:
serialize()is unchanged — pre-existing queue entries written by trusted nodes use only allowlisted types and continue to round-trip.Additional context
Added
ZookeeperDistributedQueueDeserializationTest(5 tests, all passing) covering: allowlisted scalar/collection round-trips, rejection of a non-allowlistedSerializableclass (java.io.Fileas a gadget stand-in) with anInvalidClassExceptioncause, a control case proving the same payload deserializes when the filter is disabled, and that the allowlist terminates in!*.Run with:
Suggested labels: Bug, Security, Severity: critical, Status: ready-for-code-review
Link to Devin session: https://app.devin.ai/sessions/6bcd41977dc3474bb303860f5a728e6a
Requested by: @Colhodm
Devin Review