Skip to content

OWASP API Security Top 10 Review (v1-draft)

API · Contract: openapi/mezgeb.v1.yaml · Threats: threat-model.md

Every endpoint group of the v1-draft contract, reviewed against the OWASP API Security Top 10 (2023). For each risk: what the contract does about it, and what steps 2.07 (implementation), 2.08 (authentication and authorisation) and 2.16 (security review) must still prove. “Contract” means the rule is already in openapi/mezgeb.v1.yaml; “must” is a requirement on the implementation.

Group Endpoints Who calls them
Accounts /v1/accounts… Client platforms (their own accounts); operators (status)
Templates and operations /v1/templates…, /v1/operations/* Client platforms
Entries /v1/entries/{id}, /v1/entries/by-idempotency-key/{key} Client platforms
Corrections /v1/entries/{id}/reversal, /v1/adjustments… Operators only
Holds /v1/holds… Client platforms
Periods and reports /v1/periods…, /v1/reports/* Operators only (periods: read by clients)
Offline /v1/offline/* Planned; 501
Risk Where it applies Contract The implementation must
API1 Broken object level authorisation Every {account_id}, {entry_id}, {hold_id}; every account named in an operation body A client sees only its own accounts and the entries that touch them; anything else is 404 not_found, never 403, so IDs cannot be probed (TM-05). Idempotency keys are per client Check ownership on every read and on every account bound in a body, in one place, before any engine call. A client may bind a system account (1010, 4010) only to a role whose chart codes allow it. Test that every endpoint returns 404 for another client’s object (2.08)
API2 Broken authentication All OAuth 2.0 client credentials on every operation; no endpoint is anonymous Short-lived tokens, verified signature and audience; no API keys in URLs; reject on clock skew; rate-limit the token endpoint (2.08)
API3 Broken object property level authorisation Request and response bodies Every request schema is closed (additionalProperties: false), so no field can be smuggled in (mass assignment). The requester and approver of a correction come from the token, never from the body. Responses carry no internal fields (no version, no row locks, no other client’s data) Reject unknown fields; build responses from explicit types, never from database rows
API4 Unrestricted resource consumption Lists, history, reports, posting limit is 1–100; history needs a bounded from/to; metadata is at most 32 keys and 4 KB; an entry at most 100 lines; 429 and Retry-After are part of the contract Enforce body size limits, request timeouts and per-client rate limits; cap report ranges; the 30-second transaction limit already bounds each posting
API5 Broken function level authorisation Corrections, account status, periods, reports Each operation names its scope. Operator functions have operator-only scopes (accounts:admin, corrections:write, adjustments:request, adjustments:approve, periods:close, reports:read) Never issue operator scopes to client platforms; check the scope before parsing the body; test every operation with a token lacking its scope (2.08)
API6 Unrestricted access to sensitive business flows Refunds, disputes, adjustments, withdrawals Clients post only through templates; there is no raw-lines endpoint except the adjustment, which needs a second, different person (maker_is_checker). Refunds are capped by the payment they name (INV-15). Withdrawals and disputes move whole items once Per-client and per-template limits and velocity alerts (refund ratio, TM-22); log every correction with both people (2.09)
API7 Server-side request forgery None The API never fetches a URL given by a caller: no webhooks, callbacks or URL fields in v1 Keep it so; any future webhook needs an allow-list (step 3.06)
API8 Security misconfiguration All Errors are Problem Details with a stable code and a short detail: no stack traces, SQL or internal IDs. Retryable errors say so TLS only; no CORS (server-to-server API); security headers; no default credentials; the error mapper is the only path to a response body
API9 Improper inventory management All One versioned contract (/v1), checked against the code by crates/api/tests/openapi.rs; planned endpoints are marked x-mezgeb-status: planned and answer 501; the compatibility policy is written down Serve exactly the documented paths; no debug or admin routes outside the contract; publish the contract with each release
API10 Unsafe consumption of APIs Offline receipts (planned) Offline receipts will be signed by devices and verified before settlement (spec §5, INV-22) Treat bank statements and device uploads as untrusted input; verify signatures and bounds before posting (2.12, 2.15)

Reviewing the endpoints against the list changed the design in three places:

  1. Adjustments are two-step. A single endpoint taking requested_by and approved_by in the body would let one operator claim a second approver (API3, API6). The contract has a request, then an approval or a rejection by a different authenticated person.
  2. Reversals take no actor fields. The requester comes from the token, so it cannot be spoofed (API3).
  3. Not found means not found or not yours. Using 404 for another client’s object, instead of 403, stops ID probing (API1).

What step 2.08 did against the “must” column (ADR-0017):

Risk Done Test
API1 Ownership on every read and every bound account, in shared helpers (routes/common.rs) before any engine call; another client’s object is 404 (or 422 bound_account_not_found in a body), as for none; a client binds system accounts only through template roles, and cannot open one a_client_cannot_touch_another_clients_accounts
API2 OAuth 2.0 client credentials; 15-minute tokens; secrets only in the Authorization header (never in URLs or bodies), kept as Argon2id hashes; the token endpoint rate-limited per credential before any hashing. Changed from the review: the tokens are opaque and looked up in the database, not signed, so there is no signature or audience to verify and no clock skew to reject (the ledger’s own clock decides expiry); revocation is instant instead contract/oauth.rs, revoked_credentials_and_disabled_clients_stop_at_once, clients_and_logins_are_rate_limited
API4 Per-client rate limits (429 rate_limited), with the body limit and timeouts of 2.07. Report ranges are still uncapped clients_and_logins_are_rate_limited
API5 Operator scopes belong only to operator roles in the permission matrix; the scope is checked before the request is read; every operation is tested with every role every_role_gets_exactly_what_the_matrix_allows, a_missing_scope_is_refused_before_the_request_is_read

Each risk against the implementation as it stands, not the design: what the code does, the test that shows it, and what the review found (findings).

Risk Holds? Evidence Found and fixed in 2.16
API1 Yes a_client_cannot_touch_another_clients_accounts; AC-03 (keys per client); AC-09 F-03: a refund naming another client’s entry told it apart from a missing one. Now both are 422 refunded_entry_not_found
API2 Yes contract/oauth.rs; revoked_credentials_and_disabled_clients_stop_at_once; dummy hash for unknown IDs F-01: inventing credential IDs passed the per-credential limit; failed logins now share a bucket for the service (ADR-0021)
API3 Yes 35 of 35 request types refuse unknown fields; actors come from the token (maker_is_checker)
API4 Mostly Body limit, timeouts, per-client and login limits; lists paginated 1–100; unauthenticated refusals summarised in the audit log F-01 (above). Open: two operator reports are not paginated (F-08, step 3.01); limits are per process (F-10, step 3.03)
API5 Yes every_role_gets_exactly_what_the_matrix_allows (63 operations × 6 roles, re-run); a_missing_scope_is_refused_before_the_request_is_read
API6 Yes Abuse suite: overspending, refunds past the cap, hold races, vouchers and receipts at once (AC-04 to AC-07)
API7 Yes The service fetches no URL; no webhooks yet
API8 Yes every_answer_carries_the_security_headers; no CORS; errors without internals; the published development key refused F-02: security headers on every response. F-05: the development signing key
API9 Yes tests/openapi.rs; every response of every API test, and of 24,000 fuzz cases, checked against the contract The fuzzer found one undocumented status (F-03)
API10 Yes Device receipts verified before settlement (crates/engine/tests/offline_receipts.rs); statements parsed as data
  • 3.01: paginate the trial balance and ageing reports (F-08).
  • 3.03: rate limits shared between instances (F-10).
  • 3.06: an allow-list for any webhook (API7).
  • 3.09: an alert when an audit event cannot be written (F-09).