AsyncHttpClient / async-http-client

Asynchronous Http and WebSocket Client library for Java
Other
6.29k stars 1.59k forks source link

Fixed NPE in OAuth1 implementation when one of the parameters has no value #1877

Closed Asapin closed 1 year ago

Asapin commented 1 year ago

While enabling NullAway for root org.asynchttpclient package, I noticed that DefaultRequest#getQueryParams in case of query param with no value (i.e. http://example.com/request?abc) will create Param instance with the value set to null.

But OAuthSignatureCalculatorInstance#encodedParams doesn't check for null-values when calling percentEncodeAlreadyFormUrlEncoded() resulting in NullPointerException.

I didn't change the way Param instances are created because according to this SO answer RFC 3986 doesn't specify the structure of the query string, so technically speaking http://example.com/request?abc and http://example.com/request?abc= are different URLs.

Instead I added null-check to percentEncodeAlreadyFormUrlEncoded() method because RFC 5849 The OAuth 1.0 Protocol says that query parameters should be treated the same way as application/x-www-form-urlencoded parameters as defined in HTML 4.0 Specification - a list of name=value pairs created from valid HTML elements (i.e. input, textarea, select, etc), and HTML elements input type="text" and textarea use an empty string instead of null values.

And I also tested this fix against http://lti.tools/oauth/ just in case, and both current implementation and that site produce the same result.