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

NullPointerException when http header host is null #418

Merged
merged 5 commits into from
May 5, 2023

Conversation

hamadodene
Copy link
Contributor

@hamadodene hamadodene commented Mar 29, 2023

#412
As per RFC, if host header is missing or wrong the response must be 400 Bad request.
See https://www.rfc-editor.org/rfc/rfc2616#page-38
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host

the error page can be customized by setting:
default.action.badrequest=custom_action

@hamadodene hamadodene force-pushed the bug/null-http-header-host branch 4 times, most recently from 7eed82c to 6986935 Compare March 30, 2023 07:26
@hamadodene hamadodene linked an issue Mar 30, 2023 that may be closed by this pull request
@hamadodene hamadodene force-pushed the bug/null-http-header-host branch 3 times, most recently from 2b4ac25 to a8b7424 Compare March 31, 2023 11:25
@hamadodene hamadodene requested a review from pv3ntur1 March 31, 2023 13:20
Copy link
Contributor

@dmercuriali dmercuriali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nit

@@ -133,6 +133,8 @@ public Publisher<Void> processRequest(ProxyRequest request) {
return serveInternalErrorMessage(request);
case MAINTENANCE_MODE:
return serverMaintenanceMessage(request);
case BAD_REQUEST:
return serverBadRequestMessage(request);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serveBadRequestMessage

@hamadodene hamadodene requested a review from dmercuriali April 13, 2023 14:48
return requestHostname.substring(0, colonIndex);
}
} catch (NumberFormatException e) {
return "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in that case is it better to return badRequest?

Copy link
Contributor Author

@hamadodene hamadodene Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pv3nturi Fixed

@@ -171,6 +174,27 @@ public String getRequestHostname() {
return request.requestHeaders().get(HttpHeaderNames.HOST);
}

public String getHostname() {
String requestHostname = getRequestHostname();
int colonIndex = requestHostname.indexOf(":");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May this throw NPE?

Copy link
Contributor Author

@hamadodene hamadodene Apr 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pv3nturi Fixed

@hamadodene hamadodene force-pushed the bug/null-http-header-host branch 2 times, most recently from 48e300f to 55bdd0b Compare April 14, 2023 15:41
@hamadodene hamadodene requested a review from pv3ntur1 April 14, 2023 15:45
@hamadodene hamadodene force-pushed the bug/null-http-header-host branch 2 times, most recently from f070a08 to 84a17b8 Compare May 3, 2023 16:27
@hamadodene
Copy link
Contributor Author

@pv3nturi PTAL

@hamadodene hamadodene force-pushed the bug/null-http-header-host branch from 84a17b8 to 88d839c Compare May 4, 2023 14:39
@dmercuriali dmercuriali merged commit 8de1531 into master May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Carapace 1.8 > java.lang.NullPointerException
3 participants