Skip to content

Instantly share code, notes, and snippets.

@ramsey
Last active September 28, 2017 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramsey/3a7c2465a43e145f7f03c75665ae2998 to your computer and use it in GitHub Desktop.
Save ramsey/3a7c2465a43e145f7f03c75665ae2998 to your computer and use it in GitHub Desktop.
Demonstrate that Apache converts any response containing WWW-Authenticate to 401
<?php
header('HTTP/1.1 403 Forbidden');
if (isset($_GET['authHeader']) && $_GET['authHeader'] == 1) {
header('WWW-Authenticate: Bearer realm="Foo"');
}
echo "Hi!";
#
# Using HTTPie to make requests from the command line: https://httpie.org/
#
ramsey at luthien in ~
$ http -v GET http://localhost/authenticate.php
GET /authenticate.php HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost
User-Agent: HTTPie/0.9.9
HTTP/1.1 403 Forbidden
Connection: keep-alive
Content-Length: 3
Content-Type: text/html; charset=UTF-8
Date: Thu, 28 Sep 2017 05:24:16 GMT
Server: Apache/2.4.27 PHP/7.0.21
X-Powered-By: PHP/7.0.21
Hi!
ramsey at luthien in ~
$ http -v GET http://localhost/authenticate.php?authHeader=1
GET /authenticate.php?authHeader=1 HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: localhost
User-Agent: HTTPie/0.9.9
HTTP/1.1 401 Unauthorized
Connection: keep-alive
Content-Length: 3
Content-Type: text/html; charset=UTF-8
Date: Thu, 28 Sep 2017 05:16:37 GMT
Server: Apache/2.4.27 PHP/7.0.21
WWW-Authenticate: Bearer realm="Foo"
X-Powered-By: PHP/7.0.21
Hi!
@ramsey
Copy link
Author

ramsey commented Sep 28, 2017

When I ran the same script using PHP's built-in web server, I noticed the same behavior. Turns out, PHP is responsible for this: https://github.com/php/php-src/blob/a51cb393b1accc29200e8f57ef867a6a47b2564f/main/SAPI.c#L829-L830

@ramsey
Copy link
Author

ramsey commented Sep 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment