Skip to content

id(web/main): /api/identity/me, /api/identity/register and /api/identity/name responses shape-trusted — a wrong-shape 200 persists a fake 'undefined' / '[object Object]' identity in localStorage #7839

Closed

Description

@developing-today

id(web/main): /api/identity/me, /api/identity/register and /api/identity/name responses shape-trusted — a wrong-shape 200 persists a fake 'undefined' / '[object Object]' identity in localStorage

Summary

The client identity flow in pkgs/id/web/src/main.ts uses the JSON bodies of
all three identity endpoints with no shape validation:

  • ensureIdentity() — const data = await resp.json(); for
    /api/identity/me (main.ts:148) and /api/identity/register (main.ts:185)
  • updateDisplayName() — const data = await resp.json(); for
    /api/identity/name (main.ts:215)

data.token, data.client_id and data.name flow straight into
saveIdentity() (main.ts:91), which writes them to localStorage via
setItem — and Web Storage coerces non-string values with String(value).
A wrong-shape 200 therefore does not just fail one request: it persists a
corrupt identity that survives reloads
and overwrites a previously valid
stored token.

Verified evidence (laptop, origin/main @1aea9b5f75)

Probe: ~/git/fleet/probe-identity-shape on the laptop — main.ts lines
63–224 extracted byte-verbatim (diff-checked against
git show origin/main:pkgs/id/web/src/main.ts, md5 f182df7ec224deda5298b8023c84da3f),
run under Bun with a spec-faithful localStorage stub (setItem coerces via
String()) and a stubbed fetch. Controls pass: a well-formed register
body registers and stores correctly, and a well-formed /me body rotates
the stored token.

Wrong-shape results:

Scenario Result
register {} fake success: identity {token: undefined, clientId: undefined} returned; localStorage stores the literal strings "undefined" / "undefined"; getStoredIdentity() on the next load rehydrates {token: "undefined", clientId: "undefined"}
register "abc" same fake success + "undefined" credentials persisted
register {token: 123, client_id: {x: 1}} persists token "123" and client_id "[object Object]"
register null raw TypeError on data.token, caught and logged as a generic registration error (returns null)
/me {token: {evil: 1}} with a valid stored identity overwrites the good stored token with the literal string "[object Object]"
/me {token: 12345} numeric token accepted and persisted as "12345"
/me null raw TypeError, caught by the network-error branch and misreported as an identity-check failure (stored identity returned optimistically)
/name {name: 123} updateDisplayName returns 123 as the name and persists "123"

Why it matters

Identity is the credential layer for the whole web UI. A single malformed
200 — from a proxy, a partial deploy, a different server version, or a
compromised/misbehaving endpoint — permanently poisons the stored identity
until localStorage is manually cleared: the client then presents token
"undefined" / "[object Object]" on every subsequent load, and the /me
path can destroy an otherwise valid token in place. This is the same
validate-where-you-read-it gap as #7811/#7823/#7831/#7837, but worse than
the display-only cases because the bad value is persisted as a
credential
.

Acceptance criteria

  • Parse all three identity responses through a validating parser
    (e.g. in identity-refresh.ts, alongside identityNeedsRefresh):
    the body must be a plain object; token/client_id, when required
    or present, must be non-empty strings; name must be a string or
    null. Anything else is a failed validation/register/name update —
    never a persisted value.
  • A wrong-shape /me 200 must not overwrite, coerce, or clear the
    stored identity; a wrong-shape register 200 must not call
    saveIdentity at all.
  • Regression tests (vitest, named oracle: the validated-parser
    contract) covering at least: {}, null, a bare string, a numeric
    token, and an object token/client_id for register and /me, plus a
    non-string name for /name — each asserting localStorage is
    unchanged / no identity is returned.
  • Existing web suites stay green (in particular identity-refresh,
    world, image-browser, image-upload suites).

Found by the fleet issue creator (Lane B); sibling pattern of
#7811/#7823/#7831/#7837 — different module, endpoints, and a persisted
credential sink, so filed separately.

Activity

  1. added
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    priority/normalOrdinary priority (the default)
    source/creatorFiled by the new-issue-creator job
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    on Nov 8, 2026
  2. developing-today commented on Nov 8, 2026

    @developing-today
    ContributorAuthor

    🤖 Agent note · filed

  3. dezren39 commented on Nov 10, 2026

    @dezren39
    Member

    🤖 Agent note · parked — awaiting triage

  4. dezren39 commented on Nov 11, 2026

    @dezren39
    Member

    agent-note:v1
    state: triaged
    task: 14019
    lane: code-b (repo-worker-code)
    Inline triage (runbook 1c): work kind small-fix (task/small-fix, already on issue #7839); priority/normal (a wrong-shape 200 silently persists a fake identity — bad, but requires a misbehaving/compromised endpoint, so not expedited); effort/s (effort/s already on issue); kind/bug already present. status/needs-triage removed; fix proceeds in this same claim.
    Verified live at current main 56cf191: pkgs/id/web/src/main.ts lines 148/185/215 still call resp.json() unguarded; data.token/data.client_id/data.name flow into saveIdentity which String()-coerces into localStorage. No open PR owns this (search 7839: none).
    First step: add validating parsers in identity-refresh.ts (home of identityNeedsRefresh; pattern parseUploadResponse), route all three endpoints through them, fail closed through existing error paths, never saveIdentity on a wrong-shape body.
    Acceptance: regression tests for {}, null, bare string, numeric/object token and client_id (register + /me) and non-string name (/name), asserting localStorage unchanged / no identity returned; pkgs/id web suite + typecheck green.

  5. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed on Nov 11, 2026
  6. dezren39 commented on Nov 11, 2026

    @dezren39
    Member

    agent-note:v1
    state: pr_opened
    task: 14019
    lane: code-b (repo-worker-code)
    PR #8505 opened (head c26fce3, branch queue/14019-7839-identity-response-validation): validating parsers parseIdentityMeResponse / parseIdentityRegisterResponse / parseIdentityNameResponse added in identity-refresh.ts; all three fetch sites in main.ts routed through them — a wrong-shape 200 now fails through the existing error paths and never reaches saveIdentity/updateStoredName.
    Tests: identity-refresh.test.ts 15/15 pass (10 new regression tests: {}, null, bare string, array, numeric/object token and client_id, empty token, non-string name); tsc --noEmit clean; full pkgs/id web suite 720 passed with 1 pre-existing failure (search-panel.test.ts, verified failing identically on clean main) and 1 flake (tags.test.ts, passes in isolation on both trees).

  7. added 2 commits that reference this issue on Nov 11, 2026
  8. dezren39 commented on Nov 11, 2026

    @dezren39
    Member

    state: done (already_done — verified merged)
    task 14019 (small_fix) — issue #7839 / PR #8505 — lane tmp-code-y, 2026-11-11

    Claimed task 14019 and re-verified fresh before any work: PR #8505 is MERGED (mergedAt 2026-11-11T04:00:25Z, merge commit 52f7965, merged head 1f01c77) and issue #7839 is CLOSED. Codex review on the merged head completed with no findings. The merge landed after this task's last checkpoint (pr_opened) via the standing merge path, so no further work was needed from this lane.

    Terminal: task 14019 completed with outcome already_done on this evidence. Stale in-flight labels (status/in-progress, queue/claimed, work/assigned) removed from the closed issue in the same pass.

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

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions