Skip to content

Commit 5c90141

Browse files
anidotnetclaude
andauthored
Merge commit from fork
The v1-compat migration deserializer passed stored bytes straight to ObjectInputStream.readObject() with no class restriction, so any Serializable class on the classpath could be instantiated. With a suitable gadget chain this is a remote-code-execution vector reachable on every file-based store open via MVStoreUtils.testForMigration() (CWE-502, CVSS 9.8). Enforce a JEP 290 allowlist filter that only permits Nitrite's own types and standard JDK types; all other classes are rejected before their readObject/readResolve callbacks run. Applied to both v1-compat deserializers (NitriteObjectInputStream and the raw ObjectDataType read path). Bump version to 4.4.1. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 982838e commit 5c90141

15 files changed

Lines changed: 133 additions & 13 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## Release 4.4.1 - Jul 2, 2026
2+
3+
### Security Fixes
4+
5+
- Fix unfiltered Java deserialization in the legacy v1 database migration path (CWE-502, GHSA-9297-g93h-86gg, CVSS 9.8)
6+
- Opening a file-based store runs `MVStoreUtils.testForMigration()`, which for a legacy v1-format file deserialized stored values through `ObjectInputStream.readObject()` with no class restriction. Any `Serializable` class on the embedding application's classpath could be instantiated, so a suitable gadget chain (e.g. from commons-collections) made a malicious `.db` file a remote-code-execution vector.
7+
- The v1-compat deserializer now enforces a JEP 290 allowlist filter that only permits Nitrite's own types and standard JDK types; any other class is rejected before its `readObject`/`readResolve` callbacks can run. Applications that open Nitrite database files from untrusted sources (e.g. "import"/"restore backup" features) should upgrade.
8+
19
## Release 4.4.0 - Jul 2, 2026
210

311
### Upgrade Notes

‎nitrite-bom/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.dizitart</groupId>
66
<artifactId>nitrite-java</artifactId>
7-
<version>4.4.0</version>
7+
<version>4.4.1</version>
88
</parent>
99

1010
<artifactId>nitrite-bom</artifactId>

‎nitrite-jackson-mapper/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.dizitart</groupId>
66
<artifactId>nitrite-java</artifactId>
7-
<version>4.4.0</version>
7+
<version>4.4.1</version>
88
</parent>
99

1010
<artifactId>nitrite-jackson-mapper</artifactId>

‎nitrite-mvstore-adapter/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.dizitart</groupId>
66
<artifactId>nitrite-java</artifactId>
7-
<version>4.4.0</version>
7+
<version>4.4.1</version>
88
</parent>
99

1010
<artifactId>nitrite-mvstore-adapter</artifactId>

