About Spring Security to let, control and get access to the h2 web console
I read these two posts:
- Spring Boot /h2-console throws 403 with Spring Security 1.5.2
- H2 console and Spring Security - permitAll() not working
In conclusion is mandatory use the following ("improved" in someway):
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.mvcMatchers("/admin/**").hasRole("ADMIN")
...
.mvcMatchers("/h2-console/**").hasRole("ADMIN")
.and()
.csrf().ignoringAntMatchers("/h2-console/**")
.and()
.headers().frameOptions().disable()
.and()
From above is better use .csrf().ignoringAntMatchers("/h2-console/**") instead of csrf().disable() it for security reasons because the disable point applies only to /h2-console/, the latter is global and is not recommended.
Until here I am fine. And I am able to see the H2 web console once the login process happened and the user has the required role.
Now is mandatory use .headers().frameOptions().disable(), if is not used happens the following:
The localhost refused to connect message appears to any inner block when the mouse's cursor is over any of them
My doubts are:
- How does
.headers().frameOptions().disable()work? - Is safe to use that sentence for Production Environment? Consider the difference between
.csrf().ignoringAntMatchers("/h2-console/**")andcsrf().disable(), where the former is specific and the latter is "global" (and is not recommended). Therefore perhaps would be available a specific configuration much better than.headers().frameOptions().disable()(at a first glance for me is a "global" configuration) to only apply to/h2-console/ - Could
.headers().frameOptions().disable()have any negative effect, directly or indirectly, for otherconfigure(HttpSecurity http)configuration? (Mostly for Production)

