Defensive Design, Knowledge Organiser

Knowledge Organiser: Defensive Design

Key Terms

  • Defensive design: Writing code that anticipates and handles errors, misuse, and invalid input
  • Input validation: Checking that data meets requirements before processing it
  • Input sanitisation: Removing or neutralising dangerous characters from input
  • Authentication: Verifying the identity of a user (e.g. username and password)
  • Maintainability: Writing code that is easy for others to read, understand, and update

Must-Know Facts

  • Defensive design assumes users will enter incorrect or malicious data
  • Validation checks data is acceptable; sanitisation removes dangerous content
  • Comments explain complex logic so other programmers can maintain the code
  • Meaningful variable names (e.g. customerAge not x) improve readability
  • Indentation makes code structure clear and reduces errors
  • Using subprograms and constants also improves maintainability

Key Concepts

  • Memory aid: VSCAM — Validate, Sanitise, Comments, Anticipate misuse, Maintainable
  • Limit login attempts to anticipate brute-force misuse
  • Use constants for fixed values so they are easy to update in one place
  • Sanitisation prevents SQL injection and cross-site scripting (XSS) attacks

Common Mistakes

  • Confusing validation and sanitisation: Validation checks data meets rules; sanitisation removes or neutralises dangerous characters — both are needed but do different things
  • Saying comments slow programs down: Comments are ignored by the compiler/interpreter and have no effect on execution speed — they only improve human readability
  • Using variable names like x or temp as "defensive": Meaningful variable names (e.g. customerAge) are a core feature of defensive design — vague names make code harder to maintain and debug
  • Forgetting maintainability as part of defensive design: Defensive design is not just about security — comments, indentation, and meaningful names all make code easier to maintain and update safely
  • Treating authentication as only a security issue: Authentication (verifying user identity) is also part of defensive design — it prevents unauthorised access to program features

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.