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

Redirect to 8443 if using SSL on the 8080 port #8140

Closed
dtitov opened this issue Mar 18, 2020 · 7 comments
Closed

Redirect to 8443 if using SSL on the 8080 port #8140

dtitov opened this issue Mar 18, 2020 · 7 comments
Assignees
Labels
status: invalid An issue that we don't feel is valid

Comments

@dtitov
Copy link

dtitov commented Mar 18, 2020

Summary

I came here from this issue: spring-projects/spring-boot#6140

I have a problem that is described in comments there: I have configured the web-app to run on 8080 port (basically, the default one), but using SSL. Then, when I plug in Spring Security and try to use OAuth2, it redirects me to 8443 port.

Actual Behavior

The protected endpoint redirects to 8443.

Expected Behavior

The protected endpoint keeps 8080 port.

Configuration

server:
  ssl:
    key-store-type: PKCS12
    key-store: file:${SERVER_KEYSTORE_PATH}
    key-store-password: ${SERVER_CERT_PASSWORD}
  port: 8080

Version

2.2.0.RELEASE

Sample

This is not my code, but one guy from the issue above created a minimal reproducible example for this issue: https://github.com/barrycommins/spring-boot-ssl-redirect-bug

As far as I understand, this issue is somehow related to some IE bug. I wonder if it's still even the case? The issue seems to be quite old (2016 year). It might be that this bug is gone in the recent versions of IE (and there's no point to support the old versions because even Microsoft doesn't support them).

Anyway, I believe that this strange workaround that was made with the PortResolverImpl should be removed, because the attempt to fix some IE bug (basically, some client-originated misbehavior) breaks the normal behavior of the back-end, which looks ridiculous to me...

@rwinch
Copy link
Member

rwinch commented Mar 18, 2020

This is expected Please see spring-projects/spring-boot#6140 (comment)

@rwinch rwinch added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 18, 2020
@rwinch rwinch closed this as completed Mar 18, 2020
@rwinch rwinch self-assigned this Mar 18, 2020
@dtitov
Copy link
Author

dtitov commented Mar 18, 2020

@rwinch, sorry, but did you even read my message? I came from that issue and I read all the comments there. I realize that you think (or some other developers) that this is the expected behavior. However, I (and, obviously not only me) disagree. I'm convinced that the backend system shouldn't fix the frontend bug.

Even if you insist, IMHO, there must be provided a workaround (in order to disable your workaround for IE bug) for those people who don't care about IE and want to have their TLS-terminated application working on 8080 port.

@rwinch
Copy link
Member

rwinch commented Mar 19, 2020

You can configure the PortResolver that is used by the AuthenticationEntryPoint.

@Override
protected void configure(HttpSecurity http) throws Exception {
	PortMapperImpl portMapper = new PortMapperImpl();
	portMapper.setPortMappings(Collections.singletonMap("80","443"));
	PortResolverImpl portResolver = new PortResolverImpl();
	portResolver.setPortMapper(portMapper);
	LoginUrlAuthenticationEntryPoint entryPoint = new LoginUrlAuthenticationEntryPoint(
			"/login");
	entryPoint.setPortMapper(portMapper);
	entryPoint.setPortResolver(portResolver);
	http
		.exceptionHandling()
			.authenticationEntryPoint(entryPoint)
			.and()
		//...
		;
}

@dtitov
Copy link
Author

dtitov commented Mar 19, 2020

Thanks, this helped. However, I still think that the necessity to do portMapper.setPortMappings(Collections.singletonMap("8080", "8080")) looks quite weird. But, anyway, it works...

@theshoeshiner
Copy link

theshoeshiner commented Apr 13, 2021

Does anyone have a recommended workaround for this when using a SAMLEntryPoint? That class has no internal port mapper or resolver, but It appears that the mapper and resolver on the HttpSessionRequestCache are causing the same 8080 -> 8443 issue, and I don't see any way to override those.

It looks like the relevant field is:
org.springframework.security.web.access.ExceptionTranslationFilter.requestCache

That cache has an internal port resolver, which would need to be overridden. However I can't figure out exactly where I can control that.

@sathishkumar294
Copy link

@theshoeshiner I faced the same issue with the HttpSessionRequestCache using its own portResolver to forward my requests from TLS enabled to 8080 to non-existant 8443. I fixed it for the moment using this code:

HttpSessionRequestCache cache = new HttpSessionRequestCache();
cache.setPortResolver(portResolver);
httpSecurity.setSharedObject(RequestCache.class, cache);

where portResolver was created using the steps given by @rwinch above

@mkpaz
Copy link

mkpaz commented Aug 17, 2023

IE is long dead. I'm surprised this is still an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

6 participants