feat(audit-log): add persistent audit log system with comprehensive route instrumentation#3242
feat(audit-log): add persistent audit log system with comprehensive route instrumentation#3242waleedlatif1 merged 10 commits intostagingfrom
Conversation
…oute instrumentation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
...orkspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/mcp/mcp.tsx
Show resolved
Hide resolved
Greptile SummaryThis PR adds a comprehensive audit logging system across the platform, instrumenting 53 API routes with fire-and-forget audit trail recording. It also includes a significant rework of the MCP domain validation logic to properly handle environment variable references in URLs. Key changes:
Minor concerns:
Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[API Route Handler] -->|Success path| B[recordAudit]
B --> C{Build audit entry}
C --> D[Extract IP from headers]
C --> E[Set workspaceId / actorId]
C --> F[Set action / resourceType]
D --> G[db.insert audit_log]
E --> G
F --> G
G -->|.then| H[Log debug]
G -->|.catch| I[Log error silently]
A -->|Return response| J[HTTP Response]
subgraph MCP Domain Validation
K[URL input] --> L{Has env var in hostname?}
L -->|Yes| M[Bypass domain check]
L -->|No| N{Domain in allowlist?}
N -->|Yes| O[Allow]
N -->|No| P[Reject]
M --> Q[Validate after env var resolution]
Q --> N
end
Last reviewed commit: 6d406c1 |
… remove redundant queries
- Make audit_log.workspace_id nullable with ON DELETE SET NULL (logs survive workspace/user deletion)
- Make audit_log.actor_id nullable with ON DELETE SET NULL
- Replace all 53 routes' string literal action/resourceType with AuditAction.X and AuditResourceType.X enums
- Fix empty workspaceId ('') → null for OAuth, form, and org routes to avoid FK violations
- Remove redundant DB queries in chat manage route (use checkChatAccess return data)
- Fix organization routes to pass workspaceId: null instead of organizationId
|
@cursor review |
|
@greptile |
apps/sim/app/api/organizations/[id]/invitations/[invitationId]/route.ts
Outdated
Show resolved
Hide resolved
…d fallback, string literal action
|
@greptile |
|
@cursor review |
Additional Comments (2)
The Consider adding a
When the fetch to The server-side enforcement in Consider either showing an error state when the fetch fails, or initializing with an empty array |
…eck, form workspaceId - Only bypass MCP domain check when env var is in hostname/authority, not path/query - Add post-resolution validateMcpDomain call in test-connection endpoint - Match client-side isDomainAllowed to same hostname-only bypass logic - Return workspaceId from checkFormAccess, use in form audit logs - Add 49 comprehensive domain-check tests covering all edge cases
|
@cursor review |
|
@greptile |
...orkspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/mcp/mcp.tsx
Outdated
Show resolved
Hide resolved
...orkspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/mcp/mcp.tsx
Show resolved
Hide resolved
- Remove /g flag from module-level ENV_VAR_PATTERN to avoid lastIndex state - Create fresh regex instances per call in server-side hasEnvVarInHostname - Fix authority extraction to terminate at /, ?, or # per RFC 3986 - Prevents bypass via https://evil.com?token={{SECRET}} (no path) - Add test cases for query-only and fragment-only env var URLs (53 total)
|
@greptile |
|
@cursor review |
…Name/Email, fix misleading action - Wrap recordAudit body in try/catch so nanoid() or header extraction can't throw - Accept string | null for actorName and actorEmail (session.user.name can be null) - Normalize null -> undefined before insert to match DB column types - Fix org members route: ORG_MEMBER_ADDED -> ORG_INVITATION_CREATED (sends invite, not adds member)
...orkspace/[workspaceId]/w/components/sidebar/components/settings-modal/components/mcp/mcp.tsx
Show resolved
Hide resolved
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
Summary
audit_logtable to Drizzle schema with indexes for workspace, actor, resource, and action queriesrecordAudit()fire-and-forget utility with type-safeAuditActionandAuditResourceTypeenumsauditMockto@sim/testingpackage and update all affected test filesType of Change
Testing
recordAudit,AuditAction, andAuditResourceTypeChecklist