Security Audit Workflow in Cursor
Your team is three weeks from launching a SaaS product that handles customer payment data, stores personal information, and exposes a public API. The security review was supposed to happen last sprint, but it kept getting pushed. Now the compliance officer is asking for a security assessment, and your penetration testing budget is exactly zero dollars. You need a thorough audit, and you need it fast.
AI-assisted security auditing does not replace a professional pentest. But it catches a remarkable number of the common vulnerabilities — SQL injection, XSS, insecure authentication, exposed secrets, missing rate limiting — that account for the vast majority of real-world breaches. The workflow below systematically reviews your codebase for the OWASP Top 10 categories and produces a prioritized list of findings with concrete fixes.
What You’ll Walk Away With
Section titled “What You’ll Walk Away With”- A comprehensive security audit prompt that scans your codebase for OWASP Top 10 vulnerabilities
- An authentication review prompt that checks session handling, password storage, and token management
- A dependency audit workflow that finds known CVEs in your npm/pip/cargo packages
- A secrets detection prompt that catches accidentally committed API keys, tokens, and credentials
- A security fix prompt that patches vulnerabilities without breaking existing functionality
The Workflow
Section titled “The Workflow”Step 1: Run an automated dependency audit
Section titled “Step 1: Run an automated dependency audit”Start with the easiest wins — known vulnerabilities in your dependencies. This takes seconds and often finds critical issues.
Agent will run the audit command, parse the JSON output, and give you a prioritized remediation plan. Upgrade low-risk packages immediately. For breaking changes, create separate branches.
Step 2: Scan for hardcoded secrets
Section titled “Step 2: Scan for hardcoded secrets”Accidentally committed secrets are the number one security mistake in codebases. Once a secret is in git history, it is compromised permanently even if you delete the file.
Step 3: Audit authentication and authorization
Section titled “Step 3: Audit authentication and authorization”Authentication bugs are often the most severe because they let attackers impersonate legitimate users. Use Ask mode for a thorough review.
@src/auth @src/middleware @src/api
Review the authentication and authorization implementation:
1. Password handling: - Are passwords hashed with bcrypt/scrypt/argon2 (not MD5/SHA1)? - Is there a minimum password length and complexity requirement? - Is there brute force protection (rate limiting on login)?
2. Session management: - How are sessions stored (cookie, JWT, database)? - Do sessions expire? What is the timeout? - Is there a logout mechanism that actually invalidates the session? - Are session tokens regenerated after login (preventing session fixation)?
3. Authorization: - Is every API endpoint checked for authorization? - Are there endpoints that should require auth but don't? - Is there IDOR protection (can user A access user B's data by changing an ID)? - Are admin endpoints separated and protected?
4. Token handling: - Are JWTs verified with the correct algorithm (not "none")? - Is the JWT secret strong enough (at least 256 bits)? - Are refresh tokens stored securely? - Can tokens be revoked?
For each issue found, rate severity (CRITICAL, HIGH, MEDIUM, LOW) and provide the fix.Step 4: Check for injection vulnerabilities
Section titled “Step 4: Check for injection vulnerabilities”SQL injection, XSS, and command injection are still among the most exploited vulnerabilities in web applications.
Step 5: Review API security
Section titled “Step 5: Review API security”Public APIs need defense in depth — rate limiting, input validation, proper error handling, and CORS configuration.
@src/api @src/middleware
Audit API security:
1. Rate limiting: - Is there rate limiting on authentication endpoints? - Is there rate limiting on public API endpoints? - What are the limits and are they appropriate? - Can rate limits be bypassed by changing headers (X-Forwarded-For)?
2. Input validation: - Is every API endpoint validating input with a schema (Zod, Joi, etc.)? - Are file uploads validated for type, size, and content? - Are query parameters sanitized? - Are request bodies size-limited?
3. Error handling: - Do error responses leak stack traces or internal paths? - Are database errors caught and replaced with generic messages? - Is there a global error handler that prevents unhandled exceptions from leaking?
4. CORS configuration: - Is the Access-Control-Allow-Origin specific (not wildcard *)? - Are only necessary HTTP methods allowed? - Are credentials properly restricted?
5. Headers: - Is Strict-Transport-Security set? - Is X-Content-Type-Options: nosniff set? - Is X-Frame-Options set to prevent clickjacking? - Are cookies set with Secure, HttpOnly, and SameSite flags?Step 6: Implement fixes with Agent mode
Section titled “Step 6: Implement fixes with Agent mode”Once you have the prioritized list of findings, use Agent mode to implement fixes. Start with CRITICAL and HIGH severity issues.
Step 7: Set up ongoing security monitoring
Section titled “Step 7: Set up ongoing security monitoring”A one-time audit helps, but security needs continuous attention. Set up automated checks in your CI pipeline.
Set up automated security checks:
1. Add npm audit to the CI pipeline -- fail the build on HIGH/CRITICAL vulnerabilities2. Add a git pre-commit hook that scans for secrets using detect-secrets or gitleaks3. Add SAST (Static Application Security Testing) using ESLint security plugins: - eslint-plugin-security for Node.js patterns - eslint-plugin-no-unsanitized for DOM XSS4. Add a .cursor/rules/security.mdc file that instructs Cursor to: - Always use parameterized queries - Never use dangerouslySetInnerHTML without sanitization - Always validate input with Zod before processing - Never log sensitive data (passwords, tokens, PII)
Create the CI workflow step and the rule file.When This Breaks
Section titled “When This Breaks”AI misses logic vulnerabilities. Automated scanning catches pattern-based vulnerabilities (SQL injection, XSS) but struggles with business logic bugs like “user can change the price of an item by modifying the request body” or “deleting your account does not revoke your active API keys.” For logic vulnerabilities, you need manual threat modeling. Use Ask mode to brainstorm attack scenarios: “If you were an attacker trying to steal money from this checkout system, what would you try?”
False positives waste time. The AI will flag some patterns as vulnerable that are actually safe in context (e.g., a parameterized query that looks like string concatenation because of how the ORM generates it). Verify each finding before fixing it. A false positive that you “fix” might introduce a real bug.
Fixes break functionality. Security changes are notorious for breaking legitimate features. Adding CSRF protection can break API clients that do not send tokens. Setting strict CORS can block legitimate frontend requests. Always run your full test suite after security fixes, and test manually from the user’s perspective.
Dependency upgrades introduce breaking changes. Upgrading a package to fix a CVE can break your application if the new version has API changes. Pin exact versions in package.json, upgrade one dependency at a time, and run tests after each upgrade. For major version bumps, read the changelog before upgrading.
The audit creates a false sense of security. An AI scan that says “no vulnerabilities found” does not mean your application is secure. It means no known patterns were detected. Professional penetration testing, threat modeling, and security architecture review are still necessary for applications handling sensitive data.