Spring Boot /h2-console throws 403 with Spring Security 1.5.2
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If /h2-console returns 403 Forbidden in Spring Boot 1.5.2, the problem is usually not H2 itself. Spring Security is blocking the console because the endpoint is protected, the console uses frames, and POST actions inside the console can also trigger CSRF protection.
Why the H2 Console Fails
The H2 web console is a development tool exposed over HTTP. In a Spring Boot application with Spring Security enabled, three things commonly block it:
- The path is not explicitly permitted
- CSRF protection rejects the console's form submissions
- Frame headers prevent the UI from rendering
So fixing the issue usually means changing security rules in all three areas, not only adding one permitAll() matcher.
Security Configuration for Spring Boot 1.5.2
In this version line, the common setup uses WebSecurityConfigurerAdapter. A minimal development-only configuration looks like this:
Each line matters:
- '
permitAll()lets the request reach the console' - '
ignoringAntMatchers()prevents CSRF from blocking login and query actions inside the console' - '
frameOptions().sameOrigin()allows the framed UI to render'
Make Sure the Console Is Enabled
The security fix only helps if H2 console support is enabled in the application configuration:
If the path in configuration differs from the path in your security matcher, you will still get blocked.
Keep the Fix Limited to Development
Opening the H2 console broadly is convenient for local work, but it should not be treated like a production feature. A safer pattern is to enable it only for a development profile:
That keeps the console accessible for local debugging without quietly weakening every environment.
Why 403 Happens Even After permitAll()
This is the part that confuses many developers. They add a matcher and still see a broken console. That usually means the request is now authorized, but the console's form posts are still rejected by CSRF, or the browser refuses to render the frame because of the default security headers.
So if permitAll() alone does not solve it, that is expected. The H2 console is unusual because it depends on both relaxed path rules and relaxed frame handling.
Another easy check is the browser network panel. If the initial GET succeeds but a later POST fails with 403, you are dealing with CSRF. If the page loads but the frame is blocked, the response headers are the next place to inspect.
Common Pitfalls
- Permitting
/h2-console/**but forgetting to ignore CSRF for the same path. - Disabling CSRF globally when only the console needs an exception.
- Forgetting
frameOptions().sameOrigin(), which leaves the console blank or blocked in the browser. - Using a custom H2 path in properties and a different path in the security matcher.
Summary
- A
403on/h2-consolein Spring Boot 1.5.2 is usually caused by Spring Security, not by H2. - You need to permit the path, relax CSRF for that path, and allow same-origin frames.
- '
WebSecurityConfigurerAdapteris the normal place to apply the fix in this version line.' - Keep H2 console access limited to development environments.
- If
permitAll()alone does not help, check CSRF and frame headers next.
Related reading
- Spring Boot how to hide passwords in properties file
- Spring Boot How to specify the PasswordEncoder?
- Spring boot Kafka class deserialization - not in the trusted package
- Spring Boot MSSQL Kerberos Authentication
- Spring Boot Handler dispatch failed; nested exception is java.lang.NoSuchMethodError
- Spring Boot Hibernate and Flyway boot order
- Spring boot hikari - dataSource or dataSourceClassName or jdbcUrl is required issue
- Spring boot http response compression doesn't work for some User-Agents

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.