与 Spring 安全相关的错误 MIME 类型

Bad MIME type in connection with Spring Security

如何防止我的应用程序出现此类错误:

Refused to execute script from 'http://localhost:8091/inline.f65dd8c6e3cb256986d2.bundle.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

这是一个 Spring Boot 应用程序 Angular 4,当我 运行 第一页时它会抛出这些错误。

errors

我认为它可能与 Spring Security 有关,因为当我添加时:

.and().formLogin().loginPage("/")
                .loginProcessingUrl("/").permitAll();

它开始抛出错误,但我真的需要这段代码。整个方法看起来:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable().authorizeRequests()
            .antMatchers("/resources/static/**/*", "/", "/api/auth").permitAll()
            .anyRequest().authenticated()
            .and().formLogin().loginPage("/")
            .loginProcessingUrl("/").permitAll();
}

假设您要从 WebSecurityConfigurerAdapter 扩展安全配置 class,那么您可以使用覆盖 protected void configure(WebSecurity web) throws Exception:

@Override
protected void configure(WebSecurity web) throws Exception {
    web.ignoring()
        .antMatchers("/inline.**") // or better ending with ".{js,html}" or something
        .antMatchers("/resources/static/**/*");      
}

这将允许所有以 /inline./resources/static/... 开头的请求。