How to Fix Insecure Direct Object References (IDOR) in Spring Boot
Learn how to prevent and fix Insecure Direct Object References (IDOR) vulnerabilities in Spring Boot applications. Step-by-step guide with code examples, security checklists, and best practices.
What Is Insecure Direct Object References (IDOR)?
Insecure Direct Object References (IDOR) is an access control vulnerability where an application uses user-supplied input to directly access objects (like database records, files, or API resources) without verifying the user's authorization to access that specific object. The vulnerability occurs when internal identifiers such as database IDs, filenames, or sequential numbers are exposed in URLs, form fields, or API parameters.
For example, if a user can view their invoice at `/api/invoices/1234` and simply changing the ID to `/api/invoices/1235` reveals another user's invoice, that is an IDOR vulnerability. The application checked that the user was authenticated but failed to verify that the specific invoice belongs to that user.
IDOR is extremely common in modern web applications, particularly those with RESTful APIs where resource identifiers are part of the URL path. It is often introduced when developers focus on authentication (is the user logged in?) but neglect authorization (is this user allowed to access this specific resource?). Even applications using UUIDs instead of sequential integers can be vulnerable if the UUIDs are leaked or predictable.
Why It Matters
IDOR vulnerabilities can expose sensitive data belonging to other users, including personal information, financial records, private messages, and documents. Because IDOR exploits are simple (often just changing a number in a URL), they are frequently discovered by unsophisticated attackers or automated scanners. The impact scales with the sensitivity of the exposed data and the number of affected records. In multi-tenant SaaS applications, IDOR can allow one customer to access another customer's data, leading to severe trust and compliance issues. IDOR was a factor in several major data breaches, including the 2019 First American Financial breach that exposed 885 million records.
How to Fix It in Spring Boot
Implement proper authorization checks for every data access operation. Never rely solely on authentication -- verify that the authenticated user has permission to access the specific requested resource. In database queries, always filter by the current user's ID or organization (e.g., `WHERE user_id = :currentUser AND id = :requestedId`). Use Supabase Row Level Security (RLS) policies or similar database-level access controls. Replace sequential IDs with UUIDs in public-facing interfaces to reduce enumeration risk (but still verify authorization). Implement access control at the service layer, not just the controller layer. Conduct authorization testing as part of your security review process.
Spring Boot-Specific Advice
- Use Spring Security for authentication and authorization. Configure it properly -- the default configuration may be too permissive or too restrictive.
- Use JPA/Hibernate with parameterized queries. Avoid `@Query` with string concatenation and native queries with user input.
- Spring Security includes CSRF protection by default for server-rendered forms. Keep it enabled for session-based authentication.
- Use `@Valid` and Bean Validation annotations (`@NotNull`, `@Size`, `@Pattern`) on request DTOs for input validation.
Spring Boot Security Checklist for Insecure Direct Object References (IDOR)
Spring Boot Security Best Practices
Use Spring Security for authentication and authorization. Configure it properly -- the default configuration may be too permissive or too restrictive.
Use JPA/Hibernate with parameterized queries. Avoid `@Query` with string concatenation and native queries with user input.
Spring Security includes CSRF protection by default for server-rendered forms. Keep it enabled for session-based authentication.
Use `@Valid` and Bean Validation annotations (`@NotNull`, `@Size`, `@Pattern`) on request DTOs for input validation.
Disable Spring Boot Actuator endpoints in production or protect them with authentication. Actuator can expose sensitive internals.
Use Spring Security's password encoder (BCryptPasswordEncoder) for password hashing. Never use MD5 or SHA for passwords.
Configure CORS using `@CrossOrigin` annotations or `WebMvcConfigurer` with explicit allowed origins.
Use `spring-boot-starter-security` and configure `SecurityFilterChain` with method-level security (`@PreAuthorize`) for fine-grained access control.
Scan Your Spring Boot App with SafeVibe
Stop guessing if your Spring Boot app is vulnerable to Insecure Direct Object References (IDOR). Run an automated penetration test in minutes and get actionable results.
Start Free Scan