fix(rpc): close prototype-chain permission bypass, add server/client/transport tests
C1 CRITICAL: implement() looked up procedures/handlers with plain property indexing, so any Object.prototype member name (constructor, toString, etc.) resolved truthy and skipped the permission gate entirely. Fixed with Object.hasOwn checks in packages/rpc/src/server.ts. Defense-in-depth guard added in packages/dev-server/src/rpc-dispatch.ts constraining URL path segments to a safe charset before they reach service/procedure lookups. Added missing direct test coverage for packages/rpc/src/transport.ts, server.ts and client.ts (previously untested), including a prototype-name sweep in both server.test.ts and dev-server's rpc-endpoint.test.ts. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -37,8 +37,14 @@ export function implement<Procedures extends AnyProcedures>(
|
||||
return {
|
||||
contract,
|
||||
async invoke(procedureName, payload, identity) {
|
||||
const definition = contract.procedures[procedureName as keyof Procedures];
|
||||
const handler = handlers[procedureName as keyof Procedures];
|
||||
// Object.hasOwn, not plain indexing: "constructor", "toString" and every
|
||||
// other Object.prototype member otherwise resolve as truthy, and a
|
||||
// prototype member carries no `permission`, so the gate below is skipped
|
||||
// entirely and an unintended function runs with attacker-controlled input.
|
||||
const known =
|
||||
Object.hasOwn(contract.procedures, procedureName) && Object.hasOwn(handlers, procedureName);
|
||||
const definition = known ? contract.procedures[procedureName as keyof Procedures] : undefined;
|
||||
const handler = known ? handlers[procedureName as keyof Procedures] : undefined;
|
||||
if (!definition || !handler) return failure(RPC_ERROR_CODES.unknown, "Unknown procedure");
|
||||
|
||||
let subject: SubjectContext | undefined;
|
||||
|
||||
Reference in New Issue
Block a user