Skip to content

Endpoint-route 401 in dispatcher-plugin mountRouteOnServer writes an inline flat body with no code key — the one producer #9487's constant change does not reach #9823

Description

@huangyiirene

Parent: #9487 (found during that card's Zone-2 producer sweep; filed unassigned for triage). The #9487 maintainer ruling — add code: "UNAUTHENTICATED" alongside the existing error / message keys, additive only — is the authority for the fix shape here too.

Observed

packages/runtime/src/dispatcher-plugin.tsmountRouteOnServer (the 401 arm at lines 213–221 on main @ 4c260cda5) writes an inline copy of the flat anonymous-deny body:

res.status(401);// ...res.json({error: 'UNAUTHENTICATED',message: 'Authentication is required to access this endpoint.',});

It does not reference ANONYMOUS_DENY_BODY, so the #9487 constant change does not reach it. A repo-wide sweep for the deny message finds exactly two non-test producers: the @objectstack/core constant (fixed by #9487's PR) and this inline copy.

Impact

Service-declared endpoint routes (RouteDefinition emitted via hooks, e.g. buildAIRoutes() — any route with auth not explicitly false) answer an anonymous caller 401 { error, message } with no code key. Through @objectstack/client, err.code stays undefined for those 401s — the exact defect #9487 fixed for the REST enforceAuth seam. #9487's acceptance property ("one documented key identifies the machine code on every error family, 401 included") is not universal until this site moves.

Fix shape (per the #9487 ruling — additive only)

The file already imports from @objectstack/core, and the shared constant exists precisely so seams cannot drift: replace the inline literal with res.json(ANONYMOUS_DENY_BODY) (plus ANONYMOUS_DENY_STATUS for the status), or minimally add code: 'UNAUTHENTICATED'. Additive only — no key removed or moved.

Notes for the implementer


Generated by Claude Code

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions