Skip to content

API key scopes are defined but not enforced on most write endpoints #390

Description

@Abidoyesimze

src/auth/scopes.ts (#374) defines a granular UserScope catalog for user API keys — deposit:write, goals:write, recurring_deposits:write, strategies:write, webhooks:manage, vault:write, alerts:manage, fiat:write, etc. — and requireScope() in src/middleware/apiKeyAuth.ts is the middleware meant to enforce it.

In practice requireScope is only wired up on two route files: src/routes/withdraw.ts and src/routes/keys.ts. Every other route that owns one of those named scopes — deposit.ts, goals.ts, recurring-deposits.ts, strategies.ts, webhooks.ts, vault.ts, alerts.ts, fiat.ts — only calls requireAuth, with no scope check at all.

for f in src/routes/*.ts; do grep -q "requireScope" "$f" || echo "$f"; done

Since requireAuth accepts both sessions and API keys, an API key created with DEFAULT_READ_SCOPES (read-only: portfolio:read, transactions:read, vault:read) is not actually prevented from calling these write endpoints — the scope catalog exists but isn't the access boundary it looks like.

Task

  • Audit every route under src/routes against the scope it should require per USER_SCOPES.
  • Attach the matching requireScope(...) guard (pattern already established in withdraw.ts).
  • Add regression tests (e.g. extend tests/unit/middleware/apiKeyAuth.test.ts) asserting a key without the relevant scope gets 403 on each affected route.

Acceptance criteria

  • Every write route enforces the scope named after it in USER_SCOPES.
  • A read-only-scoped API key gets 403 on all of them.

Activity

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

Metadata

Metadata

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions