Search code examples
nginxencodingcharacter-encodingbasic-authentication

Non-latin HTTP Basic Authentication message encoding / NGINX


I'd like to show cyrillic message in a browser's "HTTP Basic Authentication" prompt, but end up with abracadabra.

Here's my NGINX config:

server {
  charset utf-8;
  listen 80;
  server_name example.com;
  root /path;
  include snippets/wordpress.conf;
  auth_basic "Введите пароль.";
  auth_basic_user_file /etc/nginx/.htpasswd;
}

here's curl output, that looks pretty, with utf-8 as content-type charset:

$ curl -I http://example.com/
HTTP/1.1 401 Unauthorized
Date: Sat, 12 Dec 2015 08:37:41 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Set-Cookie: __cfduid=x; expires=Sun, 11-Dec-16 08:37:41 GMT; path=/; domain=.mydomain.com; HttpOnly
WWW-Authenticate: Basic realm="Введите пароль."
Server: cloudflare-nginx
CF-RAY: xxxxxxxxxxxx-ARN

but here's the output of Chrome, Safari, Opera, Yandex browser... every browser I was able to try:

To view this page, you must log in to this area on example.com:80: ÐведиÑе паÑолÑ.

Solution

  • For completeness: in a newer question on serverfault, I found this answer

    RFC 7617 Section 3

    The 'realm' parameter carries data that can be considered textual; however, `[RFC7235] does not define a way to reliably transport non- US-ASCII characters. This is a known issue that would need to be addressed in a revision to that specification.

    realm parameter is the string you put in auth_basic directive. So, can't suggest anything, but stick to ASCII.