Skip to content

Commit 7c26342

Browse files
committed
chore: fix stuff
1 parent 2fbf442 commit 7c26342

20 files changed

+3160
-1979
lines changed

.claude/audit-findings.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Production Readiness Audit Findings
2+
3+
## Status: ALL HIGH-PRIORITY FIXES COMPLETE
4+
5+
## CONSOLIDATED HIGH-PRIORITY FIXES
6+
7+
### FIX-1: useAction migrations (8 instances)
8+
- vendors/secondary-fields/update-secondary-fields-form.tsx
9+
- people/[employeeId]/components/EmployeeDetails.tsx
10+
- policies/[policyId]/components/PdfViewer.tsx (x3)
11+
- settings/portal/portal-settings.tsx (x4)
12+
13+
### FIX-2: Missing credentials: 'include' (6 instances)
14+
- vendors/components/create-vendor-form.tsx
15+
- people/devices/components/PolicyImagePreview.tsx
16+
- tasks/automation/hooks/use-task-automation-execution.ts
17+
- tasks/automation/components/model-selector/use-available-models.tsx
18+
- integrations/components/PlatformIntegrations.tsx
19+
- questionnaire/hooks/useQuestionnaireParse.ts
20+
21+
### FIX-3: RBAC gaps (3 instances)
22+
- controls/[controlId]/components/ControlDeleteDialog.tsx — missing usePermissions
23+
- components/forms/risks/task/update-task-form.tsx — missing usePermissions
24+
- settings/portal/portal-settings.tsx — missing usePermissions on mutations
25+
26+
### FIX-4: @db in client components (4 SOA files)
27+
- questionnaire/soa/components/SubmitApprovalDialog.tsx
28+
- questionnaire/soa/components/SOADocumentInfo.tsx
29+
- questionnaire/soa/components/SOAPendingApprovalAlert.tsx
30+
- questionnaire/soa/components/SOAFrameworkTable.tsx
31+
32+
### FIX-5: Type safety
33+
- components/task-items/TaskItems.tsx — 2x `as any`, missing Array.isArray
34+
35+
### FIX-6: Manual role parsing (5 files)
36+
- auditor/page.tsx, layout.tsx, TeamMembersClient.tsx, MemberRow.tsx, MultiRoleCombobox.tsx
37+
38+
### DEFERRED (medium priority — DS migration + tests)
39+
- ~100+ lucide-react icon imports
40+
- ~200+ @comp/ui imports
41+
- ~57 missing test files for usePermissions components
42+
43+
---
44+
45+
## VENDORS + PEOPLE (complete)
46+
47+
### HIGH
48+
- [ ] HOOKS: `useAction` in `vendors/[vendorId]/components/secondary-fields/update-secondary-fields-form.tsx` (L13,29)
49+
- [ ] HOOKS: `useAction` in `people/[employeeId]/components/EmployeeDetails.tsx` (L22,58)
50+
- [ ] HOOKS: Missing `credentials: 'include'` in `vendors/components/create-vendor-form.tsx` (L66)
51+
- [ ] HOOKS: Missing `credentials: 'include'` in `people/devices/components/PolicyImagePreview.tsx` (L6)
52+
- [ ] HOOKS: Direct `@db` in `vendors/backup-overview/components/charts/vendors-by-status.tsx` (L2)
53+
- [ ] HOOKS: Direct `@db` in `vendors/backup-overview/components/charts/vendors-by-category.tsx` (L2)
54+
- [ ] HOOKS: Direct `@db` in `people/page.tsx` (L5)
55+
- [ ] HOOKS: Direct `@db` in `people/dashboard/components/EmployeesOverview.tsx` (L3-4)
56+
- [ ] HOOKS: Direct `@db` in `people/all/components/TeamMembers.tsx` (L6)
57+
58+
### MEDIUM
59+
- [ ] DS: 22 lucide-react icon imports across vendors + people
60+
- [ ] TESTS: Missing tests for 10 usePermissions components (VendorsTable, InherentRiskForm, ResidualRiskForm, VendorResidualRiskChart, VendorInherentRiskChart, create-vendor-task-form, VendorPageClient, DeviceDropdownMenu, EmployeeDetails)
61+
- [ ] DS: Multiple @comp/ui imports that could use DS
62+
63+
---
64+
65+
## CONTROLS + POLICIES (complete)
66+
67+
### HIGH
68+
- [ ] HOOKS: `useAction` x3 in `policies/[policyId]/components/PdfViewer.tsx` (L31,73,99,112) — getPolicyPdfUrl, upload, delete
69+
- [ ] RBAC: Manual role parsing in `policies/[policyId]/page.tsx` (L75-76) — `role.includes('employee')`
70+
- [ ] RBAC: Missing permission check on `controls/[controlId]/components/ControlDeleteDialog.tsx` (L75-76) — no usePermissions
71+
72+
### MEDIUM
73+
- [ ] DS: 11 files with lucide-react icons (controls + policies)
74+
- [ ] DS: 6+ files with @comp/ui imports (Button, Dialog, Dropdown, Badge)
75+
- [ ] DS: 3 Badge components with className that DS doesn't support
76+
- [ ] TESTS: Missing tests for 8 usePermissions components (UpdatePolicyOverview, PublishVersionDialog, PolicyPageTabs, PolicyVersionsTab, PolicyAlerts, PolicyArchiveSheet, PolicyControlMappings, PolicyDetails, PolicyDeleteDialog)
77+
## TASKS + RISK (complete)
78+
79+
### HIGH
80+
- [ ] HOOKS: Missing `credentials: 'include'` in `tasks/[taskId]/automation/[automationId]/hooks/use-task-automation-execution.ts` (L56)
81+
- [ ] HOOKS: Missing `credentials: 'include'` in `tasks/[taskId]/automation/[automationId]/components/model-selector/use-available-models.tsx` (L27)
82+
83+
### MEDIUM
84+
- [ ] TESTS: Missing tests for 6 usePermissions components (FindingsList, BrowserAutomationsList, CreateFindingSheet, SingleTask, RiskPageClient, RisksTable)
85+
- [ ] DS: 40+ lucide-react icon imports across tasks + risk
86+
- [ ] DS: 70+ @comp/ui imports that could use DS
87+
88+
### CLEAN
89+
- RBAC: All mutation elements properly gated
90+
- No useAction usage
91+
- No @db in client components (type-only)
92+
- Array.isArray checks present
93+
## FRAMEWORKS + INTEGRATIONS (complete)
94+
95+
### HIGH
96+
- [ ] HOOKS: Missing `credentials: 'include'` in `integrations/components/PlatformIntegrations.tsx` (L294)
97+
98+
### MEDIUM
99+
- [ ] DS: 11 files with lucide-react icons
100+
- [ ] TESTS: Missing tests for 3 usePermissions components (AddFrameworkModal, ToDoOverview, FrameworkDeleteDialog, PlatformIntegrations)
101+
102+
### CLEAN
103+
- RBAC: All mutation elements properly gated
104+
- No useAction, no @db in client components
105+
- No apiClient 3rd arg issues
106+
## QUESTIONNAIRE + SETTINGS (complete)
107+
108+
### HIGH
109+
- [ ] HOOKS: `useAction` x4 in `settings/portal/portal-settings.tsx` (L24,29,34,39) — deviceAgent, securityTraining, whistleblower, accessRequestForm
110+
- [ ] RBAC: Missing usePermissions on `settings/portal/portal-settings.tsx` mutations
111+
- [ ] HOOKS: Missing `credentials: 'include'` in `questionnaire/hooks/useQuestionnaireParse.ts` (L45)
112+
- [ ] HOOKS: `@db` import (non-type) in 4 client components: `questionnaire/soa/components/SubmitApprovalDialog.tsx`, `SOADocumentInfo.tsx`, `SOAPendingApprovalAlert.tsx`, `SOAFrameworkTable.tsx`
113+
114+
### MEDIUM
115+
- [ ] HOOKS: Direct `@db` in `settings/page.tsx` and `settings/portal/page.tsx` (server components, should use serverApi)
116+
- [ ] TESTS: Missing tests for 12 usePermissions components (2 questionnaire + 10 settings)
117+
- [ ] DS: 83 @comp/ui imports across questionnaire + settings
118+
- [ ] DS: 31 lucide-react icon imports
119+
- [ ] STYLE: `AdditionalDocumentsSection.tsx` exceeds 300 lines (447)
120+
## SHARED COMPONENTS + HOOKS (complete)
121+
122+
### HIGH
123+
- [ ] RBAC: Missing usePermissions on `components/forms/risks/task/update-task-form.tsx` — no permission gate on task mutation form
124+
- [ ] TYPE: 2x `as any` casts in `components/task-items/TaskItems.tsx` (L97,99)
125+
- [ ] HOOKS: Missing `Array.isArray()` on members in `components/task-items/TaskItems.tsx` (L74)
126+
127+
### MEDIUM
128+
- [ ] DS: 10 files with lucide-react icons in components/
129+
- [ ] TESTS: Missing tests for 8 usePermissions components (transfer-ownership, update-org-advanced-mode, update-org-evidence-approval, update-org-logo, create-new-policy, update-policy-form, TaskItemFocusView, TaskItemsHeader)
130+
## API ROUTES + ACTIONS (complete)
131+
132+
### HIGH
133+
- [ ] HOOKS: Missing `credentials: 'include'` in `app/api/training/certificate/route.ts` (L68)
134+
- [ ] SECURITY: `app/api/user-frameworks/route.ts` — weak string comparison for SECRET_KEY, no rate limiting
135+
- [ ] SECURITY: `app/api/frameworks/route.ts` — no authentication on GET endpoint
136+
- [ ] SECURITY: QA/Retool endpoints use plain string comparison (not timing-safe) for secrets
137+
138+
### MEDIUM
139+
- [ ] SECURITY: Hardcoded test password `Test123456!` in `auth/test-login/route.ts` (L50)
140+
- [ ] SECURITY: Test endpoints return raw error details
141+
## AUDITOR + LAYOUT + MISC (complete)
142+
143+
### HIGH
144+
- [ ] TESTS: Missing tests for 10 usePermissions components in trust portal (TrustSettingsClient, TrustPortalSwitch, TrustPortalCustomLinks, TrustPortalFaqBuilder, TrustPortalAdditionalDocumentsSection, BrandSettings, TrustPortalDomain, AllowedDomainsManager, TrustPortalOverview, TrustPortalVendors)
145+
146+
### MEDIUM
147+
- [ ] RBAC: Manual role parsing in 5 files (auditor/page.tsx, layout.tsx, TeamMembersClient.tsx, MemberRow.tsx, MultiRoleCombobox.tsx) — should centralize via permissions lib
148+
- [ ] DS: 4 files with lucide-react icons (AuditorView, TrustPortalSwitch, TrustPortalCustomLinks, AppShellRailNav)
149+
- [ ] DS: 9 files mixing @comp/ui with DS in trust portal settings
150+
- [ ] HOOKS: Server action in `trust/portal-settings/actions/check-dns-record.ts` bypasses audit logs

