0
Fork 0
mirror of https://github.com/oblien/openship.git synced 2026-11-16 06:57:12 +00:00
openship/apps/api/test/modules/audit
Saim Shafique 3fd39c5dc5
fix(api): stamp PAT token id on REST audit rows and audit token reads (#1708)
* fix(api): stamp PAT token id on REST audit rows and audit token reads

Two gaps in the audit log, both from the same root: a REST call made
with a personal access token left no trace of WHICH token made it, and
a successful read made with a token left no row at all — while the
same read through MCP was audited with the token id attached.

- resolveCallClientId now falls back to the credential the auth layer
  already resolved: a token principal's session id IS its canonical
  principal id (pat:<id> / oauth:<clientId>), minted from the
  hashed-token lookup, not from anything the caller supplies. The
  nonce-signed MCP claim still wins. Browser sessions never reach the
  fallback (no principalKind), so a cookie session id can never land
  in the column. Shared operations and the deployment create path use
  the same resolver, so their rows gain the token id too. No schema
  change: the column was documented for exactly this value.
- The route emitter now audits successful reads/lists by token
  principals (PAT / OAuth) — a script holding a token gets the same
  "what did it look at" treatment MCP already gives its reads.
  Browser reads stay unaudited (too noisy), failed reads are still
  not logged, and operations that already recorded the call still
  skip the emitter. One exception: reads of the audit log itself are
  not audited — every such read would append a row to the log, so its
  total could never be stable and its facets would be dominated by
  whoever reads it most.

Fixes #1703

* fix(api): clear the error-boundary gate and the tokens parity expectation

The error-boundary gate flagged the pre-auth catch in
resolveCallClientId as unobserved. It only runs when no
RequestContext exists yet, so there is no credential to derive
from: mark it with the repo's diagnostics-ignore marker.

The tokens SDK-parity audit test listed only the three MCP rows,
but token reads are now audited by design, so the two remote
token-client reads in that test add two settings:read rows.
Expect them, matching the settings/webhooks parity updates.

Fixes #1703

* fix(api): avoid duplicate MCP read audit events

* fix(api): simplify audit coverage and reject malformed nonce bytes

---------

Co-authored-by: Hydra <abdelhamedmo59@gmail.com>
History 2026-11-11 14:43:44 +02:00
..
_env.ts batch 0.5.5 2026-08-05 03:12:09 +03:00
_harness.ts ship sdk, intial scale panel 2026-09-14 01:34:59 +03:00
audit-agent-attribution.test.ts fix(security): upgrade Better Auth to 1.7.15 and patch Hono (#1568) 2026-11-03 14:23:26 +02:00
audit-filters.test.ts batch 0.5.5 2026-08-05 03:12:09 +03:00
audit-settings.test.ts ship sdk, intial scale panel 2026-09-14 01:34:59 +03:00
settings-audit-sdk-parity.test.ts fix(api): stamp PAT token id on REST audit rows and audit token reads (#1708) 2026-11-11 14:43:44 +02:00