waffle icon indicating copy to clipboard operation
waffle copied to clipboard

Support basic authentication headers with ISO-1 encoding

Open dblock opened this issue 10 years ago • 1 comments

Some browsers and also Java client send basic authentication headers with ISO-1 encoding. Other browser send it with UTF-8. Here is a patch to solve this. It try first an UTF-8 encoding and if this failing then use ISO-1 encoding.

-        final String usernamePassword = new String(authorizationHeader.getTokenBytes(), Charsets.UTF_8);
+        byte[] tokenBytes = authorizationHeader.getTokenBytes();
+        String usernamePassword = new String(tokenBytes, Charsets.UTF_8);
+        if( usernamePassword.contains( "\ufffd" ) ) { 
+            // if UTF-8 converting failing use ISO_8859_1
+            // Chrome use UTF-8, Java use ISO-1, IE and FF use ISO or platform default like CP1252
+            usernamePassword = new String(tokenBytes, Charsets.ISO_8859_1);
+        }

dblock avatar Nov 29 '14 21:11 dblock

The patch above is likely incorrect, see http://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication of how to determine the encoding of the credentials.

dblock avatar Nov 29 '14 21:11 dblock