mirror of
https://github.com/github/codeql.git
synced 2026-04-27 17:55:19 +02:00
Merge branch 'main' into atorralba/promote-ognl-injection
This commit is contained in:
34
java/ql/test/query-tests/security/CWE-502/KryoTest.java
Normal file
34
java/ql/test/query-tests/security/CWE-502/KryoTest.java
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import com.esotericsoftware.kryo.Kryo;
|
||||
import com.esotericsoftware.kryo.pool.KryoPool;
|
||||
import com.esotericsoftware.kryo.io.Input;
|
||||
|
||||
public class KryoTest {
|
||||
|
||||
private Kryo getSafeKryo() {
|
||||
Kryo kryo = new Kryo();
|
||||
kryo.setRegistrationRequired(true);
|
||||
// ... kryo.register(A.class) ...
|
||||
return kryo;
|
||||
}
|
||||
|
||||
public void kryoDeserialize(Socket sock) throws java.io.IOException {
|
||||
KryoPool kryoPool = new KryoPool.Builder(this::getSafeKryo).softReferences().build();
|
||||
Input input = new Input(sock.getInputStream());
|
||||
Object o = kryoPool.run(kryo -> kryo.readClassAndObject(input)); // OK
|
||||
}
|
||||
|
||||
public void kryoDeserialize2(Socket sock) throws java.io.IOException {
|
||||
KryoPool kryoPool = new KryoPool.Builder(this::getSafeKryo).softReferences().build();
|
||||
Input input = new Input(sock.getInputStream());
|
||||
Kryo k = kryoPool.borrow();
|
||||
try {
|
||||
Object o = k.readClassAndObject(input); // OK
|
||||
} finally {
|
||||
kryoPool.release(k);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user