0
votes

I have an angular 4 app that shows a user's information profile. The app is located in https://www.myapp.com but the user's profile picture is located in https://s3-sa-east-1.amazonaws.com/xxxx.png. The Angular app makes a Get Request to my Spring Boot Backend to obtain user profile information, but the profile image is not loaded and the browser shows me the following error:

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://s3-sa-east-1.amazonaws.com/xxxx.png with MIME type application/xml. See https://www.chromestatus.com/feature/5629709824032768 for more details.

My question is how to configure my Spring Boot App in order to prevent the Cross-Origin Read Blocking (CORB)?

Next I show the security settings of my spring application:

@Configuration
@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter {


    private UserDetailsService userDetailsService;

    private BCryptPasswordEncoder bCryptPasswordEncoder;

    public WebSecurity(UserDetailsService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) {
        this.userDetailsService = userDetailsService;
        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.cors().and().csrf().disable()
        .authorizeRequests().antMatchers(HttpMethod.POST, USER_REGISTRATION_URL).permitAll()
        .antMatchers(HttpMethod.POST, RETURN_DATA).permitAll()
        .anyRequest().authenticated()
        .and().addFilter(new JWTAuthenticationFilter(authenticationManager(), getApplicationContext()))
        .addFilter(new JWTAuthorizationFilter(authenticationManager(), getApplicationContext()))
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    }


    @Bean
    CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.addAllowedOrigin("*");
        configuration.addAllowedHeader("*");
        configuration.setAllowedMethods(Arrays.asList("GET","POST","PUT","PATCH","DELETE","OPTIONS"));
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        return source;
    }


} 

I would like to understand why this happens despite the configuration shown, it should be enough.

Many Thanks!

1

1 Answers

2
votes

The issue has nothing to do with the Spring Boot app that serves your API.

The problem is that after your Angular app receives the profile information from the Spring Boot app, it tries to load the image from your S3 bucket, and your S3 bucket is not configured for CORS. So, the browser requests the image from S3, and the request is blocked.

To fix this, you must configure your S3 bucket for CORS support. The latest info on how to do that is in Amazon's documentation at https://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html