‎nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/NitriteObjectInputStream.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import java.io.IOException;
2222
import java.io.InputStream;
23+
import java.io.ObjectInputFilter;
2324
import java.io.ObjectInputStream;
2425
import java.io.ObjectStreamClass;
2526
import java.util.HashMap;
@@ -30,9 +31,18 @@
3031
* @author Anindya Chatterjee.
3132
*/
3233
@Slf4j(topic = "nitrite-mvstore")
33-
class NitriteObjectInputStream extends ObjectInputStream {
34+
public class NitriteObjectInputStream extends ObjectInputStream {
3435
private static final Map<String, Class<?>> migrationMap = new HashMap<>();
3536

37+
/**
38+
* Allowlist filter for the legacy v1 migration path (CWE-502). Only Nitrite's
39+
* own (compat) types and standard JDK types may be deserialized; any other
40+
* class - e.g. a third-party gadget on the classpath - is rejected. See
41+
* GHSA-9297-g93h-86gg.
42+
*/
43+
static final ObjectInputFilter SERIAL_FILTER = ObjectInputFilter.Config.createFilter(
44+
"maxdepth=32;org.dizitart.no2.**;java.**;!*");
45+
3646
static {
3747
migrationMap.put("org.dizitart.no2.Security$UserCredential", Compat.UserCredential.class);
3848
migrationMap.put("org.dizitart.no2.NitriteId", Compat.NitriteId.class);
@@ -51,6 +61,7 @@ class NitriteObjectInputStream extends ObjectInputStream {
5161
*/
5262
public NitriteObjectInputStream(InputStream stream) throws IOException {
5363
super(stream);
64+
setObjectInputFilter(SERIAL_FILTER);
5465
}
5566

5667
@Override

‎nitrite-mvstore-adapter/src/main/java/org/dizitart/no2/mvstore/compat/v1/mvstore/type/ObjectDataType.java‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
import java.io.ByteArrayInputStream;
1313
import java.io.ByteArrayOutputStream;
14-
import java.io.ObjectInputStream;
1514
import java.io.ObjectOutputStream;
1615
import java.lang.reflect.Array;
16+
import org.dizitart.no2.mvstore.compat.v1.NitriteObjectInputStream;
17+
1718
import java.math.BigDecimal;
1819
import java.math.BigInteger;
1920
import java.nio.ByteBuffer;
@@ -371,7 +372,9 @@ public static byte[] serialize(Object obj) {
371372
public static Object deserialize(byte[] data) {
372373
try {
373374
ByteArrayInputStream in = new ByteArrayInputStream(data);
374-
ObjectInputStream is = new ObjectInputStream(in);
375+
// route through the allowlist-filtered stream to prevent unsafe
376+
// deserialization during legacy v1 migration (CWE-502, GHSA-9297-g93h-86gg)
377+
NitriteObjectInputStream is = new NitriteObjectInputStream(in);
375378
return is.readObject();
376379
} catch (Throwable e) {
377380
throw DataUtils.newIllegalArgumentException(
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2019-2020. Nitrite author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.evil;
18+
19+
import java.io.ObjectInputStream;
20+
import java.io.Serializable;
21+
22+
/**
23+
* Stands in for a third-party gadget class on the classpath (outside the
24+
* {@code org.dizitart.no2} / {@code java} allowlist) for GHSA-9297-g93h-86gg.
25+
*/
26+
public class EvilGadget implements Serializable {
27+
private static final long serialVersionUID = 1L;
28+
public static boolean readObjectCalled = false;
29+
30+
private void readObject(ObjectInputStream in) throws Exception {
31+
in.defaultReadObject();
32+
readObjectCalled = true;
33+
}
34+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2019-2020. Nitrite author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.dizitart.no2.mvstore.compat.v1;
18+
19+
import com.evil.EvilGadget;
20+
import org.junit.Test;
21+
22+
import java.io.ByteArrayOutputStream;
23+
import java.io.ObjectOutputStream;
24+
import java.util.LinkedHashMap;
25+
26+
import static org.junit.Assert.*;
27+
28+
/**
29+
* Regression test for GHSA-9297-g93h-86gg: the legacy v1 migration deserializer
30+
* must reject arbitrary (potentially gadget) classes on the classpath.
31+
*/
32+
public class NitriteObjectInputStreamTest {
33+
34+
private static byte[] serialize(Object obj) throws Exception {
35+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
36+
try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
37+
oos.writeObject(obj);
38+
}
39+
return bos.toByteArray();
40+
}
41+
42+
@Test
43+
public void rejectsUnknownClass() throws Exception {
44+
EvilGadget.readObjectCalled = false;
45+
byte[] payload = serialize(new EvilGadget());
46+
47+
try {
48+
NitriteDataType.deserialize(payload);
49+
fail("expected deserialization of a non-allowlisted class to be rejected");
50+
} catch (IllegalArgumentException expected) {
51+
// filter rejected the class before its readObject() could run
52+
}
53+
assertFalse("gadget readObject() must not be invoked", EvilGadget.readObjectCalled);
54+
}
55+
56+
@Test
57+
public void allowsStandardTypes() throws Exception {
58+
assertEquals("hello", NitriteDataType.deserialize(serialize("hello")));
59+
60+
LinkedHashMap<String, Object> doc = new LinkedHashMap<>();
61+
doc.put("k", 42L);
62+
assertEquals(doc, NitriteDataType.deserialize(serialize(doc)));
63+
}
64+
}

‎nitrite-native-tests/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>org.dizitart</groupId>
99
<artifactId>nitrite-java</artifactId>
10-
<version>4.4.0</version>
10+
<version>4.4.1</version>
1111
</parent>
1212

1313
<artifactId>nitrite-native-tests</artifactId>

‎nitrite-rocksdb-adapter/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.dizitart</groupId>
66
<artifactId>nitrite-java</artifactId>
7-
<version>4.4.0</version>
7+
<version>4.4.1</version>
88
</parent>
99

1010
<artifactId>nitrite-rocksdb-adapter</artifactId>

0 commit comments

Comments
 (0)