Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 38 ยท Insecure Design and Misconfiguration

Insecure Design: Thinking Before Coding (A04)

Learn what insecure design means, how it differs from insecure implementation, and apply secure design patterns: abuse cases, trust limits, rate limiting, secure defaults and tiered environments.

Insecure Design (A04) was new in the 2021 list, and it makes an important point: some applications are vulnerable not because of a coding slip, but because the design never included the security control. You can write flawless code for a flawed design and still be attacked. A fence built perfectly around the wrong yard does not protect the house.

The distinction:

  • Insecure design: a missing or ineffective control. "Password reset asks three trivia questions whose answers are on the user's public profile." Perfect code cannot fix that.
  • Insecure implementation: a correct design coded wrongly. "The reset token check has an off-by-one bug."

Implementation bugs are fixed by patching. Design flaws need rethinking, and that is expensive late in a project, which is why this category is about when you think about security: before the code.

Shift left: design-time practices

  1. Collect security requirements with the functional ones. For each feature ask what must stay confidential, what must never change, and what happens if it is abused.
  2. Threat model features that touch money, identity, personal data or administration (see threat modeling).
  3. Write abuse cases next to use cases: "As an attacker I want to try many passwords quickly."
  4. Use proven patterns and components (framework authentication, vetted payment providers) instead of inventing them.
  5. Review designs, not only code, before building.
  6. Turn findings into tests so the controls remain after refactoring.

Abuse cases

A use case describes what a legitimate user wants. An abuse case describes what a malicious user wants from the same feature. Writing them takes minutes and reveals missing controls.

Feature Use case Abuse case Control to design in
Login Member signs in Try a million passwords Rate limiting, lockout, MFA
Coupons Apply a discount Reuse a one-time code Server-side usage count
Password reset Regain access Take over someone's account Short-lived single-use token, notify user
File upload Share a document Upload a huge or malicious file Size and type limits, scanning, storage outside web root
Free trial Try the product Create 1,000 accounts Verification, device and payment checks
Search Find items Scrape the whole catalog Pagination caps, throttling
Python Turn abuse cases into a design checklist

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Rate limiting: a design control

Limiting how often an action may happen defends against password guessing, scraping, abuse of expensive operations and denial of service. A common approach is a token bucket or sliding window per user, per IP address, or both.

Python A sliding-window rate limiter

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Design questions that follow: what key do you limit by (account, IP, device)? Attackers can spread attempts over many IPs, and a shared office IP can lock out innocent users, so combine limits with other signals such as MFA, CAPTCHAs on suspicious flows and alerts.

Secure design principles in practice

  • Least privilege and separation of duties. The person who creates a payment should not be the one who approves it.
  • Fail securely. If the fraud-check service is down, do you approve payments or hold them? Decide on purpose.
  • Defense in depth. Do not rely on a single check (validation at the edge, authorization in the service, constraints in the database).
  • Complete mediation. Check access on every access, not once at login.
  • Minimise trust. Services should not trust each other just because they are "internal".
  • Secure by default, usable by design. The safe path should also be the easy path.
  • Limit resource use. Cap sizes, counts, time and memory per request or user.
  • Keep environments separate. Development, test and production use different data, credentials and accounts. Real customer data never appears in test environments.

Multi-tenant designs

Applications serving many customers ("tenants") from one system need isolation designed in: every query scoped by tenant id, tenant id taken from the authenticated session, separate encryption keys for sensitive tenants, and tests that prove tenant A can never read tenant B. A missing tenant filter is both an access control bug and a design flaw if the architecture makes it easy to forget.

Security requirements example

Good security requirements are specific and testable:

  • "Passwords must be at least 12 characters and checked against a breach list."
  • "A user may attempt at most 5 logins per minute per account."
  • "Every order can only be read by its owner or by staff with the support role."
  • "Uploads are limited to 5 MB and the types png, jpg, pdf."

Compare these with vague ones such as "the system must be secure", which nobody can test.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does insecure design differ from insecure implementation?

    Perfect code cannot repair a design that lacks the necessary control.
  2. 2. What is an abuse case?

    Writing what an attacker wants from a feature reveals missing controls early.
  3. 3. Which is a testable security requirement?

    Specific, measurable requirements can be implemented and tested.
  4. 4. Why separate development and production data?

    Test environments usually have weaker controls, so they must hold only synthetic data.

Summary

  • Insecure design means the needed security control was never designed, so flawless code cannot fix it.
  • Shift security left: requirements, threat models, abuse cases and design reviews before implementation.
  • Use design controls such as rate limits, separation of duties, tenant isolation, resource caps and fail-safe behavior.
  • Write security requirements that are specific and testable and turn findings into automated tests.
  • Reuse proven patterns instead of inventing authentication or payment flows.

Next: Business Logic Flaws and Abuse Cases