Can't access Bitbucket Server through Proxy with NumberFormatException

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Problem

When access Bitbucket Server through a proxy there is an HTTP 500 error and an additional message saying

For input string: " example.net" Please see your system administrator." Note the leading whitespace on the FQDN of the host. 

The following error will appear in the atlassian-bitbucket-server.log

2016-11-17 10:30:41,489 ERROR [http-nio-7990-exec-4] bstuart @7WP2NNx630x330x0 1ab83hf :24.113.206.169,10.0.0.42 "POST /projects HTTP/1.0" c.a.s.i.w.HandlerExceptionResolverImpl For input string: " example.net"
java.lang.NumberFormatException: For input string: " example.net"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_102]
	at java.lang.Integer.parseInt(Integer.java:569) ~[na:1.8.0_102]
	at java.lang.Integer.parseInt(Integer.java:615) ~[na:1.8.0_102]
	at org.springframework.web.util.UriComponentsBuilder.adaptFromForwardedHeaders(UriComponentsBuilder.java:691) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]
	at org.springframework.web.util.WebUtils.isSameOrigin(WebUtils.java:833) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE]

 

It appears that there is a leading white space in front of the FQDN. 

Cause

X-Forwarded-Host header has bad data and your proxy configuration may look like this.

    proxy_set_header X-Forwarded-Host: $host;
    proxy_set_header X-Forwarded-Server: $host;
    proxy_set_header X-Forwarded-For: $proxy_add_x_forwarded_for;

The Spring framework will split the X-Forwarded-Host header if it has a colon and tries to parse the second part as an Integer since it expects what falls after the colon to be a port. The header is coming in as : example.net and then Spring tries to parse " example.net" as an Integer and thus you get a NumberFormatException. More information can be found at UriComponentsBuilder.java

Resolution

Remove the colons from your configuration and restart the proxy. Your configuration should look like this.

    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Server $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Last modified on Dec 2, 2016

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.