fix(security): withhold amounts from REST answers for keys without usage:read

Aperta
#783 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
next.js, react, typescript
Ambito
api, security

Direzione di ricerca

Read src/lib/mcp/server.ts:127-144 to understand the existing scope withholding, then inspect src/lib/api/resources.ts and src/lib/api/endpoints.ts for the REST event and alert responses. First, resolve the open choice between options A and B on the issue; the acceptance criteria require both surfaces and docs to follow that decision. Done means the documented scope rule is consistent and tests cover each scope on both surfaces.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: security bug decision impact: low priority: P3 size: S

Context

Found by the Fable pre-production review on 2026-12-02 (main at cedc1914; every line reference below re-checked on main at cde5aa3b). Source: security and privacy readiness report, new issue 6.

The MCP server and the REST API apply different rules to the same API key:

  • MCP withholds money from a key without usage:read: list_events and list_alerts drop the fields that can quote an amount (SPEND_SCOPE and ALERT_MONEY_FIELDS, src/lib/mcp/server.ts:127-144; rule stated at :36-37). docs/mcp.md:9 says such a key "never sees an amount".
  • REST returns those fields under events:read and alerts:read alone (src/lib/api/endpoints.ts:102, :112): event title and body (src/lib/api/resources.ts:234-235), and alert threshold_label and observed_amount_minor (:273, :275).

Impact: low. The holder of an events:read key calls GET /api/v1/events and reads daily summary spend and payment amounts in titles and bodies, which the scope model says that key should not see. Only workspace owners and admins create keys.

Option Pros Cons Effort Impact
Status quo: REST returns amounts under events:read and alerts:read No change docs/mcp.md:9 is false for the same key on REST; the scope model differs by surface XS (nothing) A key scoped away from spend can still read it over REST; no data outside the workspace
A. REST applies MCP's withholding for keys without usage:read One rule on both surfaces; the docs claim becomes true A REST client using events:read today loses event text it may rely on; needs a changelog note S Spend stays behind usage:read everywhere
B. Keep REST as is and change docs/mcp.md and docs/api.md to say only MCP withholds No behavior change Two rules for one key; the scope name usage:read no longer means what it says XS Same exposure as today, documented

Files each option touches:

Option Files
Status quo none
A src/lib/api/resources.ts, src/lib/api/endpoints.ts, a shared withholding helper with src/lib/mcp/server.ts, docs/api.md, tests
B docs/mcp.md, docs/api.md

Recommendation: A. The deciding argument: a scope is a promise about the key, not the surface, and the MCP rule already exists to reuse. Second choice: B.

Plan

  1. Eddie picks an option on this issue.
  2. For A: move the withholding into a helper shared by MCP and REST, apply it in the REST event and alert resources, and state the rule in docs/api.md.
  3. For B: correct docs/mcp.md:9 and docs/api.md.

Acceptance criteria

  • The chosen option is recorded on this issue.
  • REST and MCP answer the same key the same way, or the docs say exactly where they differ.
  • docs/api.md states the rule.
  • A test covers each scope on both surfaces.
  • Playwright e2e: none needed, API only.

Files and areas

src/lib/api/, src/lib/mcp/server.ts, docs/api.md, docs/mcp.md, tests.

Non-goals: new scopes, rate limits (#96).

Verification

npm run typecheck, npm run lint, npx vitest run src/lib/api src/lib/mcp.


Branch: <issue-number>-rest-withhold-amounts

Model: anthropic/claude-opus-5-5 | Reasoning effort: unknown

Lingua principale
TypeScript
Stelle
13
Fork
2
Merge medio
5h 20m
PR unite (30g)
287

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di eddiejaoude/StackDash

Tutte le issue di eddiejaoude/StackDash

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.