Skip to main content
In this lesson we audit application business logic — the sequence of operations, rules, and state transitions that define how an application behaves as users interact with it. Business-logic vulnerabilities are often subtle and can enable attackers to bypass intended workflows, manipulate values, or expose sensitive information.
A presentation slide titled "Business Logic Vulnerabilities" with a dark blue curved panel on the right containing the word "Demo." The bottom left shows a small "© Copyright KodeKloud" notice.
What is business logic?
  • Business logic implements application functionality: login/logout, purchases, transfers, approvals, workflows, and the rules that guard them.
  • Small applications can still expose serious business-logic flaws (for example: user enumeration via timing differences or missing brute-force protections in a login flow).
  • When auditing, focus on where server-side enforcement is missing, where state transitions are inconsistent, or where client-supplied values are treated as authoritative.
Sample interactive prompt that appears in the project context:
Audit assistant prompts and repo Below is the auditing prompt we drop into the assistant to drive this business-logic review (trimmed for clarity):
Primary business-logic issue classes to check
  • Race conditions: concurrent request handling, double-spending prevention, inventory updates.
  • Price and value manipulation: client-side totals, coupon/discount abuse, currency tampering.
  • Workflow bypass: skipping validation steps, status manipulation, approval-flow circumvention.
  • Time-based vulnerabilities: TOCTOU (Time of Check, Time of Use), expiration bypasses, timezone issues.
  • Integer overflow/underflow: calculation errors and negative-value handling.
Table — Issue classes, what to check, and examples Common examples and short explanations
  • Double-spend / race conditions: Concurrent requests modify shared state (e.g., inventory) without suitable locking or transactional safeguards.
  • Client-side price validation: Never trust totals or prices from the client; compute and validate authoritative values server-side.
  • Workflow bypass: Ensure each step in a workflow enforces required checks and transitions; attackers can call endpoints out-of-order to override intended flow.
  • Time-based attacks: Differences between time of check and time of use may allow expiry bypasses or TOCTOU issues.
  • Integer issues: Watch for underflow/overflow in financial calculations, counters, and balances.
Always validate critical values on the server — client-side checks are for better UX only and can be bypassed by an attacker.
Example: audit output produced by the tool
Key findings (summary)
  • Risk Score: 6.5/10 — five vulnerabilities identified; rate limiting and timing attacks are top priority.
  • Top findings:
    1. Timing attack / user enumeration via measurable response-time differences.
    2. Missing rate limiting (no brute-force protection on login endpoint).
    3. Weak JWT secret present in development configuration.
    4. Error information disclosure (detailed DB errors returned).
    5. Missing account lockout / failed-attempt tracking.
Detailed example — Timing attack (user enumeration)
  • The audit flagged a measurable timing discrepancy in the authentication path. When a login attempt references a non-existent user, the code returns immediately. When a user exists, the code calls bcrypt.compare(), which adds a measurable delay (~100 ms). Attackers can distinguish valid accounts by measuring response times across many requests.
Evidence (excerpted from routes/auth.js:29-46):
Why it matters
  • Early return for non-existent users vs. bcrypt.compare() for existing users produces measurable timing differences.
  • Attackers can enumerate valid accounts by measuring average response times.
Remediation — normalize timing by always performing a password hash comparison, using a dummy hash when the account is not found:
Brute-force protection — add rate limiting
  • The login endpoint lacked rate limiting. Add express-rate-limit or a similar middleware to slow or block brute-force attempts.
Example using express-rate-limit:
Account lockout / failed-attempt tracking
  • Implement server-side counters and temporary lockouts after repeated failures. Use business-appropriate backoff and unlock mechanisms (email or admin unlock) to avoid permanent denial for legitimate users.
Weak JWT secret
  • Do not use default or development secrets in production. Generate secure secrets and fail-fast if missing.
Generate a strong secret:
Enforce JWT secret presence/strength at startup:
Error information disclosure
  • Avoid returning detailed database or stack traces to clients. Log internal details server-side and return a concise, generic error to the caller.
Example error handling pattern:
Checklist results (from the audit) Top 5 prioritized fixes
  1. Add rate limiting on authentication endpoints.
  2. Normalize authentication timing to mitigate user enumeration.
  3. Validate and require a strong JWT secret; fail startup if missing.
  4. Implement account lockout / failed-attempt tracking with safe unlock paths.
  5. Sanitize error responses to avoid leaking internal details.
Do not use development default secrets in production. Rotate weak secrets and enforce secure values in deployment pipelines.
Summary
  • Business-logic vulnerabilities can meaningfully increase application risk even in small demos.
  • In this Express login demo the primary issues were timing-based user enumeration and missing brute-force protections; both can be fixed with the code snippets above.
  • After applying fixes, re-run the audit to confirm mitigations and detect regressions.
Recommended next topic: secrets management and safe secret injection into CI/CD pipelines. Links and references

Watch Video