Skip to content
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

Fix for Basic Auth not being passed through with PHP in CGI mode #32

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

graham73may
Copy link

#1 Issue fixed.

PHP_AUTH_USER & PHP_AUTH_PW are now being set if PHP is using fast CGI

@mnelson4
Copy link

mnelson4 commented May 9, 2016

FYI pulled into https://github.com/eventespresso/Basic-Auth

@sebastienbarre
Copy link

This is sorely needed, this was hard to track. Please consider merging.

@kadamwhite
Copy link
Contributor

Just flagged this in core slack to see if @rmccue et al can take a look

@bigandy
Copy link

bigandy commented Dec 8, 2016

Any progress on this issue? For the moment I am using @mnelson4 version https://github.com/eventespresso/Basic-Auth which works A+

@alkema
Copy link

alkema commented Apr 5, 2017

The solution developed here https://github.com/eventespresso/Basic-Auth is the best one in my opinion because it does not suggest any Apache-specific solutions. The handling of HTTP headers is best handled in PHP, then the plugin just works with any web server. Thanks @mnelson4!

@kadamwhite
Copy link
Contributor

@rmccue Could you review this?

@MrToph
Copy link

MrToph commented Feb 15, 2018

Thanks so much, this fixed my issue with Basic Authentication not working 👍

Copy link

@Tug Tug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is quite an old one but I did a similar patch and just found out about this PR :)

This should be quite useful for sites who use CGI/FastCGI imo!

}

if ( !empty( $header ) ) {
list( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ) = explode( ':', base64_decode(substr( $header, 6 ) ) );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should be explode( ':', base64_decode( substr( $header, 6 ) ), 2 ); in case password contains a colon.

@@ -18,6 +18,18 @@ function json_basic_auth_handler( $user ) {
return $user;
}

if ( !isset( $_SERVER['PHP_AUTH_USER'] ) && ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) || isset( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ) ) ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this file plugin doesn't always use spaces after a ! but the WordPress coding standards suggest to have them

$header = $_SERVER['REDIRECT_HTTP_AUTHORIZATION'];
}

if ( !empty( $header ) ) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check that it's a basic access auth here:

if ( 'Basic ' === substr( $header, 0, 6 ) ) {

@@ -18,6 +18,18 @@ function json_basic_auth_handler( $user ) {
return $user;
}

if ( !isset( $_SERVER['PHP_AUTH_USER'] ) && ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) || isset( $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] ) ) ) {
if ( isset( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
$header = $_SERVER['HTTP_AUTHORIZATION'];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about naming this variable $authorization_header to make it more explicit?

// Check user is logged in before returning API results
add_filter('rest_pre_dispatch', function ($result) {

global $DI;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what this is for?

add_filter('flush_rewrite_rules_hard','__return_false');
```

### Check for authorisation
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this part is necessary in the context of this plugin.

@Ipstenu
Copy link

Ipstenu commented May 22, 2020

This was approved a year ago.

A number of hosts use FastCGI and telling customers to use an htaccess workaround to force HTTP for auth is not really a good security practice. Can this please be revisited for WP 5.5?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.