Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WelcomePageHandlerMapping does not honor CORS #21048

Closed
kycrow32 opened this issue Apr 20, 2020 · 1 comment
Closed

WelcomePageHandlerMapping does not honor CORS #21048

kycrow32 opened this issue Apr 20, 2020 · 1 comment
Assignees
Labels
type: bug A general bug
Milestone

Comments

@kycrow32
Copy link

kycrow32 commented Apr 20, 2020

I am using spring-boot-autoconfigure version 2.2.5.RELEASE.

I have added CORS mapping in a WebMvcConfiguer in my application:

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8123")
                .allowedMethods("GET", "PUT", "POST", "DELETE")
                .allowedHeaders("*")
                .allowCredentials(true);
    }

}

This works in my test setup, when I load http://localhost/version in an iframe embedded in http://localhost:8123

This fails with a CORS error when I load http://localhost/

This fails because WelcomePageHandlerMapping has a null CorsConfigurationSource.

Bug 1:
WebMvcAutoConfiguration.welcomePageHandlerMapping() does not call WelcomePageHandlerMapping.setCorsConfigurations(getCorsConfigurations()).

WebMvcAutoConfiguration.requestMappingHandlerMapping does call this function (in super.requestMappingHandlerMapping), so for regular requests, CORS is handled correctly. welcomePageHandlerMapping() should do this as well.

Bug 2:
A workaround could involve a custom configuration, or a PostConstruct handler, or something, that called WelcomePageHandlerMapping.setCorsConfigurations().
But WelcomePageHandlerMapping is a non-public class, so there is no clean way to do this.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 20, 2020
@philwebb philwebb added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 20, 2020
@philwebb philwebb added this to the 2.1.x milestone Apr 20, 2020
@philwebb
Copy link
Member

This looks similar to the interceptors problem we fixed in 5f33643

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

3 participants