Authorization Bugs Overview
Authorization bugs are among the most dangerous security vulnerabilities. They allow users to access data or perform actions they should not.
Common Authorization Bugs
- Broken Object Level Authorization (BOLA) - User A can access User B data by changing an ID
- Broken Function Level Authorization - Regular user accesses admin endpoints
- Missing Authorization - No permission check at all
- Excessive Data Exposure - API returns more data than user should see
Real-World Impact
| Bug Type | Impact |
|---|---|
| BOLA | Data breach, privacy violation |
| Broken Function Auth | Privilege escalation |
| Missing Auth | Complete data exposure |
Prevention Strategies
- Always check permissions before returning data
- Use consistent authorization middleware across all endpoints
- Test with multiple user roles during development
- Apply principle of least privilege
Defense Patterns
Authorization Check Examples
Always verify object ownership server-side:
- Check that the authenticated user owns the resource
- Use authorization annotations like @PreAuthorize
- Never rely on client-side checks alone
Testing Authorization
Test Matrix:
Endpoint | Owner | Other | Admin
GET /order | Allow | Deny | Allow
PUT /order | Allow | Deny | Deny
DELETE | Allow | Deny | Allow
Key Principles
- Deny by default - require explicit permission
- Check on every request - never cache auth decisions
- Validate server-side - client-side checks are bypassable
- Log all denials - for security auditing
Practice Problems
Design and implement a solution for Authorization Bugs in a backend system. Consider scalability, error handling, and production readiness.
Solution
// Authorization Bugs implementation
// Key aspects: validation, error handling, logging, testing
public class AuthorizationBugs {
// Production-ready implementation
} Identify and handle edge cases for Authorization Bugs. What happens under high load, with invalid input, or during failures?
Solution
// Edge case handling:
// 1. Null/empty input -> validation
// 2. High load -> rate limiting, queuing
// 3. Failures -> retries, circuit breaker
// 4. Concurrent access -> locks, idempotency Write a testing strategy for Authorization Bugs. Include unit tests, integration tests, and performance tests.
Solution
// Test plan:
// - Unit: 80% coverage target
// - Integration: API contracts
// - Performance: latency, throughput
// - Chaos: failure injection Quiz
1. What is BOLA?
2. How to prevent authorization bugs?
3. What is a common mistake when implementing Authorization Bugs?
Flashcards
Question
What is BOLA?
Click to reveal answer
Answer
Broken Object Level Authorization - accessing others data via ID manipulation
Question
How to prevent auth bugs?
Click to reveal answer
Answer
Deny by default, check every request, validate server-side
Question
Authorization Bugs best practices
Click to reveal answer
Answer
Follow SOLID principles, write clean code, test thoroughly, document decisions, and monitor in production.
Revision Notes
Key Takeaways
- 1. BOLA is the most common API security vulnerability
- 2. Always check object ownership before returning data
- 3. Use deny-by-default policy
- 4. Test authorization with multiple user roles
Interview Tips
- • Explain how you would test for BOLA
- • Discuss the difference between authentication and authorization
Cheat Sheet
Authorization Bugs
- BOLA: Access others data via ID manipulation
- Prevention: Deny by default, check every request
- Testing: Matrix of users x endpoints
- Logging: Record all denials for audit