Skip to content

Adding the provision of redirecting HTTP requests to HTTPS#675

Open
ShubhamGupta29 wants to merge 2 commits into
linkedin:tuning_20190221from
ShubhamGupta29:http_requests_redirection
Open

Adding the provision of redirecting HTTP requests to HTTPS#675
ShubhamGupta29 wants to merge 2 commits into
linkedin:tuning_20190221from
ShubhamGupta29:http_requests_redirection

Conversation

@ShubhamGupta29

Copy link
Copy Markdown
Contributor

DESCRIPTION
In this PR changes are done to redirect HTTP requests to HTTPS-enabled endpoints if Dr.Elephant has HTTPS enabled. This is achieved by checking the port of every request and if the port is the same as that of HTTP_PORT(defined in elephant.conf or 8080 by default) then redirect the request to the HTTPS-enabled port if exists.

HOW THESE CHANGES ARE TESTED
Tested these changes on the local and EI machines both. In this testing confirmed if the HTTPS requests are getting redirected to HTTPs endpoints or not.

@ShubhamGupta29 ShubhamGupta29 self-assigned this Apr 8, 2020
@ShubhamGupta29 ShubhamGupta29 added the security Any issue related to security of the user or service label Apr 9, 2020

@loganrosen loganrosen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for implementing this!

Comment thread app/Global.java Outdated
* @return Return the port of the of the hostAddress if exists else return INVALID_PORT
*/
private String getPortFromHostAddress(String hostAddress) {
String patterForPort = "(.+):([\\d]{1,5})";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

s/patter/pattern/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After using Guava's HostAndPort.fromString() there was no need of the method so removed the respective method.

Comment thread app/Global.java Outdated
Comment on lines +129 to +141
/**
*
* @param hostAddress The hostAddress string which will be of format "elephant.abc.com:8080"
* @return Return the port of the of the hostAddress if exists else return INVALID_PORT
*/
private String getPortFromHostAddress(String hostAddress) {
String patterForPort = "(.+):([\\d]{1,5})";
Matcher matcher = Pattern.compile(patterForPort).matcher(hostAddress);
if (matcher.find()) {
return matcher.group(2);
}
return INVALID_PORT;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You might want to consider leveraging Guava's HostAndPort.fromString() instead of manually implementing this logic. I also don't think this regular expression will work if it's a bare IPv6 address.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Big thanks Logan, I was looking for such a utility method and couldn't find it so implemented a crude one. Thanks for the review and for reporting this issue.

@saniyanajeeb saniyanajeeb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security Any issue related to security of the user or service task

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Credentials for login are passed over HTTP even if HTTPS is enabled

3 participants