Skip to content

cold-store-reaper: token-endpoint responses are parsed unguarded — a wrong-shape 200 from access_token/auth_exchange raises raw KeyError/TypeError/JSONDecodeError, not ColdStoreError #6846

Closed

Description

@dezren39

Problem

pkgs/cold-store-reaper/cold_store.py parses the OAuth token endpoint's
HTTP-200 responses with a bare json.loads(resp) and unchecked field
access in both auth flows — the exact assumption the D1 paths in the same
file were hardened against in issue #2618 (which added the guarded
_d1_parse_payload helper at :259-285). The token paths never got it:

  • auth_exchange (:648, payload at :667): payload.get("refresh_token")
    on whatever json.loads returned. A list body raises a raw
    AttributeError; a non-JSON 200 body raises a raw JSONDecodeError.
    (A dict body missing refresh_token is handled with a named
    ColdStoreError — the intended pattern, already present one line down.)
  • access_token (:678, payload at :708): the payload is subscripted for
    the token field and expires_in is added to the current timestamp with
    no shape checks at all:
    • dict body missing the token field → raw KeyError
    • list body → raw TypeError: list indices must be integers;
      string body → raw TypeError: string indices must be integers
    • non-JSON 200 body → raw JSONDecodeError
    • expires_in as a string or null → raw TypeError: unsupported operand type(s) for +: 'float' and 'str'/'NoneType' when computing
      the in-memory expiry
    • a non-string token value (e.g. 123) is returned unchecked and flows
      into the Authorization: Bearer … header built by _auth_headers

Every cold-store command goes through access_token() before touching
Drive/S3/D1, so a shape-drifted 200 from the token endpoint (or an
intermediary/proxy answering in its place — the transport layer in this
same file documents exactly that class of intermediary misbehavior for
S3) kills the run with a traceback that names neither the endpoint nor
the unexpected shape, instead of the module's own ColdStoreError.

Evidence (verified this run)

Laptop primary ~/git/code at origin/main
65beb42c1a70672bed159fe401c2cb1079aa516f. Probe:
~/git/fleet/probe-cold-store-state/probe_token.py (+ probe_token2.py)
against the real cold_store.py copied verbatim from origin/main
(sha256 39a1ecb1a8ff10dedcb59538cc6d2691d7a264e3def2afcb41963240dea27f2d),
with http_request stubbed to return HTTP 200 with canned bodies and a
fixture credentials file — no network, no real credentials.

Controls (as expected):

  • access_token with {"access_token": "…", "expires_in": 3600} → token
    returned, expiry set
  • auth_exchange with a dict carrying refresh_token → stored, returned
    summary; dict without refresh_token → named ColdStoreError
    (re-run-the-grant guidance)

Failing shapes:

  • access_token: missing token field → raw KeyError; token 123 →
    returned unchecked; expires_in "3600" or null → raw TypeError;
    body [] / "hello" → raw TypeError; body not json → raw
    JSONDecodeError
  • auth_exchange: body [] → raw AttributeError: 'list' object has no attribute 'get'; body not json → raw JSONDecodeError

Dedup: searched open + closed issues for cold-store token response shape, access_token ColdStoreError — no hits. Issue #2618 covers only
the D1 response paths (d1_error_message / _d1_select / sync loop) and
its fix added _d1_parse_payload in this same file; the token-endpoint
paths at :667/:708 do not use it. Issue #6845 (filed this run) covers the
local files load_state/load_credentials, a different input surface.

Why it matters

access_token() is on the critical path of every command. When the token
endpoint's 200 body drifts in shape, the operator currently gets a raw
KeyError/TypeError/JSONDecodeError with no indication that the
token response was the problem — and a non-string token silently
propagates into the Authorization header of every subsequent request.

Acceptance criteria

  • Both token-response parses (auth_exchange :667, access_token
    :708) validate the payload shape — reusing or mirroring the
    _d1_parse_payload pattern from cold-store-reaper: D1 response handling assumes object shapes throughout — array/string bodies and non-object errors/result entries raise AttributeError instead of ColdStoreError #2618 — so a non-JSON or
    non-object 200 body raises a ColdStoreError naming the token
    endpoint and the unexpected shape; no raw
    JSONDecodeError/AttributeError/TypeError escapes.
  • access_token: a missing or non-string token field raises the
    named ColdStoreError; a present expires_in must be a number —
    a string/null/object value raises the named error instead of a
    raw arithmetic TypeError (absent expires_in keeps the existing
    3600 default).
  • auth_exchange: the existing missing-refresh_token
    ColdStoreError behaviour is preserved, and a non-string
    refresh_token value is refused the same way rather than written
    into credentials.json.
  • New tests in pkgs/cold-store-reaper/tests/test_cold_store.py
    (transport stubbed, as in the probe) cover: non-JSON body, list
    body, missing token field, non-string token, string/null
    expires_in for access_token; list body and non-JSON body for
    auth_exchange; happy-path controls still pass.
  • The full cold-store test suite passes (laptop or CI).

Activity

  1. developing-today commented on Nov 7, 2026

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

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · picked up

  5. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · done

    What landed in PR #7001

    Note: PR #7001 was created through the developing.today GitHub App (fleet_paperwork REST route) because the user token's GraphQL rate limit is exceeded this shift; the branch push and all verification are unaffected.

  6. 16 remaining items

  7. added
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    on Nov 8, 2026
  8. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor

    🤖 Agent note · parked

  9. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 8, 2026
  10. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor
  11. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

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/cold-store-reaperPackage/app: cold-store-reaper (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 jobstatus:donetask/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