-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
pippo-session-parent/pippo-session/src/main/java/ro/pippo/session/ClassFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
private ArrayList<String> WhiteList= null; | ||
public ClassFilter() { | ||
WhiteList=new ArrayList<String>(); | ||
WhiteList.add("ro.pippo.session.SessionData"); | ||
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; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ssion-parent/pippo-session/src/main/java/ro/pippo/session/FilteringObjectInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package ro.pippo.session; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InvalidClassException; | ||
import java.io.ObjectInputStream; | ||
|
||
/** | ||
* @author idealzh | ||
*/ | ||
public class FilteringObjectInputStream extends ObjectInputStream { | ||
public FilteringObjectInputStream(InputStream in) throws IOException { | ||
super(in); | ||
} | ||
|
||
protected Class<?> resolveClass(java.io.ObjectStreamClass descriptor) throws ClassNotFoundException, IOException { | ||
String className = descriptor.getName(); | ||
ClassFilter classFilter = new ClassFilter(); | ||
if(className != null && className.length() > 0 && !classFilter.isWhiteListed(className)) { | ||
throw new InvalidClassException("Unauthorized deserialization attempt", descriptor.getName()); | ||
} else { | ||
return super.resolveClass(descriptor); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters