paperclip/server
Waseem Ilyas 1114ebaf42 fix(server): keep the JWT run-mismatch audit when the claimed run is missing
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for work
> - Rejected agent JWTs whose run header disagrees with the signed claim
    are audited into activity_log so operators can see spoof attempts
> - The audit insert writes the claimed run id into run_id, which is a
    real foreign key to heartbeat_runs; a bogus claim violates the FK and
    the catch swallows it, so the audit row is silently lost exactly when
    it matters most
> - This pull request verifies the claimed run exists before trusting it
    into the FK column; the claim itself stays in entityId and details
> - The benefit is a reliable audit trail for rejected credentials

## Linked Issues or Issue Description

Refs #10498 — the anonymous fall-through half was fixed on master already
(every failed-credential branch now returns an explicit 401/403/422);
this closes the residual FK-swallowed audit defect.

## What Changed

- server/src/middleware/auth.ts: auditAgentJwtRunHeaderMismatch looks up
  the claimed run id and populates runId only when the row exists;
  entityId and details.claimRunId carry the claim either way.
- server/src/__tests__/agent-auth-middleware.test.ts: a mismatch whose
  claimed run does not exist still produces the audit row with runId
  omitted.

## Verification

- pnpm --filter @paperclipai/server vitest run
  src/__tests__/agent-auth-middleware.test.ts — 17 tests pass.

## Risks

- Low risk. One extra indexed select on a rare rejection path; the audit
  payload is unchanged apart from runId now being conditional.

## Model Used

- Anthropic Claude — SWE-2 Max agent via Devin CLI, tool use and code
  execution.

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-09-10 23:05:53 +00:00
..
scripts fix(server): bundle the vendored paperclip-runner instead of hand-mirroring its deps (#13121) 2026-09-09 16:38:17 -07:00
src fix(server): keep the JWT run-mismatch audit when the claimed run is missing 2026-09-10 23:05:53 +00:00
CHANGELOG.md fix: bound workspace Git scans (#11572) 2026-08-17 22:11:30 -05:00
package.json fix(server): bundle the vendored paperclip-runner instead of hand-mirroring its deps (#13121) 2026-09-09 16:38:17 -07:00
tsconfig.json Fix root TypeScript solution config 2026-03-09 14:09:30 -05:00
vitest.config.ts fix(server): bundle the vendored paperclip-runner instead of hand-mirroring its deps (#13121) 2026-09-09 16:38:17 -07:00