💻 Coding Prompt
DeepSeek for Backend Devs: Fix Security Vulnerabilities in an API
Expert DeepSeek prompts for Backend Developers finding and fixing security vulnerabilities in production APIs
The Prompt
You are an expert API security engineer with 14 years of experience identifying and remediating security vulnerabilities in REST and GraphQL APIs for consulting firms that build and maintain production systems for regulated industry clients where an unpatched API vulnerability exposes both the consulting firm and its clients to breach liability. Help me review and harden the API so I can ship features faster on a codebase that passes security review without rework and gives the team a security baseline that accelerates approval cycles for new feature deployments.
My situation:
- API type and language: [e.g., "a REST API built in Node.js 18 with Express — the API serves a healthcare client's patient data management platform and handles PHI under HIPAA — approximately 34 endpoints across authentication, patient records, appointment scheduling, and billing"]
- Known vulnerability categories: [e.g., "the last internal security scan flagged missing rate limiting on authentication endpoints, overly permissive CORS configuration allowing any origin, JWT tokens without expiry enforcement, and one endpoint returning a full stack trace on unhandled errors"]
- Authentication and authorization model: [e.g., "JWT-based authentication with role-based access control — the roles are admin, clinician, and patient — the RBAC middleware exists but three billing endpoints were found to be missing the middleware call during last sprint's code review"]
- Dependency vulnerability status: [e.g., "npm audit shows 4 high-severity vulnerabilities in production dependencies — two in an outdated version of jsonwebtoken and two in an XML parsing library used for insurance claim exports"]
- Error handling pattern: [e.g., "unhandled errors currently bubble up to Express's default error handler which returns the full stack trace in the response body — this is consistently reproduced on four specific endpoints by passing malformed JSON"]
- Team deployment workflow: [e.g., "the team deploys via GitHub Actions to AWS ECS — there is no automated security scan in the pipeline, and security review is a manual checklist completed by the tech lead before each release"]
- Client compliance requirement: [e.g., "the healthcare client requires a signed security attestation before each production deployment — the tech lead signs the attestation manually and the process currently takes 3 hours per release"]
Deliver:
1. A vulnerability assessment report — a structured document covering the six identified vulnerability categories (missing rate limiting, overly permissive CORS, JWT expiry, RBAC middleware gaps, dependency vulnerabilities, and stack trace exposure) with a severity rating, the OWASP API Security Top 10 category each maps to, and the specific endpoint or configuration where each vulnerability is located
2. A rate limiting middleware implementation — a complete Express middleware function using express-rate-limit that applies endpoint-specific limits (authentication endpoints: 5 requests per 15 minutes per IP, general API endpoints: 100 requests per minute per authenticated user) with a standardized 429 response body and a Retry-After header
3. A CORS configuration fix — the corrected Express CORS configuration with an explicit allowlist of permitted origins, the permitted methods restricted to the minimum required, and the credentials flag set correctly for JWT-based authentication — with an explanation of why the wildcard origin is a HIPAA risk in the context of PHI data access
4. A JWT hardening specification — the corrected JWT configuration covering expiry enforcement (access token 15 minutes, refresh token 7 days), the refresh token rotation implementation, the token revocation list approach for immediate session invalidation on logout or role change, and the specific jsonwebtoken version that resolves the two high-severity CVEs
5. An RBAC middleware audit script — a Node.js script that scans all Express router files for endpoint definitions and reports any route that does not have the RBAC middleware in its middleware chain, formatted as a CI check that can be added to the GitHub Actions pipeline and fails the build if any unprotected route is detected
6. A global error handler implementation — a complete Express error handling middleware that catches all unhandled errors, logs the full stack trace to the server-side logging system (not the response), returns a standardized error response body with a request ID and a generic error message, and maps known error types (validation errors, authentication errors, authorization errors) to their correct HTTP status codes
7. A security pipeline integration brief — the GitHub Actions job definition that runs npm audit --audit-level=high on every PR and blocks merge if high-severity vulnerabilities are found, plus the OWASP ZAP baseline scan configuration that runs on staging deployment and generates the signed security attestation report the tech lead needs for each production release — reducing the 3-hour manual attestation process to a 20-minute automated report review
**Treat every vulnerability as a HIPAA breach risk rather than a code quality issue — write every implementation with the evidence trail and the configuration specificity that a HIPAA security officer would require to sign off on the remediation, and flag any item where the fix requires a client communication or a change to the signed business associate agreement.**
💡 How to use this prompt
- Write and deploy the global error handler from output item 6 before any other fix. Stack trace exposure is the only vulnerability on the list that is actively exploitable by anyone who can send a malformed request to the API — it hands an attacker the internal file structure, dependency versions, and error logic of the system. This fix is a single middleware function that can be deployed in under an hour and eliminates the highest-information-leakage vulnerability before the longer remediation items are addressed.
- The most common mistake is updating the jsonwebtoken dependency to resolve the CVEs without simultaneously enforcing JWT expiry. The CVE fix closes the library-level vulnerability, but if tokens still have no expiry, a stolen token remains valid indefinitely — the two fixes must be deployed together in the same release, or the CVE fix creates a false sense of security while the architectural vulnerability remains.
- DeepSeek handles this at a fraction of the API cost of GPT-4o or Claude. Use DeepSeek R1 with Deep Thinking mode enabled for the RBAC audit script and the JWT rotation implementation — complex stateful logic benefits from the extended reasoning. For public-facing or client-sensitive outputs containing PHI system details, review DeepSeek's data storage policy before use and consider running those outputs through Claude instead.
Best Tools for This Prompt
🤖 Best AI Coding Tools for This Prompt
Tested & reviewed — run this prompt with the best AI tools
Related Topics
About This Coding AI Prompt
This free Coding prompt is designed for DeepSeek and works with any modern AI assistant including ChatGPT, Claude, Gemini, and more. Simply copy the prompt above, paste it into your preferred AI tool, and customize the bracketed sections to fit your specific needs.
Coding prompts like this one help you get better, more consistent results from AI tools. Instead of starting from scratch every time, you can use this tested prompt as a foundation and adapt it to your workflow. Browse more Coding prompts →