Skip to content

Commit

Permalink
fix: Do not allow unregistered classes in JSON RPC interface
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Aug 25, 2023
1 parent ad16b22 commit 898fbe0
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions yarn-project/foundation/src/json-rpc/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ export function convertFromJsonObj(cc: ClassConverter, obj: any): any {
}
return newObj;
}

// Throw if this is a non-primitive class that was not registered
if (typeof obj === 'object' && obj.constructor !== Object) {
throw new Error(`Object ${obj.constructor.name} not registered for deserialisation`);
}
// Leave alone, assume JSON primitive
return obj;
}
Expand Down Expand Up @@ -118,7 +121,10 @@ export function convertToJsonObj(cc: ClassConverter, obj: any): any {
}
return newObj;
}

// Throw if this is a non-primitive class that was not registered
if (typeof obj === 'object' && obj.constructor !== Object) {
throw new Error(`Object ${obj.constructor.name} not registered for serialisation`);
}
// Leave alone, assume JSON primitive
return obj;
}

0 comments on commit 898fbe0

Please sign in to comment.