-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Basic Auth is broken when using non-ASCII characters #2456
Comments
Yeah, looks like there's an issue with the character encoding. |
Looks like swagger-ui uses btoa to encode to base64. The native browser btoa function treats every input character as a byte with the same number, and throws for any character outside of the range 0–255 (which maps to ISO-8859-1). However swagger-ui supplies its own implementation of btoa that silently takes the lowest 8 bits of each code point and discards the rest, resulting in the mangled If you wanted to send credentials in UTF-8 instead of ISO-8859-1, which would be necessary to send Cyrillic characters, you could change the line in btoa:
to
although as this behaviour is no longer btoa-compatible you would probably want to rename the function. Basic authentication character encoding is a long-running source of frustration on the web in general. Until recently, the correct encoding was completely undefined; there is little agreement between browsers and servers on what the encoding should be. RFC 7617 finally extends Basic Auth to support non-ASCII characters with UTF-8, but until that's widely implemented it's not at all clear what encoding a service wants. Changing btoa as above will work for servers that want UTF-8 but break if there's anything that wants ISO-8859-1 (not to mention all the other locale-specific encodings IE can send). There might have to be an option to specific which encoding is desired? |
eww I wasn't aware of these issues with basic auth. Maybe this is how we convince people to stop using it :) We do need to support this on the node server as well. Perhaps you have time to submit a test and/or a fix as a PR and we can get it in? |
@bodnia this seems to be the case with 3.X as well. Can you look into it? |
@EvgenyOrekhov the fix is in latest master, could you please check |
@bodnia It works, thanks! |
It doesn't seem to work for version 3.51 when using SwaggerUIBundle |
@Anastasiyaaa please open a new issue and fill in the issue template. |
username: Ремонтник
password: Ремонтник
Swagger-UI produces the following header
But it's wrong. The correct header for the above credentials is
Swagger-UI version: 2.2.6
Update: this happens only when I use Swagger-UI's "Authorize" button, this does not happen when I use browser's native Basic Auth prompt.
The text was updated successfully, but these errors were encountered: