-
Notifications
You must be signed in to change notification settings - Fork 287
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
base: master
Are you sure you want to change the base?
Conversation
FYI pulled into https://github.com/eventespresso/Basic-Auth |
This is sorely needed, this was hard to track. Please consider merging. |
Just flagged this in core slack to see if @rmccue et al can take a look |
Any progress on this issue? For the moment I am using @mnelson4 version https://github.com/eventespresso/Basic-Auth which works A+ |
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! |
@rmccue Could you review this? |
Thanks so much, this fixed my issue with Basic Authentication not working 👍 |
There was a problem hiding this 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 ) ) ); |
There was a problem hiding this comment.
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'] ) ) ) { |
There was a problem hiding this comment.
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 ) ) { |
There was a problem hiding this comment.
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']; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
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? |
#1 Issue fixed.
PHP_AUTH_USER & PHP_AUTH_PW are now being set if PHP is using fast CGI