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

Don't fail on invalid HTTP request targets #49

Merged
merged 2 commits into from
Feb 23, 2016

Conversation

twz123
Copy link
Contributor

@twz123 twz123 commented Feb 22, 2016

Problem:
When broken or malicious clients issue HTTP requests with invalid request targets (e.g. wrongly escaped query parameters) in the HTTP Request Line, logbook fails by throwing a IllegalArgumentException/URISyntaxException. This results in unlogged HTTP requests and most probably in 500 Internal Server Error responses from HTTP backends.

Proposed fix:
Don't use java.net.URI as return type of BaseHttpRequest::getRequestUri, but a plain String. Implementation was straight forward, with one exception: Query Parameter Obfuscation. If the request URI is malformed, query parameters cannot be extracted in the usual way in order to apply the Obfuscator to them. Currently, malformed URIs are then forwarded as-is. This may not be desirable. What do you think?

…ng in order to support logging of malformed URLs that may be requested by broken or malicious HTTP clients
@@ -45,6 +45,20 @@
(contentType, body) -> body.replace("s3cr3t", "f4k3"));

@Test
public void shouldNotFailOnInvalidUri() {
final String invalidUri = "/af.cgi?_browser_out=.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2Fetc%2Fpasswd";
Copy link
Collaborator

Choose a reason for hiding this comment

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

oO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, seen in the wild by one of our services, along with a dozen similar
URIs, all leading 500s b/c of an IAE in URI.create.
Am 22.02.2016 12:32 schrieb "Willi Schönborn" notifications@github.com:

In
logbook-core/src/test/java/org/zalando/logbook/ObfuscatedHttpRequestTest.java
#49 (comment):

@@ -45,6 +45,20 @@
(contentType, body) -> body.replace("s3cr3t", "f4k3"));

 @Test
  • public void shouldNotFailOnInvalidUri() {
  •    final String invalidUri = "/af.cgi?_browser_out=.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2F.|.%2Fetc%2Fpasswd";
    

oO


Reply to this email directly or view it on GitHub
https://github.com/zalando/logbook/pull/49/files#r53613418.

@whiskeysierra
Copy link
Collaborator

Thanks for the pull request!

Implementation was straight forward, with one exception: Query Parameter Obfuscation. If the request URI is malformed, query parameters cannot be extracted in the usual way in order to apply the Obfuscator to them. Currently, malformed URIs are then forwarded as-is. This may not be desirable. What do you think?

That's a tough decision actually. I think the current approach is the best compromise, let's see what the others are saying.

@lukasniemeier-zalando
Copy link
Member

👍

What would be the alternative? If we cannot parse the URI obfuscate it completely?

@whiskeysierra
Copy link
Collaborator

Yes. I'd assume since we can't read the parameters from the URI we can't obfuscate it partially, which would be the default strategy. So we are left with:

  1. No obfuscation
  2. Complete obfuscation

@twz123
Copy link
Contributor Author

twz123 commented Feb 22, 2016

A complete obfuscation would make it impossible to analyze a possible attack, or broken client on the server side.

Another approach could be to try to parse the URL manually, in a more lenient way? A quick internet seach brought up for example OkHttp’s New URL Class: https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/HttpUrl.java.

@twz123
Copy link
Contributor Author

twz123 commented Feb 22, 2016

We could also go for a dumb approach like this: twz123/logbook@757a56a

@jhorstmann
Copy link
Contributor

I would actually prefer to not touch or try to parse the incoming url at all, instead to log it exactly as it was on the wire. This would mean changing the obfuscator though, probably to be based on regular expressions.

@whiskeysierra
Copy link
Collaborator

Sounds good to me, but that implies that we need to change the obfuscation
API as well, doesn't it?
On 22 Feb 2016 16:32, "Jörn Horstmann" notifications@github.com wrote:

I would actually prefer to not touch or try to parse the incoming url at
all, instead to log it exactly as it was on the wire. This would mean
changing the obfuscator though, probably to be based on regular expressions.


Reply to this email directly or view it on GitHub
#49 (comment).

@twz123
Copy link
Contributor Author

twz123 commented Feb 23, 2016

While a better solution is being discussed, do you think this intermediary solution is good enough to be merged, so that we can get a new release that doesn't fail on invalid URLs?

@whiskeysierra
Copy link
Collaborator

While a better solution is being discussed, do you think this intermediary solution is good enough to be merged, so that we can get a new release that doesn't fail on invalid URLs?

I agree. The proposed solution is a step in the right direction, I think. For any further thoughts/plans/investigations we should open another issue.

Can someone else please approve with a 👍 so we can get this through?

@lukasniemeier-zalando
Copy link
Member

👍

whiskeysierra added a commit that referenced this pull request Feb 23, 2016
Don't fail on invalid HTTP request targets
@whiskeysierra whiskeysierra merged commit 0e5269e into zalando:master Feb 23, 2016
@whiskeysierra
Copy link
Collaborator

@twz123 I deployed 0.13.0 to central.

@whiskeysierra
Copy link
Collaborator

I created a followup issue #50

@twz123
Copy link
Contributor Author

twz123 commented Feb 23, 2016

@whiskeysierra Perfect, thanks!

@twz123 twz123 deleted the support-invalid-urls branch February 23, 2016 10:37
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.

4 participants