Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 458 #470

Merged
merged 9 commits into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### [Unreleased][unreleased]

#### Fixed
- [#458]: Java deserialization vulnerability in SerializationSessionDataTranscoder.decode()
rygel marked this conversation as resolved.
Show resolved Hide resolved

#### Changed
- [#466]: Updated `FastJson` to latest version 1.2.51
- [#466]: Updated `FastJson` tp latest version 1.2.51

#### Added

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ro.pippo.session;

import java.util.ArrayList;

/**
* @author idealzh
*/
public class ClassFilter {
rygel marked this conversation as resolved.
Show resolved Hide resolved
private ArrayList<String> WhiteList= null;
rygel marked this conversation as resolved.
Show resolved Hide resolved
public ClassFilter() {
WhiteList=new ArrayList<String>();
WhiteList.add("ro.pippo.session.DefaultSessionData");
WhiteList.add("java.util.HashMap");
WhiteList.add("ro.pippo.core.Flash");
WhiteList.add("java.util.ArrayList");
}

public boolean isWhiteListed(String className) {
if (className==null) return false;
for(String name:WhiteList) {
if(name.equals(className)) return true;
} return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ro.pippo.session;
rygel marked this conversation as resolved.
Show resolved Hide resolved

import java.io.IOException;
import java.io.InputStream;
import java.io.InvalidClassException;
import java.io.ObjectInputStream;

/**
* @author idealzh
*/
public class FilteringObjectInputStream extends ObjectInputStream {
rygel marked this conversation as resolved.
Show resolved Hide resolved
public FilteringObjectInputStream(InputStream in) throws IOException {
super(in);
}

protected Class<?> resolveClass(java.io.ObjectStreamClass descriptor) throws ClassNotFoundException, IOException {
rygel marked this conversation as resolved.
Show resolved Hide resolved
String className = descriptor.getName();
ClassFilter classFilter = new ClassFilter();
if(className != null && className.length() > 0 && !classFilter.isWhiteListed(className)) {
rygel marked this conversation as resolved.
Show resolved Hide resolved
throw new InvalidClassException("Unauthorized deserialization attempt", descriptor.getName());
} else {
return super.resolveClass(descriptor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String encode(SessionData sessionData) {
public SessionData decode(String data) {
byte[] bytes = Base64.getDecoder().decode(data);
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(bytes);
ObjectInputStream objectInputStream = new ObjectInputStream(inputStream)) {
FilteringObjectInputStream objectInputStream = new FilteringObjectInputStream(inputStream)) {
return (SessionData) objectInputStream.readObject();
} catch (IOException | ClassNotFoundException e) {
throw new PippoRuntimeException(e, "Cannot deserialize session. A new one will be created.");
Expand Down