fix(gateway): limit plugin route backend trust

This commit is contained in:
Rai Butera 2026-03-14 11:53:33 +00:00
parent bdf4ed03c0
commit a36d22ad63
2 changed files with 35 additions and 1 deletions

View File

@ -178,6 +178,40 @@ describe("createGatewayPluginRequestHandler", () => {
expect(log.warn).toHaveBeenCalledWith(expect.stringContaining("missing scope: operator.admin"));
});
it("does not mark unauthenticated plugin routes as internal backend clients", async () => {
loadOpenClawPlugins.mockReset();
handleGatewayRequest.mockReset();
handleGatewayRequest.mockImplementation(async (opts: HandleGatewayRequestOptions) => {
opts.respond(true, { internal: opts.client?.isInternalBackendClient === true });
});
const subagent = await createSubagentRuntime();
const handler = createGatewayPluginRequestHandler({
registry: createTestRegistry({
httpRoutes: [
createRoute({
path: "/hook",
auth: "plugin",
handler: async (_req, _res) => {
await subagent.deleteSession({ sessionKey: "agent:main:subagent:child" });
return true;
},
}),
],
}),
log: createPluginLog(),
});
const { res } = makeMockHttpResponse();
const handled = await handler({ url: "/hook" } as IncomingMessage, res, undefined, {
gatewayAuthSatisfied: false,
});
expect(handled).toBe(true);
expect(handleGatewayRequest).toHaveBeenCalledTimes(1);
expect(handleGatewayRequest.mock.calls[0]?.[0]?.client?.isInternalBackendClient).toBe(false);
});
it("returns false when no routes are registered", async () => {
const log = createPluginLog();
const handler = createGatewayPluginRequestHandler({

View File

@ -49,7 +49,7 @@ function createPluginRouteRuntimeClient(params: {
role: "operator",
scopes,
},
isInternalBackendClient: true,
isInternalBackendClient: params.requiresGatewayAuth && params.gatewayAuthSatisfied !== false,
};
}