Skip to content

Commit 5fcca74

Browse files
authored
[GEODE-10599] Secure JMX query expression deserialization via ValidatingObjectInputStream (#8025)
* Secure JMX query expression deserialization via ValidatingObjectInputStream * fix formatting * license
1 parent b37841a commit 5fcca74

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

geode-web/src/main/java/org/apache/geode/management/internal/web/controllers/ShellCommandsController.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.apache.commons.io.IOUtils.toInputStream;
1818
import static org.apache.geode.management.internal.web.util.UriUtils.decode;
1919

20+
import java.io.ByteArrayInputStream;
2021
import java.io.FileInputStream;
2122
import java.io.IOException;
2223
import java.nio.file.Path;
@@ -34,6 +35,7 @@
3435
import javax.management.ReflectionException;
3536

3637
import org.apache.commons.io.FileUtils;
38+
import org.apache.commons.io.serialization.ValidatingObjectInputStream;
3739
import org.apache.commons.lang3.ArrayUtils;
3840
import org.springframework.core.io.InputStreamResource;
3941
import org.springframework.http.HttpHeaders;
@@ -169,8 +171,12 @@ public ResponseEntity<?> queryNames(@RequestParam("objectName") final String obj
169171
ObjectName name = ObjectName.getInstance(decode(objectName));
170172
QueryExp query = null;
171173
if (queryExpressionBase64 != null) {
172-
query =
173-
(QueryExp) IOUtils.deserializeObject(Base64.getDecoder().decode(queryExpressionBase64));
174+
byte[] decodedBytes = Base64.getDecoder().decode(queryExpressionBase64);
175+
try (ValidatingObjectInputStream ois =
176+
new ValidatingObjectInputStream(new ByteArrayInputStream(decodedBytes))) {
177+
ois.accept("javax.management.*", "java.lang.*", "java.util.*");
178+
query = (QueryExp) ois.readObject();
179+
}
174180
}
175181
final Set<ObjectName> objectNames = getMBeanServer().queryNames(name, query);
176182
return new ResponseEntity<>(IOUtils.serializeObject(objectNames), HttpStatus.OK);
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3+
* agreements. See the NOTICE file distributed with this work for additional information regarding
4+
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
5+
* "License"); you may not use this file except in compliance with the License. You may obtain a
6+
* 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 distributed under the License
11+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12+
* or implied. See the License for the specific language governing permissions and limitations under
13+
* the License.
14+
*/
15+
package org.apache.geode.management.internal.web.controllers;
16+
17+
import java.io.ByteArrayInputStream;
18+
import java.io.ByteArrayOutputStream;
19+
import java.io.ObjectOutputStream;
20+
21+
import javax.management.Query;
22+
import javax.management.QueryExp;
23+
24+
import org.apache.commons.io.serialization.ValidatingObjectInputStream;
25+
import org.junit.Test;
26+
27+
public class QueryExpDeserializationTest {
28+
@Test
29+
public void testQueryExp() throws Exception {
30+
QueryExp query = Query.eq(Query.attr("Name"), Query.value("mock"));
31+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
32+
ObjectOutputStream oos = new ObjectOutputStream(baos);
33+
oos.writeObject(query);
34+
oos.close();
35+
36+
byte[] decoded = baos.toByteArray();
37+
ValidatingObjectInputStream ois =
38+
new ValidatingObjectInputStream(new ByteArrayInputStream(decoded));
39+
ois.accept("javax.management.*", "java.lang.*", "java.util.*");
40+
41+
QueryExp q = (QueryExp) ois.readObject();
42+
System.out.println(q);
43+
}
44+
}

0 commit comments

Comments
 (0)