Skip to content

GrailsWebRequest.getBaseUrl() returns wrong result when "X-Forwarded-Proto" request header is present #14090

@ilPittiz

Description

@ilPittiz

Expected Behavior

No response

Actual Behaviour

WebUtils.retrieveGrailsWebRequest().getBaseUrl() does not return a consistent request base URL when:

  • X-Forwarded-Proto request header is defined
  • X-Forwarded-Port request header is not defined

Steps To Reproduce

Example:
curl -H 'X-Forwarded-Proto: https' https://my.domain.com/path

MyController.groovy

def debug() {
    println WebUtils.retrieveGrailsWebRequest().getBaseUrl()
}

Output:
https://my.domain.com:null

There's an ambiguous logical expression at

} else if (forwardedPort != null &&
("http".equals(forwardedScheme) && !"80".equals(forwardedPort)) ||
("https".equals(forwardedScheme) && !"443".equals(forwardedPort))) {
sb.append(":").append(forwardedPort);
}

where

  • forwardedScheme = "https"
  • forwardedPort = null

The if statement is in the form of A && B || C, while it should be A && (B || C), as forwardedPort is indeed null.

Environment Information

Not relevant

Example Application

No response

Version

Issue found on Grails 6.x

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions