Harden ZookeeperDistributedQueue against insecure deserialization (CWE-502)#47
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
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.
A Brief Overview
ZookeeperDistributedQueue.deserialize()calledObjectInputStream.readObject()on bytes read from Zookeeper with no class filtering, a classic insecure-deserialization vulnerability (CWE-502). If an attacker can influence data stored in Zookeeper, a gadget chain on the classpath could lead to Remote Code Execution.This PR installs a JEP 290
ObjectInputFilterallowlist on theObjectInputStreamso only expected classes are ever resolved; everything else is rejected before itsreadObjectruns. The project targets Java 17, soObjectInputFilteris available natively (no new dependencies).What changed
deserialize()now sets anObjectInputFilteron the stream before reading:DEFAULT_DESERIALIZATION_FILTER_PATTERN) permits JDK value types/collections (java.langwrappers,java.util.*,java.time.*,java.math.*,java.lang.Objectfor the backing arrays of collections) plusorg.broadleafcommerce.**, and ends in!*to reject everything else. It also sets resource limits (maxbytes,maxdepth,maxrefs,maxarray) to guard against DoS.getDeserializationFilter()lazily falls back to the default so deserialization can never silently run unfiltered;setDeserializationFilter(...)/setDeserializationFilterPattern(...)let applications extend the allowlist for customSerializablequeue element types.Note: the allowlist matches by exact class name (not subtype), so the boxed wrapper types and
java.lang.Object(collection backing arrays) are enumerated explicitly.Tests
New
ZookeeperDistributedQueueDeserializationTest(uses EasyMockpartialMockBuilderto exercise the realserialize/deserializewithout the Zookeeper-dependent constructor):String,Integer,ArrayList) round-trip successfully;com.example.attack.MaliciousPayload, deliberately outsideorg.broadleafcommerce) is rejected with anInvalidClassExceptionand itsreadObjectnever executes;Labels: Security, critical, ready-for-code-review
Additional context
Behavioral change: queue payloads outside the default allowlist (custom application
Serializabletypes not underorg.broadleafcommerce) will be rejected until added viasetDeserializationFilterPattern(...). This is intentional fail-closed behavior.Link to Devin session: https://app.devin.ai/sessions/e0ea74c3a36a4e11b3018a37d9f355d0
Devin Review