Skip to content

[Bug]: Malformed RPC payload throws ParseError inside scope resolution, producing a defect report instead of a 403 #26491

Closed

Description

@IzonIcy

requiredScopesForRpcCall (packages/contracts/src/clientRpcPermissions.ts ~71-84) decodes payloads with Schema.decodeUnknownSync to pick a dynamic scope, and runs synchronously from the middleware factory (apps/server/src/auth/RpcAuthorization.ts ~229-279) before any authorization decision. A malformed payload to serverUpdateSettings, projectsMutate, assetsCreateUrl, gitRunStackedAction, or gitPreparePullRequestThread throws there, and Effect RPC surfaces it as a server defect (the connection survives with disableFatalDefects, but a defect report is emitted).

Any authenticated session, including a deliberately narrow read-only one, can loop malformed calls and generate unbounded defect reports and log noise, and receives an ambiguous internal error rather than a clean invalid-request/403.

Expected: decode with Schema.decodeUnknownEither and return a typed failure (invalid request) on parse failure, failing closed. Do not fall back to the static table scope on decode failure; serverUpdateSettings can require providers:manage beyond settings:write, so a fallback would under-authorize.

I plan to submit a focused fix (Either-based decode with typed failure, with a test).

Activity

  1. juliusmarminge commented on Oct 28, 2026

    @juliusmarminge
    Member

    Thanks for the detailed write-up. I tested this on main at 5211acf, and malformed payloads never reach requiredScopesForRpcCall.

    Effect RPC's RpcServer.make decodes each request's payload against the RPC's payloadSchema before it calls the handler or any middleware. A failed decode is answered at that point with that request's own failure. RpcScopeAuthorization only ever receives payloads that already decoded. The five RPCs you list (server.updateSettings, projects.mutate, assets.createUrl, git.runStackedAction, git.preparePullRequestThread) declare the same schemas that the scope resolver decodes again, so a payload that gets through the first decode also gets through the second.

    What I ran: a vp run dev server with a fresh database, a bearer session issued with only orchestration:read, and raw RPC frames over /ws:

    • Malformed payloads to all five RPCs: each came back as its own request's failure with the schema message, for example Expected object at ["patch"] or Missing key at ["cwd"]. The server logged no Unhandled defect, and the socket stayed open. A server.probe sent afterwards succeeded.
    • A valid but unauthorized server.updateSettings (defaultRuntimeMode: "full-access") returned EnvironmentAuthorizationError for settings:write.
    • With temporary logging inside requiredScopesForRpcCall, only the three valid calls reached it; none of the malformed calls did.

    So scope resolution doesn't throw here, and no defect report is emitted. Closing as not a bug. If you have a payload that does get past the RPC's own decode and then throws in the scope resolver, please reopen with the frame and we'll look again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions