Skip to content

feat: governed analyst investigation console (#62) - #97

Merged
jusso-dev merged 4 commits into
mainfrom
feat/issue-62
Jul 28, 2026
Merged

feat: governed analyst investigation console (#62)#97
jusso-dev merged 4 commits into
mainfrom
feat/issue-62

Conversation

@jusso-dev

@jusso-dev jusso-dev commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a governed investigation console so analysts can run approved, trusted query/connector commands from case/entity/evidence context without arbitrary shell, scripts, or free-form outbound URLs.

Closes #62

Schema (migration 0036_parallel_bloodaxe)

  • investigation_executions — durable run history with redacted params, approval fields, cancel markers, result summary/storage/hash, evidence save link, entity/alert links
  • investigation_result_refs — storage key + sha256 + size for large results
  • investigation_command_favourites — per-user favourites/templates

Trusted handler registry

Command Class Notes
kelpie.previous_cases read Prior org cases sharing an observable value
virustotal.report read VT summary via fixed API paths + safeFetch; mock when unconfigured
kelpie.flag_entity_reviewed write Entity review note; dual-control approval required

Each handler declares name/version, typed Zod params, required scopes, read/write class, timeout, size/rate limits, approval policy, redaction keys, and result renderers (table | json | markdown).

Hard prohibitions

  • No shell / user scripts / eval
  • No arbitrary destination URLs (param guards + fixed handler endpoints)
  • Unknown/prohibited command names rejected

API (/api/v1/investigation/...)

  • GET commands · GET/POST executions · GET executions/:id
  • POST .../cancel · .../approve · .../reject
  • POST .../save-evidence (preserves command version, redacted params, provider request id, timestamps, hash)
  • POST .../links (entities/alerts)

Scopes: investigation:read, investigation:execute. Case context uses authorizeCase. Token scopes fail closed. Save-evidence also requires evidence:write.

Tests

npm run test:investigation-console covers schema rejection, injection/SSRF, scopes, approval, timeout/cancel, redaction, tenant isolation, and evidence save.

Test plan

  • npm run test:investigation-console (Postgres; all assertions pass)
  • npx tsc --noEmit
  • Apply 0036 on a staging DB and exercise list → execute previous_cases → save evidence
  • Approve/reject write command with a second admin user
  • Confirm empty-scope tokens cannot execute

Summary by CodeRabbit

  • New Features

    • Added a governed investigation console for discovering and running validated investigation commands.
    • Added execution history, result retrieval, cancellation, approval/rejection workflows, and case/entity/alert linking.
    • Added support for saving successful results as verifiable case evidence.
    • Added built-in commands for previous-case searches, VirusTotal reports, and entity review notes.
    • Added scoped access controls, tenant isolation, rate limits, redaction, timeout handling, and safe parameter validation.
  • Documentation

    • Documented investigation console capabilities, API endpoints, access scopes, execution states, and evidence behavior.
  • Tests

    • Added comprehensive integration coverage for validation, security controls, approvals, cancellation, timeouts, evidence, and tenant isolation.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jusso-dev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 8 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c3c3e5b4-d15b-4245-aa9a-3dcfb56e6430

📥 Commits

Reviewing files that changed from the base of the PR and between a1e90a2 and bf1fb51.

📒 Files selected for processing (26)
  • docs/api.md
  • drizzle/0038_investigation_console.sql
  • drizzle/meta/_journal.json
  • package.json
  • scripts/test-investigation-console.ts
  • src/app/api/v1/investigation/commands/route.ts
  • src/app/api/v1/investigation/executions/[id]/approve/route.ts
  • src/app/api/v1/investigation/executions/[id]/cancel/route.ts
  • src/app/api/v1/investigation/executions/[id]/links/route.ts
  • src/app/api/v1/investigation/executions/[id]/reject/route.ts
  • src/app/api/v1/investigation/executions/[id]/route.ts
  • src/app/api/v1/investigation/executions/[id]/save-evidence/route.ts
  • src/app/api/v1/investigation/executions/route.ts
  • src/db/schema.ts
  • src/lib/investigation-console/core.ts
  • src/lib/investigation-console/handlers/flag-entity-reviewed.ts
  • src/lib/investigation-console/handlers/previous-cases.ts
  • src/lib/investigation-console/handlers/virustotal-report.ts
  • src/lib/investigation-console/limits.ts
  • src/lib/investigation-console/params.ts
  • src/lib/investigation-console/redaction.ts
  • src/lib/investigation-console/registry.ts
  • src/lib/investigation-console/result-store.ts
  • src/lib/investigation-console/types.ts
  • src/lib/scopes.ts
  • src/lib/timeline.ts
📝 Walkthrough

Walkthrough

Adds a governed investigation console with typed trusted handlers, scoped execution, approval and cancellation lifecycle controls, bounded result storage, evidence linking, REST endpoints, database persistence, and integration tests.

Changes

Investigation console

Layer / File(s) Summary
Contracts and execution storage
src/lib/investigation-console/types.ts, src/db/schema.ts, drizzle/0036_parallel_bloodaxe.sql, src/lib/scopes.ts, src/lib/timeline.ts
Adds command contracts, execution states, result metadata, investigation scopes, timeline support, and persistence tables with foreign keys, indexes, and uniqueness constraints.
Registry, handlers, and result safety
src/lib/investigation-console/registry.ts, src/lib/investigation-console/params.ts, src/lib/investigation-console/redaction.ts, src/lib/investigation-console/limits.ts, src/lib/investigation-console/handlers/*, src/lib/investigation-console/result-store.ts
Registers trusted commands, validates and redacts parameters, blocks dangerous inputs, enforces rate and size limits, implements three handlers, and stores inline or external results.
Execution lifecycle and evidence operations
src/lib/investigation-console/core.ts
Adds scoped command execution, idempotency, approval and rejection, cancellation, timeout handling, history queries, evidence persistence, entity/alert linking, and public execution mapping.
REST API and documentation
src/app/api/v1/investigation/*, docs/api.md
Adds authenticated routes for command discovery, execution history, command execution, result retrieval, approval, rejection, cancellation, evidence saving, and target linking, with corresponding API documentation.
Integration validation and test wiring
scripts/test-investigation-console.ts, package.json, drizzle/meta/_journal.json
Adds database-backed integration coverage for validation, isolation, approval, cancellation, timeout, evidence, and handler behavior, plus the test script and migration journal entry.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant InvestigationAPI
  participant ExecutionCore
  participant Database
  participant Handler
  Client->>InvestigationAPI: Submit authenticated command
  InvestigationAPI->>ExecutionCore: Execute command with scopes and context
  ExecutionCore->>Database: Create or reuse execution
  ExecutionCore->>Handler: Run validated trusted handler
  Handler-->>ExecutionCore: Return structured result
  ExecutionCore->>Database: Persist status and result metadata
  ExecutionCore-->>InvestigationAPI: Return public execution
  InvestigationAPI-->>Client: Return execution response
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: a governed analyst investigation console.
Linked Issues check ✅ Passed The PR implements the governed investigation console requirements: trusted handlers, typed validation, approvals, history, evidence links, and safety controls.
Out of Scope Changes check ✅ Passed The changes stay focused on the investigation console, its API, schema, handlers, docs, and tests, with no clear unrelated additions.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/issue-62

Comment @coderabbitai help to get the list of available commands.

jusso-dev added a commit that referenced this pull request Jul 28, 2026
Close security findings on #62 / PR #97:

- previous_cases filters results with filterCasesForActor (no restricted leak)
- list executions without caseId omits rows the actor cannot know_exists
- save-evidence authorizes source case and forbids body.caseId mismatch
- approve/reject/cancel/links require authorizeCase when execution is case-bound
- write dual-control stores paramsSealed (never public); refuse approve from redacted placeholders
- idempotency unique on (organisation_id, idempotency_key)
Register investigation commands with typed params, scopes, read/write
class, timeouts, rate/size limits, redaction, and dual-control approval
for writes. Persist executions and result storage refs (0036). Expose
list/execute/history/cancel/approve/reject/save-evidence/link APIs.
Prohibits shell, scripts, and arbitrary destination URLs.

Closes #62
Close security findings on #62 / PR #97:

- previous_cases filters results with filterCasesForActor (no restricted leak)
- list executions without caseId omits rows the actor cannot know_exists
- save-evidence authorizes source case and forbids body.caseId mismatch
- approve/reject/cancel/links require authorizeCase when execution is case-bound
- write dual-control stores paramsSealed (never public); refuse approve from redacted placeholders
- idempotency unique on (organisation_id, idempotency_key)
Main already has 0036 post-incident review and 0037 investigation graph.
Fold console base schema and ACL follow-up into a single 0038 migration.
Main took 0036 for post-incident review and 0037 for investigation
graph. Emit investigation console schema (base tables, params_sealed,
org-scoped idempotency unique) as a single 0038 migration with a
correct snapshot prevId chain after rebase.
@jusso-dev
jusso-dev merged commit 20b1669 into main Jul 28, 2026
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.

[P2] Add a governed analyst investigation console for queries and connector commands

1 participant