Skip to content

Commit 020ca0e

Browse files
committed
👌 reane SafeObjectInputStream to ObjectInputStreams
1 parent 2ff73fb commit 020ca0e

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/main/java/io/github/pixee/security/SafeObjectInputStream.java renamed to src/main/java/io/github/pixee/security/ObjectInputStreams.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
* href="https://cheatsheetseries.owasp.org/cheatsheets/Deserialization_Cheat_Sheet.html">OWASP
1515
* Cheat Sheet</a>.
1616
*/
17-
public final class SafeObjectInputStream {
17+
public final class ObjectInputStreams {
1818

1919
/**
2020
* Private no-op constructor to prevent accidental initialization of this class
2121
*/
22-
private SafeObjectInputStream() {}
22+
private ObjectInputStreams() {}
2323

2424
/**
2525
* This method returns a wrapped {@link ObjectInputStream} that protects against deserialization
@@ -29,19 +29,12 @@ private SafeObjectInputStream() {}
2929
* @return an {@link ObjectInputStream} which is safe against all publicly known gadgets
3030
* @throws IOException if the underlying creation of {@link ObjectInputStream} fails
3131
*/
32-
public static ObjectInputStream createSafeObjectInputStream(final InputStream ois)
32+
public static ObjectInputStream createValidatingObjectInputStream(final InputStream ois)
3333
throws IOException {
34-
try {
35-
final ValidatingObjectInputStream is = new ValidatingObjectInputStream(ois);
36-
for (String gadget : UnwantedTypes.dangerousClassNameTokens()) {
37-
is.reject("*" + gadget + "*");
38-
}
39-
return is;
40-
} catch (IOException e) {
41-
// ignored
34+
final ValidatingObjectInputStream is = new ValidatingObjectInputStream(ois);
35+
for (String gadget : UnwantedTypes.dangerousClassNameTokens()) {
36+
is.reject("*" + gadget + "*");
4237
}
43-
44-
// if for some reason we can't replace it, we'll pass it back as it was given
45-
return new ObjectInputStream(ois);
38+
return is;
4639
}
4740
}

src/test/java/io/github/pixee/security/SafeObjectInputStreamTest.java renamed to src/test/java/io/github/pixee/security/ObjectInputStreamsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import static org.junit.jupiter.api.Assertions.assertThrows;
1616
import static org.junit.jupiter.api.Assertions.fail;
1717

18-
final class SafeObjectInputStreamTest {
18+
final class ObjectInputStreamsTest {
1919

2020
private static DiskFileItem gadget; // this is an evil gadget type
2121
private static byte[] serializedGadget; // this the serialized bytes of that gadget
@@ -41,7 +41,7 @@ static void setup() throws IOException {
4141
@Test
4242
void validating_ois_works() throws Exception {
4343
ObjectInputStream ois =
44-
SafeObjectInputStream.createSafeObjectInputStream(new ByteArrayInputStream(serializedGadget));
44+
ObjectInputStreams.createValidatingObjectInputStream(new ByteArrayInputStream(serializedGadget));
4545
assertThrows(
4646
InvalidClassException.class,
4747
() -> {

0 commit comments

Comments
 (0)