Harden ZookeeperDistributedQueue deserialization against untrusted class instantiation (CWE-502)#52
Open
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
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.
Purpose
Fixes an insecure deserialization vulnerability (CWE-502) in
ZookeeperDistributedQueue.deserialize(). The method fed data read from Zookeeper straight intoObjectInputStream.readObject()with no class filtering, so anyone able to influence the bytes stored in Zookeeper could trigger a "gadget chain" and achieve remote code execution.A Brief Overview
deserialize()now uses a hardenedObjectInputStream(ValidatingObjectInputStream) that validates every class against an allowlist before it is resolved, and rejects all dynamic proxy classes.Behavior:
The allowlist (
getAllowedDeserializationClassNames(), seeded fromDEFAULT_ALLOWED_DESERIALIZATION_CLASS_NAMES) accepts exact class names or package prefixes ending in.. Defaults cover the JDK value/collection types the queue itself relies on (e.g. theIntegercapacity marker,java.util.*,java.time.*,java.math.*, commonjava.langscalars) plusorg.broadleafcommerce.*. Array encodings such as[Ljava.lang.String;and[[Iare normalized to their base component type before matching; primitive-array components are always allowed.Compatibility note: applications that place custom
Serializablepayloads on the queue must register those class names, e.g.:Otherwise reads of those entries will fail with a wrapped
InvalidClassException. This is the intended, fail-closed behavior for CWE-502.Tests
Adds
ZookeeperDistributedQueueDeserializationTest(6 tests, all passing) covering: scalar/collection/array round-trips for allowlisted types, rejection of a non-allowlistedSerializable(java.io.File) with anInvalidClassExceptioncause, re-enabling it via the allowlist, and the class-name/array/gadget matching logic.Run:
Labels
Additional context
Fix is confined to
ZookeeperDistributedQueue; theserialize()path is unchanged, so entries written before this change remain readable as long as their types are on (or added to) the allowlist.Link to Devin session: https://app.devin.ai/sessions/7c7e5906d28a44459675d36c1b935a87
Requested by: @Colhodm
Devin Review