Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Closed
Changes from all 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
45 changes: 21 additions & 24 deletions packages/core/src/actor/router-endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,41 +427,23 @@ export async function handleAction(
logger().debug("handling action", { actionName, encoding });

// Validate incoming request
let actionArgs: unknown[];
let body: unknown;
if (encoding === "json") {
try {
const body = await c.req.json();

// Validate using the action schema
const result = protoHttpAction.ActionRequestSchema.safeParse(body);
if (!result.success) {
throw new errors.InvalidActionRequest("Invalid action request format");
}

actionArgs = result.data.a;
body = await c.req.json();
} catch (err) {
if (err instanceof errors.InvalidActionRequest) {
throw err;
}
throw new errors.InvalidActionRequest("Invalid JSON");
throw new errors.InvalidActionRequest(
`Invalid JSON: ${stringifyError(err)}`,
);
}
} else if (encoding === "cbor") {
try {
const value = await c.req.arrayBuffer();
const uint8Array = new Uint8Array(value);
const deserialized = await deserialize(
uint8Array as unknown as InputData,
encoding,
);

// Validate using the action schema
const result =
protoHttpAction.ActionRequestSchema.safeParse(deserialized);
if (!result.success) {
throw new errors.InvalidActionRequest("Invalid action request format");
}

actionArgs = result.data.a;
body = await deserialize(uint8Array as unknown as InputData, encoding);
} catch (err) {
throw new errors.InvalidActionRequest(
`Invalid binary format: ${stringifyError(err)}`,
Expand All @@ -471,6 +453,21 @@ export async function handleAction(
return assertUnreachable(encoding);
}

// Validate using the action schema
let actionArgs: unknown[];
try {
const result = protoHttpAction.ActionRequestSchema.safeParse(body);
if (!result.success) {
throw new errors.InvalidActionRequest("Invalid action request format");
}

actionArgs = result.data.a;
} catch (err) {
throw new errors.InvalidActionRequest(
`Invalid schema: ${stringifyError(err)}`,
);
}

// Invoke the action
let actor: AnyActorInstance | undefined;
let conn: AnyConn | undefined;
Expand Down
Loading