Skip to content

feat(audit): record the client surface on audit entries and identify CLI login requests - #7823

Merged
waleedlatif1 merged 1 commit into
stagingfrom
feat/audit-surface-cli-auth-header
Sep 14, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
feat/audit-surface-cli-auth-header

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Adds a nullable surface column to audit_log (web, desktop, cli, sdk-js, sdk-python), written from the client the route wrapper already resolves per request, so every audit entry recorded while serving a request says which client it came from
    • Read from the ambient request context in the one row builder shared by recordAudit, recordAuditBatch, and recordAuditOnce, so no caller changes; null for background work and callers that don't identify themselves
    • Not added to any read projection: the v1/v2 audit APIs, admin API, and data drain all map fields explicitly, so responses and exports are unchanged
  • Migration 0344_audit_log_surface is a single ADD COLUMN ... text (nullable, no default): metadata-only, compatible with the deployed app, which never writes it, and no contract step to follow. The snapshot diff is that one column
  • The CLI's OAuth discovery, token exchange/refresh, and device-flow poll now send X-Sim-Client-Info like every other CLI request, so they carry the coding agent instead of falling back to user-agent attribution
    • One identityHeaders() helper now supplies the user agent and client info for the API client and all three login requests, replacing four hand-written copies
    • Drops an unused clientInfoHeader barrel export

Type of Change

  • New feature

Testing

  • New audit tests: surface recorded from the request context, and absent outside a request; confirmed they fail without the change
  • Login token and device-poll tests assert both identity headers
  • CLI suite passes with and without the publish job's telemetry env; audit, db, sim-cli, and apps/sim type-check
  • bun run check:migrations, bun run lint, check:audits, and docs-manifest:check pass; full apps/sim suite passes apart from one unrelated timing test that passes on rerun

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Sep 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Sep 14, 2026 10:09pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge with no actionable correctness, security, migration, or repository-rule issues identified.

Summary

The PR adds client-surface attribution to audit rows and consistently identifies CLI login traffic.

  • Adds a nullable audit_log.surface column with matching migration metadata and Drizzle schema.
  • Populates audit surfaces from the request-scoped client context shared by single, batch, and idempotent audit writes.
  • Centralizes CLI identity headers and applies them to OAuth discovery, token requests, device-flow polling, and normal API requests.
  • Adds focused tests for request-context attribution and login identity headers.

Diagram

sequenceDiagram
  participant CLI
  participant Route as Sim route wrapper
  participant Context as Request context
  participant Audit as Audit writer
  participant DB as audit_log

  CLI->>Route: Request with User-Agent and X-Sim-Client-Info
  Route->>Route: Resolve official client surface
  Route->>Context: Run handler with client metadata
  Context->>Audit: recordAudit / recordAuditBatch / recordAuditOnce
  Audit->>Context: Read client.surface
  Audit->>DB: Insert audit row with nullable surface
Loading

Reviews (1) · Last reviewed commit: "feat(audit): record the client surface o..."

@waleedlatif1
waleedlatif1 merged commit 5a7b924 into staging Sep 14, 2026
33 checks passed
@waleedlatif1
waleedlatif1 deleted the feat/audit-surface-cli-auth-header branch September 14, 2026 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant