Ortem Technologies
    Cybersecurity

    Backend Security Best Practices: Protecting APIs and Databases in 2026

    Praveen JhaMarch 12, 202613 min read
    Backend Security Best Practices: Protecting APIs and Databases in 2026
    Quick Answer

    The most critical backend security practices: (1) never store secrets in code — use environment variables and a secrets manager (AWS Secrets Manager, HashiCorp Vault); (2) validate and sanitise all input; (3) use parameterised queries to prevent SQL injection; (4) implement rate limiting on all public endpoints; (5) use short-lived JWTs with refresh token rotation; (6) enforce HTTPS everywhere; (7) run dependency audits weekly (npm audit, Snyk); (8) implement the OWASP Top 10 checklist before launch. Most breaches exploit basic hygiene failures, not sophisticated exploits.

    Commercial Expertise

    Need help with Cybersecurity?

    Ortem deploys dedicated Cybersecurity Solutions squads in 72 hours.

    Secure Your App

    OWASP Top 10 for Backend Developers (2026)

    The OWASP Top 10 represents the most critical web application security risks. Most real-world breaches exploit one of these:

    1. Broken Access Control — Users accessing resources they should not
    2. Cryptographic Failures — Sensitive data exposed due to weak encryption or no encryption
    3. Injection — SQL, NoSQL, command injection via unsanitised input
    4. Insecure Design — Missing security requirements at the design phase
    5. Security Misconfiguration — Default credentials, verbose error messages, open S3 buckets
    6. Vulnerable and Outdated Components — Dependencies with known CVEs
    7. Identification and Authentication Failures — Weak passwords, no MFA, session issues
    8. Software and Data Integrity Failures — Unverified updates, insecure CI/CD
    9. Security Logging and Monitoring Failures — Attacks not detected
    10. Server-Side Request Forgery (SSRF) — Server making requests to unintended locations

    Authentication and Authorisation

    JWT Best Practices

    • Short expiry for access tokens (15–60 minutes)
    • Long-lived refresh tokens stored in httpOnly cookies (not localStorage)
    • Rotate refresh tokens on every use
    • Include only necessary claims in JWT payload (no sensitive data)
    • Verify token signature on every request — never trust unverified claims

    Password Storage

    Never store passwords in plain text or with reversible encryption. Use bcrypt, Argon2, or scrypt with appropriate work factors:

    // Node.js with bcrypt
    const hash = await bcrypt.hash(password, 12); // cost factor 12
    const isValid = await bcrypt.compare(input, hash);
    

    Role-Based Access Control (RBAC)

    Implement access checks at the service layer, not just the route layer. Assume every request is potentially malicious:

    // Check ownership, not just authentication
    if (resource.userId !== req.user.id && req.user.role !== 'admin') {
      throw new ForbiddenError();
    }
    

    Preventing Injection Attacks

    SQL Injection — Parameterised Queries

    // VULNERABLE — never do this
    const query = `SELECT * FROM users WHERE email = '${email}'`;
    
    // SAFE — always use parameterised queries
    const user = await db.query('SELECT * FROM users WHERE email = $1', [email]);
    

    Modern ORMs (Prisma, TypeORM, SQLAlchemy) use parameterised queries by default. Raw query interfaces still require explicit parameterisation.

    Input Validation

    Validate all input at the boundary of your application. Use schema validation libraries:

    • Node.js: Zod, Joi, Yup
    • Python: Pydantic, Marshmallow

    Never trust: query parameters, request bodies, headers, cookies, path parameters, or file uploads.

    Rate Limiting

    Protect all public endpoints from abuse and brute force:

    // Express with express-rate-limit
    const limiter = rateLimit({
      windowMs: 15 * 60 * 1000, // 15 minutes
      max: 100, // 100 requests per window
      standardHeaders: true,
    });
    app.use('/api/', limiter);
    
    // Stricter limits for auth endpoints
    const authLimiter = rateLimit({ windowMs: 60 * 60 * 1000, max: 10 });
    app.use('/api/auth/', authLimiter);
    

    Secret Management

    Never commit secrets to version control. Not once, ever.

    For local development: Use .env files (add .env to .gitignore immediately) For production: Use a secrets manager:

    • AWS Secrets Manager / Parameter Store
    • HashiCorp Vault
    • GCP Secret Manager
    • Azure Key Vault

    Rotate secrets regularly. Revoke immediately if exposed.

    Dependency Security

    Run weekly automated dependency audits:

    npm audit --audit-level=high
    # or
    npx snyk test
    

    Enable Dependabot or Renovate to auto-create PRs for security patches. A dependency with a known CVE is a ticking clock.

    Security Headers

    Set security headers on all HTTP responses:

    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Content-Type-Options: nosniff
    X-Frame-Options: DENY
    Content-Security-Policy: default-src 'self'
    Referrer-Policy: strict-origin-when-cross-origin
    

    Use helmet middleware in Express to set these in one line.

    Logging and Monitoring

    Log all authentication events (login, logout, failed attempts, password reset) and all access to sensitive resources. Do not log sensitive data (passwords, tokens, card numbers). Use structured logging and ship logs to a centralised SIEM (Datadog, Splunk, AWS CloudWatch).

    Need a security review of your backend? Talk to our cybersecurity team → or contact us to schedule a security audit.

    📬

    Get the Ortem Tech Digest

    Monthly insights on AI, mobile, and software strategy - straight to your inbox. No spam, ever.

    Backend SecurityAPI SecurityDatabase SecurityOWASPCybersecurity Best Practices

    About the Author

    P
    Praveen Jha

    Director – AI Product Strategy, Development, Sales & Business Development, Ortem Technologies

    Praveen Jha is the Director of AI Product Strategy, Development, Sales & Business Development at Ortem Technologies. With deep expertise in technology consulting and enterprise sales, he helps businesses identify the right digital transformation strategies - from mobile and AI solutions to cloud-native platforms. He writes about technology adoption, business growth, and building software partnerships that deliver real ROI.

    Business DevelopmentTechnology ConsultingDigital Transformation
    LinkedIn

    Stay Ahead

    Get engineering insights in your inbox

    Practical guides on software development, AI, and cloud. No fluff — published when it's worth your time.

    Ready to Start Your Project?

    Let Ortem Technologies help you build innovative solutions for your business.