Security Panel MVP (#1660)
TODOs: - [x] Add documentation - [x] e2e tests: run security review, update knowledge, and fix issue - [x] more stringent risk rating <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Introduces a new Security mode with a Security Review panel that runs reviews, edits rules, parses findings via IPC, and supports fixing issues, with tests and prompt/runtime support. > > - **UI/Preview Panel**: > - Add `security` preview mode to `previewModeAtom` and ActionHeader (Shield button). > - New `SecurityPanel` showing findings table (sorted by severity), run review, fix issue flow, and edit `SECURITY_RULES.md` dialog. > - Wire into `PreviewPanel` content switch. > - **Hooks**: > - `useSecurityReview(appId)`: fetch latest review via IPC. > - `useStreamChat`: add `onSettled` callback to invoke refreshes after streams. > - **IPC/Main**: > - `security_handlers`: `get-latest-security-review` parses `<dyad-security-finding>` from latest assistant message. > - Register handler in `ipc_host`; expose channel in `preload`. > - `ipc_client`: add `getLatestSecurityReview(appId)`. > - `chat_stream_handlers`: detect `/security-review`, use dedicated system prompt, optionally append `SECURITY_RULES.md`, suppress Supabase-not-available note in this mode. > - **Prompts**: > - Add `SECURITY_REVIEW_SYSTEM_PROMPT` with structured finding output. > - **Supabase**: > - Enhance schema query to include `rls_enabled`, split policy `using_clause`/`with_check_clause`. > - **E2E Tests**: > - New `security_review.spec.ts` plus snapshots and fixture findings; update test helper for `security` mode and findings table snapshot. > - Fake LLM server streams security findings for `/security-review` and increases batch size. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 5022d01e22a2dd929a968eeba0da592e0aeece01. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
This commit is contained in:
@@ -43,6 +43,7 @@ import {
|
||||
getSupabaseClientCode,
|
||||
} from "../../supabase_admin/supabase_context";
|
||||
import { SUMMARIZE_CHAT_SYSTEM_PROMPT } from "../../prompts/summarize_chat_system_prompt";
|
||||
import { SECURITY_REVIEW_SYSTEM_PROMPT } from "../../prompts/security_review_prompt";
|
||||
import fs from "node:fs";
|
||||
import * as path from "path";
|
||||
import * as os from "os";
|
||||
@@ -578,6 +579,29 @@ ${componentSnippet}
|
||||
|
||||
systemPrompt += `\n\n# Referenced Apps\nThe user has mentioned the following apps in their prompt: ${mentionedAppsList}. Their codebases have been included in the context for your reference. When referring to these apps, you can understand their structure and code to provide better assistance, however you should NOT edit the files in these referenced apps. The referenced apps are NOT part of the current app and are READ-ONLY.`;
|
||||
}
|
||||
|
||||
const isSecurityReviewIntent =
|
||||
req.prompt.startsWith("/security-review");
|
||||
if (isSecurityReviewIntent) {
|
||||
systemPrompt = SECURITY_REVIEW_SYSTEM_PROMPT;
|
||||
try {
|
||||
const appPath = getDyadAppPath(updatedChat.app.path);
|
||||
const rulesPath = path.join(appPath, "SECURITY_RULES.md");
|
||||
let securityRules = "";
|
||||
|
||||
await fs.promises.access(rulesPath);
|
||||
securityRules = await fs.promises.readFile(rulesPath, "utf8");
|
||||
|
||||
if (securityRules && securityRules.trim().length > 0) {
|
||||
systemPrompt +=
|
||||
"\n\n# Project-specific security rules:\n" + securityRules;
|
||||
}
|
||||
} catch (error) {
|
||||
// Best-effort: if reading rules fails, continue without them
|
||||
logger.info("Failed to read security rules", error);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
updatedChat.app?.supabaseProjectId &&
|
||||
settings.supabase?.accessToken?.value
|
||||
@@ -591,7 +615,9 @@ ${componentSnippet}
|
||||
}));
|
||||
} else if (
|
||||
// Neon projects don't need Supabase.
|
||||
!updatedChat.app?.neonProjectId
|
||||
!updatedChat.app?.neonProjectId &&
|
||||
// If in security review mode, we don't need to mention supabase is available.
|
||||
!isSecurityReviewIntent
|
||||
) {
|
||||
systemPrompt += "\n\n" + SUPABASE_NOT_AVAILABLE_SYSTEM_PROMPT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user