Implements secure credential encryption using OpenBao Transit API with
automatic fallback to AES-256-GCM when OpenBao is unavailable.
Features:
- AppRole authentication with automatic token renewal at 50% TTL
- Transit encrypt/decrypt with 4 named keys
- Automatic fallback to CryptoService when OpenBao unavailable
- Auto-detection of ciphertext format (vault:v1: vs AES)
- Request timeout protection (5s default)
- Health indicator for monitoring
- Backward compatible with existing AES-encrypted data
Security:
- ERROR-level logging for fallback
- Proper error propagation (no silent failures)
- Request timeouts prevent hung operations
- Secure credential file reading
Migrations:
- Account encryption middleware uses VaultService
- Uses TransitKey.ACCOUNT_TOKENS for OAuth tokens
- Backward compatible with existing encrypted data
Tests: 56 tests passing (36 VaultService + 20 middleware)
Closes#353
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements secure credential storage using OpenBao Transit encryption.
Features:
- Auto-initialization on first run (1-of-1 Shamir key for dev)
- Auto-unseal on container restart with verification and retry logic
- Transit secrets engine with 4 named encryption keys
- AppRole authentication with Transit-only policy
- Localhost-only API binding for security
- Comprehensive integration test suite (22 tests, all passing)
Security:
- API bound to 127.0.0.1 (localhost only, no external access)
- Unseal verification with 3-attempt retry logic
- Sanitized error messages in tests (no secret leakage)
- Volume-based secret reading (doesn't require running container)
Files:
- docker/openbao/config.hcl: Server configuration
- docker/openbao/init.sh: Auto-init/unseal script
- docker/docker-compose.yml: OpenBao and init services
- tests/integration/openbao.test.ts: Full test coverage
- .env.example: OpenBao configuration variables
Closes#357
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements Row-Level Security (RLS) policies on accounts and sessions tables with FORCE enforcement.
Core Implementation:
- Added FORCE ROW LEVEL SECURITY to accounts and sessions tables
- Created conditional owner bypass policies (when current_user_id() IS NULL)
- Created user-scoped access policies using current_user_id() helper
- Documented PostgreSQL superuser limitation with production deployment guide
Security Features:
- Prevents cross-user data access at database level
- Defense-in-depth security layer complementing application logic
- Owner bypass allows migrations and BetterAuth operations when no RLS context
- Production requires non-superuser application role (documented in migration)
Test Coverage:
- 22 comprehensive integration tests (9 accounts + 9 sessions + 4 context)
- Complete CRUD coverage: CREATE, READ, UPDATE, DELETE (own + others)
- Superuser detection with fail-fast error message
- Verification that blocked DELETE operations preserve data
- 100% test coverage, all tests passing
Integration:
- Uses RLS context provider from #351 (runWithRlsClient, getRlsClient)
- Parameterized queries using set_config() for security
- Transaction-scoped session variables with SET LOCAL
Files Created:
- apps/api/prisma/migrations/20260207_add_auth_rls_policies/migration.sql
- apps/api/src/auth/auth-rls.integration.spec.ts
Fixes#350
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add 52 tests achieving 99.3% coverage
- Test all public methods: getLatestPipeline, getPipeline, waitForPipeline, getPipelineLogs
- Test auto-diagnosis for all failure categories
- Test pipeline parsing and status handling
- Mock ConfigService and child_process exec
- All tests passing with >85% coverage requirement met
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add CIOperationsService for Woodpecker CI integration
- Add types for pipeline status, failure diagnosis
- Add waitForPipeline with auto-diagnosis on failure
- Add getPipelineLogs for log retrieval
- Integrate CIModule into orchestrator app
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add ci-pipeline-status.sh for checking pipeline status
- Add ci-pipeline-logs.sh for fetching logs
- Add ci-pipeline-wait.sh for waiting on completion
- Update package.json bin section
- Update README with CI commands and examples
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Sanitize user-facing error messages (no raw API/DB errors)
- Remove dead try/catch from Chat.tsx handleSendMessage
- Add onError callback for persistence errors in useChat
- Add console.error logging to loadConversation
- Guard minimize/toggleMinimize against closed overlay state
- Improve error dedup bucketing for non-DOMException errors
- Add tests: non-Error throws, updateConversation failure,
minimize/toggleMinimize guards
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add sprint archival instructions so completed tasks.md files are
retained in docs/tasks/ for post-mortem reference. Includes recovery
behavior when an orchestrator finds no active tasks.md.
Archive M6-AgentOrchestration-Fixes: 88/90 done, 2 deferred.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Port high-value features from work/m4-llm branch into develop's
security-hardened codebase:
- Separate LLM vs persistence error handling in useChat (shows
assistant response even when save fails)
- Add structured error context logging with errorType, messagePreview,
messageCount fields for debugging
- Enforce state invariant in useChatOverlay: cannot be minimized when
closed
- Add onStorageError callback with user-friendly messages and
per-error-type deduplication
- Add error logging to Chat imperative handle methods
- Create Chat.test.tsx with loadConversation failure mode tests
Skipped from work/m4-llm (superseded by develop):
- AbortSignal timeout (develop has centralized client timeout)
- Custom toast system (duplicates @mosaic/ui)
- ErrorBoundary (develop has its own)
- WebSocket typed events (develop's ref-based pattern is superior)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
CQ-WEB-11: Add aria-label attributes to search input, date inputs,
and id/htmlFor associations for status and priority filter checkboxes
in FilterBar component to improve screen reader accessibility.
CQ-WEB-12: Guard all browser-specific API usage in ReactFlowEditor
behind typeof window checks. Move isDark detection into useState +
useEffect to prevent SSR/hydration mismatches.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Convert tasks, calendar, and dashboard pages from synchronous mock data
to async loading pattern with useState/useEffect. Each page now shows a
loading state via child components while data loads, and displays a
PDA-friendly amber-styled message with a retry button if loading fails.
This prepares these pages for real API integration by establishing the
async data flow pattern. Child components (TaskList, Calendar, dashboard
widgets) already handled isLoading props — now the pages actually use them.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace per-keystroke DOM element creation/removal with a persistent
off-screen mirror element stored in useRef. The mirror and cursor span
are lazily created on first use and reused for all subsequent caret
position measurements, eliminating layout thrashing. Cleanup on
component unmount removes the element from the DOM.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace exported const mockConnections with getMockConnections() function
that returns mock data only when NODE_ENV === "development". In production
and test environments, returns an empty array as defense-in-depth alongside
the existing ComingSoon page gate (SEC-WEB-4).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SEC-WEB-33: Replace raw diagram source and detailed error messages in
MermaidViewer error UI with a generic "Diagram rendering failed" message.
Detailed errors are logged to console.error for debugging only.
SEC-WEB-35: Add console.warn in useWorkspaceId when no workspace ID is
found in localStorage, making it easier to distinguish "no workspace
selected" from silent hook failure.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SEC-WEB-32: Added maxLength to form inputs (names: 100, descriptions: 500,
emails: 254) in WorkspaceSettings, TeamSettings, InviteMember components.
SEC-WEB-34: Added AbortController timeout (30s default, configurable) to
apiRequest and apiPostFormData in API client.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add runtime type validation after all JSON.parse calls in the web app to
prevent runtime crashes from corrupted or tampered storage data. Creates a
shared safeJsonParse utility with type guard functions for each data shape
(Message[], ChatOverlayState, LayoutConfigRecord). All four affected
callsites now validate parsed data and fall back to safe defaults on
mismatch.
Files changed:
- apps/web/src/lib/utils/safe-json.ts (new utility)
- apps/web/src/lib/utils/safe-json.test.ts (25 tests)
- apps/web/src/hooks/useChat.ts (deserializeMessages)
- apps/web/src/hooks/useChat.test.ts (3 new corruption tests)
- apps/web/src/hooks/useChatOverlay.ts (loadState)
- apps/web/src/hooks/useChatOverlay.test.ts (3 new corruption tests)
- apps/web/src/components/chat/ConversationSidebar.tsx (ideaToConversation)
- apps/web/src/lib/hooks/useLayout.ts (layout loading)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SEC-WEB-27: Replace weak email.includes('@') check with RFC 5322-aligned
programmatic validation (isValidEmail). Uses character-level domain label
validation to avoid ReDoS vulnerabilities from complex regex patterns.
SEC-WEB-28: Replace unsafe 'as WorkspaceMemberRole' type casts with
runtime validation (toWorkspaceMemberRole) that checks against known enum
values and falls back to MEMBER for invalid inputs. Applied in both
InviteMember.tsx and MemberList.tsx.
Adds 43 tests covering validation logic, InviteMember component, and
MemberList component behavior.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove debug console.log from workspaces page and teams page
- Fix formatTime to return "Invalid date" fallback instead of empty string
when date parsing fails (handles both thrown errors and NaN dates)
- Export formatTime and add unit tests for error handling cases
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace hardcoded BullMQ job retention values (completed: 100 jobs / 1h,
failed: 1000 jobs / 24h) with configurable env vars to prevent memory
growth under load. Adds QUEUE_COMPLETED_RETENTION_COUNT,
QUEUE_COMPLETED_RETENTION_AGE_S, QUEUE_FAILED_RETENTION_COUNT, and
QUEUE_FAILED_RETENTION_AGE_S to orchestrator config. Defaults preserve
existing behavior.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add crypto.randomBytes(4) hex suffix to container name generation
to prevent name collisions when multiple agents spawn simultaneously
within the same millisecond. Container names now include both a
timestamp and 8 random hex characters for guaranteed uniqueness.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
SEC-ORCH-28: Add connectTimeout (5000ms default) and commandTimeout
(3000ms default) to Valkey/Redis client to prevent indefinite connection
hangs. Both are configurable via VALKEY_CONNECT_TIMEOUT_MS and
VALKEY_COMMAND_TIMEOUT_MS environment variables.
SEC-ORCH-29: Add @ArrayMaxSize(50) and @MaxLength(2000) to workItems
in AgentContextDto to prevent memory exhaustion from unbounded input.
Also adds @ArrayMaxSize(20) and @MaxLength(200) to skills array.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comprehensive JSDoc and inline comments documenting the known race
condition in the in-memory fallback path of ThrottlerValkeyStorageService.
The non-atomic read-modify-write in incrementMemory() is intentionally
left without a mutex because:
- It is only the fallback path when Valkey is unavailable
- The primary Valkey path uses atomic INCR and is race-free
- Adding locking to a rarely-used degraded path adds complexity
with minimal benefit
Also adds Logger.warn calls when falling back to in-memory mode
at runtime (Redis command failures).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace all console.error calls in MCP services with NestJS Logger
instances for consistent structured logging in production.
- mcp-hub.service.ts: Add Logger instance, replace console.error in
onModuleDestroy cleanup
- stdio-transport.ts: Add Logger instance, replace console.error for
stderr output (as warn) and JSON parse failures (as error)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
createAuthMiddleware was calling SET LOCAL on the raw PrismaClient
outside of any transaction. In PostgreSQL, SET LOCAL without a
transaction acts as a session-level SET, which can leak RLS context
to subsequent requests sharing the same pooled connection, enabling
cross-tenant data access.
Wrapped the setCurrentUser call and downstream handler execution
inside a $transaction block so SET LOCAL is automatically reverted
when the transaction ends (on both success and failure).
Added comprehensive test suite for db-context module verifying:
- RLS context is set on the transaction client, not the raw client
- next() executes inside the transaction boundary
- Authentication errors prevent any transaction from starting
- Errors in downstream handlers propagate correctly
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Set forbidNonWhitelisted: true in ValidationPipe to reject requests
with unknown DTO properties, preventing mass assignment vulnerabilities
- Reject requests with no Origin header in production (SEC-API-26)
- Restrict localhost:3001 to development mode only
- Update CORS tests to cover production/development origin validation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Graceful container shutdown: detect "not running" containers and skip
force-remove escalation, only SIGKILL for genuine stop failures
- data: URI stripping: add security audit logging via NestJS Logger
when data: URIs are blocked in markdown links and images
- Orchestrator bootstrap: replace void bootstrap() with .catch() handler
for clear startup failure logging and clean process.exit(1)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Worker limits and other orchestrator settings will be configurable
via the Coordinator service with DB-centric storage.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously the catch block in searchEntries silently swallowed all
non-abort errors, showing "No entries found" when the search actually
failed. This misled users into thinking the knowledge base was empty.
- Add searchError state variable
- Set PDA-friendly error message on non-abort failures
- Clear error state on subsequent successful searches
- Render error in amber (distinct from gray "No entries found")
- Add 3 tests: error display, error clearing, abort exclusion
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
All other search DTOs (SemanticSearchBodyDto, HybridSearchBodyDto,
BrainQueryDto, BrainSearchDto) already enforce @MaxLength(500) on their
query fields. SearchQueryDto.q was missed, leaving the full-text
knowledge search endpoint accepting arbitrarily long queries.
Adds @MaxLength(500) decorator and validation test coverage.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove duplicate validateSpawnRequest from AgentsController. Validation
is now handled exclusively by:
1. ValidationPipe + DTO decorators (HTTP layer, class-validator)
2. AgentSpawnerService.validateSpawnRequest (business logic layer)
This eliminates the maintenance burden and divergence risk of having
identical validation in two places. Controller tests for the removed
duplicate validation are also removed since they are fully covered by
the service tests and DTO validation decorators.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the always-force container removal (SIGKILL) with a two-phase
approach: first attempt graceful stop (SIGTERM with configurable timeout),
then remove without force. Falls back to force remove only if the graceful
path fails. The graceful stop timeout is configurable via
orchestrator.sandbox.gracefulStopTimeoutSeconds (default: 10s).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>