Skip to content

Commit

Permalink
fix: move custom OIS implementations to patch to a separate config value
Browse files Browse the repository at this point in the history
Otherwise the class patching in older SiB
versions would break with a newer remote config
  • Loading branch information
dogboy21 committed Aug 20, 2023
1 parent 9c6e3f6 commit 332b69e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public class Patches {

public static PatchModule getPatchModuleForClass(String className) {
for (PatchModule patchModule : SerializationIsBad.getInstance().getConfig().getPatchModules()) {
if (patchModule.getClassesToPatch().contains(className)) {
if (patchModule.getClassesToPatch().contains(className)
|| patchModule.getCustomOISClasses().contains(className)) {
return patchModule;
}
}
Expand All @@ -43,8 +44,13 @@ private static byte[] writeClassNode(ClassNode classNode) {

private static void applyPatches(String className, ClassNode classNode, boolean passClassLoader) {
SerializationIsBad.logger.info("Applying patches to " + className);
PatchModule patchModule = Patches.getPatchModuleForClass(className);
if (patchModule == null) {
SerializationIsBad.logger.info(" No patches to apply");
return;
}

if ("java/io/ObjectInputStream".equals(classNode.superName)) {
if (patchModule.getCustomOISClasses().contains(className) && "java/io/ObjectInputStream".equals(classNode.superName)) {
for (MethodNode methodNode : classNode.methods) {
if (!"resolveClass".equals(methodNode.name)) continue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

public class PatchModule {
private Set<String> classesToPatch;
private Set<String> customOISClasses;
private Set<String> classAllowlist;
private Set<String> packageAllowlist;

public PatchModule() {
this.classesToPatch = new HashSet<>();
this.customOISClasses = new HashSet<>();
this.classAllowlist = new HashSet<>();
this.packageAllowlist = new HashSet<>();
}
Expand All @@ -22,6 +24,15 @@ public void setClassesToPatch(Set<String> classesToPatch) {
this.classesToPatch = classesToPatch;
}


public Set<String> getCustomOISClasses() {
return this.customOISClasses;
}

public void setCustomOISClasses(Set<String> customOISClasses) {
this.customOISClasses = customOISClasses;
}

public Set<String> getClassAllowlist() {
return this.classAllowlist;
}
Expand All @@ -37,4 +48,5 @@ public Set<String> getPackageAllowlist() {
public void setPackageAllowlist(Set<String> packageAllowlist) {
this.packageAllowlist = packageAllowlist;
}

}

0 comments on commit 332b69e

Please sign in to comment.