apps/api/.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
/dist
33
/node_modules
44
/build
5+
src/**/*.js
6+
*.Extension.js
7+
customPrismaExtension.js
8+
emailExtension.js
9+
integrationPlatformExtension.js
510

611
# Logs
712
logs
@@ -56,4 +61,6 @@ pids
5661
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
5762

5863

59-
prisma/schema.prisma
64+
prisma/schema.prisma
65+
trigger.config.js
66+
test/**/*.js

apps/api/src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { AssistantChatModule } from './assistant-chat/assistant-chat.module';
3636
import { OrgChartModule } from './org-chart/org-chart.module';
3737
import { TrainingModule } from './training/training.module';
3838
import { EvidenceFormsModule } from './evidence-forms/evidence-forms.module';
39+
import { FrameworksModule } from './frameworks/frameworks.module';
3940
import { RolesModule } from './roles/roles.module';
4041

4142
@Module({
@@ -85,6 +86,7 @@ import { RolesModule } from './roles/roles.module';
8586
TrainingModule,
8687
OrgChartModule,
8788
EvidenceFormsModule,
89+
FrameworksModule,
8890
RolesModule,
8991
],
9092
controllers: [AppController],

apps/api/src/auth/auth.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { PermissionGuard } from './permission.guard';
1515
import { RequirePermission } from './require-permission.decorator';
1616
import { AuthContext } from './auth-context.decorator';
1717
import { HybridAuthGuard } from './hybrid-auth.guard';
18+
import { SkipOrgCheck } from './skip-org-check.decorator';
1819
import type { AuthContext as AuthContextType } from './types';
1920

2021
@ApiTags('Auth')
@@ -23,6 +24,7 @@ import type { AuthContext as AuthContextType } from './types';
2324
@ApiSecurity('apikey')
2425
export class AuthController {
2526
@Get('me')
27+
@SkipOrgCheck()
2628
@ApiOperation({ summary: 'Get current user info, organizations, and pending invitations' })
2729
async getMe(@AuthContext() authContext: AuthContextType) {
2830
const userId = authContext.userId;

apps/api/src/auth/hybrid-auth.guard.ts

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@ import {
55
Logger,
66
UnauthorizedException,
77
} from '@nestjs/common';
8+
import { Reflector } from '@nestjs/core';
89
import { db } from '@trycompai/db';
910
import { ApiKeyService } from './api-key.service';
1011
import { auth } from './auth.server';
12+
import { IS_PUBLIC_KEY } from './public.decorator';
13+
import { SKIP_ORG_CHECK_KEY } from './skip-org-check.decorator';
1114
import { resolveServiceByToken } from './service-token.config';
1215
import { AuthenticatedRequest } from './types';
1316

1417
@Injectable()
1518
export class HybridAuthGuard implements CanActivate {
1619
private readonly logger = new Logger(HybridAuthGuard.name);
1720

18-
constructor(private readonly apiKeyService: ApiKeyService) {}
21+
constructor(
22+
private readonly apiKeyService: ApiKeyService,
23+
private readonly reflector: Reflector,
24+
) {}
1925

2026
async canActivate(context: ExecutionContext): Promise<boolean> {
27+
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
28+
context.getHandler(),
29+
context.getClass(),
30+
]);
31+
if (isPublic) return true;
2132
const request = context.switchToHttp().getRequest<AuthenticatedRequest>();
2233

2334
// Try API Key authentication first (for external customers)
@@ -33,7 +44,11 @@ export class HybridAuthGuard implements CanActivate {
3344
}
3445

3546
// Try session-based authentication (bearer token or cookies)
36-
return this.handleSessionAuth(request);
47+
const skipOrgCheck = this.reflector.getAllAndOverride<boolean>(SKIP_ORG_CHECK_KEY, [
48+
context.getHandler(),
49+
context.getClass(),
50+
]);
51+
return this.handleSessionAuth(request, skipOrgCheck);
3752
}
3853

3954
private async handleApiKeyAuth(
@@ -95,6 +110,7 @@ export class HybridAuthGuard implements CanActivate {
95110

96111
private async handleSessionAuth(
97112
request: AuthenticatedRequest,
113+
skipOrgCheck = false,
98114
): Promise<boolean> {
99115
try {
100116
// Build headers for better-auth SDK
@@ -132,47 +148,51 @@ export class HybridAuthGuard implements CanActivate {
132148
}
133149

134150
const organizationId = sessionData.activeOrganizationId;
135-
if (!organizationId) {
151+
if (!organizationId && !skipOrgCheck) {
136152
throw new UnauthorizedException(
137153
'No active organization. Please select an organization.',
138154
);
139155
}
140156

141157
// Fetch member data for role and department info
142-
const member = await db.member.findFirst({
143-
where: {
144-
userId: user.id,
145-
organizationId,
146-
deactivated: false,
147-
},
148-
select: {
149-
id: true,
150-
role: true,
151-
department: true,
152-
user: {
153-
select: {
154-
isPlatformAdmin: true,
158+
// Skip if no active org (e.g., /auth/me during onboarding)
159+
let userRoles: string[] | null = null;
160+
if (organizationId) {
161+
const member = await db.member.findFirst({
162+
where: {
163+
userId: user.id,
164+
organizationId,
165+
deactivated: false,
166+
},
167+
select: {
168+
id: true,
169+
role: true,
170+
department: true,
171+
user: {
172+
select: {
173+
isPlatformAdmin: true,
174+
},
155175
},
156176
},
157-
},
158-
});
159-
160-
if (!member) {
161-
throw new UnauthorizedException(
162-
`User is not a member of the active organization`,
163-
);
177+
});
178+
179+
if (!member) {
180+
throw new UnauthorizedException(
181+
`User is not a member of the active organization`,
182+
);
183+
}
184+
185+
userRoles = member.role ? member.role.split(',') : null;
186+
request.memberId = member.id;
187+
request.memberDepartment = member.department;
188+
request.isPlatformAdmin = member.user?.isPlatformAdmin ?? false;
164189
}
165190

166-
const userRoles = member.role ? member.role.split(',') : null;
167-
168191
// Set request context for session auth
169192
request.userId = user.id;
170193
request.userEmail = user.email;
171194
request.userRoles = userRoles;
172-
request.memberId = member.id;
173-
request.memberDepartment = member.department;
174-
request.isPlatformAdmin = member.user?.isPlatformAdmin ?? false;
175-
request.organizationId = organizationId;
195+
request.organizationId = organizationId ?? '';
176196
request.authType = 'session';
177197
request.isApiKey = false;
178198

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { SetMetadata } from '@nestjs/common';
2+
3+
export const IS_PUBLIC_KEY = 'isPublic';
4+
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { SetMetadata } from '@nestjs/common';
2+
3+
export const SKIP_ORG_CHECK_KEY = 'skipOrgCheck';
4+
export const SkipOrgCheck = () => SetMetadata(SKIP_ORG_CHECK_KEY, true);

apps/api/src/browserbase/browserbase.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Injectable, Logger } from '@nestjs/common';
22
import Browserbase from '@browserbasehq/sdk';
3-
import { Stagehand } from '@browserbasehq/stagehand';
3+
// Lazy-imported in createStagehand() to avoid Node v25 crash
4+
// (SlowBuffer.prototype was removed — @browserbasehq/stagehand bundles buffer-equal-constant-time which uses it)
5+
type Stagehand = import('@browserbasehq/stagehand').Stagehand;
46
import { db } from '@trycompai/db';
57
import { z } from 'zod';
68
import {
@@ -196,6 +198,7 @@ export class BrowserbaseService {
196198
// ===== Stagehand helpers =====
197199

198200
private async createStagehand(sessionId: string): Promise<Stagehand> {
201+
const { Stagehand } = await import('@browserbasehq/stagehand');
199202
const stagehand = new Stagehand({
200203
env: 'BROWSERBASE',
201204
apiKey: process.env.BROWSERBASE_API_KEY,

apps/api/src/evidence-forms/evidence-forms.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ type MockDb = {
4646
describe('EvidenceFormsService', () => {
4747
const authContext: AuthContext = {
4848
organizationId: 'org_123',
49-
authType: 'jwt',
50-
isApiKey: false,
49+
authType: 'session',
50+
isApiKey: false, isPlatformAdmin: false,
5151
userRoles: ['admin'],
5252
userId: 'usr_reviewer',
5353
userEmail: 'reviewer@example.com',

apps/api/src/findings/findings.controller.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ import { FindingsController } from './findings.controller';
5353
describe('FindingsController', () => {
5454
const authContext: AuthContext = {
5555
organizationId: 'org_123',
56-
authType: 'jwt',
57-
isApiKey: false,
56+
authType: 'session',
57+
isApiKey: false, isPlatformAdmin: false,
5858
userRoles: ['admin'],
5959
userId: 'usr_123',
6060
userEmail: 'admin@example.com',

0 commit comments

Comments
 (0)