Course contentsShow
← Security
Lesson 839 of 3,05217. Web Security - Authorization and Access ControlFree lesson

Deny by Default Principles

Implement secure defaults where all access is denied unless explicitly granted through properly configured permissions.

Deny by Default Principles

What you'll learn: How to implement secure defaults that deny all access unless explicitly granted, creating a robust foundation for authorization.


What Is Deny by Default?

Deny by Default is a security principle where every resource or action starts in a locked-down state—all access is blocked unless you explicitly configure a permission to allow it. This is the opposite of "allow by default," where everything is accessible until you specifically deny something.

Think of it like a locked building: every door is locked by default, and you must have the right key (permission) to open specific doors. You don't leave all doors unlocked and try to lock the dangerous ones—that's asking for mistakes.

Why It Matters

When implementing access control (like RBAC or ABAC from earlier lessons), deny by default ensures that:

  • Forgotten permissions don't create vulnerabilities: If you forget to configure a resource, it remains inaccessible rather than open to everyone
  • New features are secure automatically: Adding a new endpoint or resource doesn't expose it until you explicitly grant access
  • Configuration errors fail safely: A typo or misconfiguration results in blocked access (annoying but safe) rather than unintended exposure

Common Implementation Patterns

Code-level defaults:

// Bad: Allow by default
if (user.role === 'admin') {
  return false; // deny admin somehow?
}
return true; // allow everything else

// Good: Deny by default
if (user.role === 'admin' || user.role === 'editor') {
  return true; // explicitly allow
}
return false; // deny everything else

Configuration approach: Start with a global deny rule, then layer on specific allow rules based on tested authorization checks.

Key Takeaway: Deny by default transforms access control from "what should I block?" to "what must I explicitly allow?"—a far more secure and maintainable approach that prevents IDOR, privilege escalation, and broken access control vulnerabilities.