Missing Authorization header in Apache
Emmanuel Gautier / September 17, 2024
2 min read
If you are using Apache with PHP-FPM, PHP-CGI, or any other FastCGI implementation, you may have noticed that the Authorization header is missing in your code. This is because Apache removes the Authorization header for security reasons.
Authorization headers are used to send credentials to the server. They are used to authenticate the user and authorize access to resources. If the Authorization header is missing, your application won't be able to authenticate the user and authorize access to resources. It includes the Bearer token used in OAuth2 authentication, Basic authentication, and other authentication methods.
Apache configuration
To fix this issue, you need to add the CGIPassAuth directive to your Apache configuration. This directive tells Apache to pass the Authorization header to the FastCGI server.
Here is an example of how you can add the CGIPassAuth directive to your Apache configuration:
CGIPassAuth on
In your VirtualHost configuration, you can add the following configuration:
<VirtualHost *:80>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</VirtualHost>
.htaccess configuration
If you don't have access to the Apache configuration file, you can also add the CGIPassAuth directive to your .htaccess file. This will tell Apache to pass the Authorization header to the FastCGI server for the specific directory.
Here is an example of how you can add the CGIPassAuth directive to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
Ressources
Consulting
If you're seeking solutions to a problem or need expert advice, I'm here to help! Don't hesitate to book a call with me for a consulting session. Let's discuss your situation and find the best solution together.
Featured Posts
Introducing new blog about OAuth, OpenID Connect, and IAM Solutions
I'm excited to announce the launch of a new blog named CerberAuth, where I'll be exploring the world of OAuth, OpenID Connect, and IAM solutions for modern security.
How to deal with Docker Hub rate limit on AWS
Since 2020, DockerHub has been limited to only 200 container image pull requests per six hours. This article will help you to deal with this limitation on AWS.
How to enable Python type checking in VSCode
Python now has support for type hints. In this article, we will see how to enable better IntelliSense and type checking analysis in VSCode.