-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add require login bypass tokens feature #222
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Addons for Require Login. | ||
* | ||
* Pass query arg like: foo/bar?altis-auth=TOKEN | ||
*/ | ||
|
||
namespace Altis\Security\Require_Login; | ||
|
||
use Altis; | ||
|
||
const QUERY_ARG = 'altis-auth'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should ideally be passed through the Authorization header rather than as a query parameter, as the query parameter will end up in server logs/etc. Do the tools this was created for support this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, @mattheu ? |
||
|
||
/** | ||
* Setup. | ||
* | ||
* @return void | ||
*/ | ||
function bootstrap() : void { | ||
add_filter( 'hm-require-login.allowed_pages', __NAMESPACE__ . '\\allow_request_for_valid_token', 10, 2 ); | ||
} | ||
|
||
/** | ||
* Filter require login to allow request if a valid token is passed. . | ||
* | ||
* @param array $allowed Allowed pages. | ||
* @param string|null $page Page. | ||
* @return array | ||
*/ | ||
function allow_request_for_valid_token( array $allowed, ?string $page ) : array { | ||
$tokens = (array) ( Altis\get_config()['modules']['security']['require-login']['bypass-tokens'] ?? [] ); | ||
|
||
/** | ||
* Filters the list of accepted values for $_GET['altis-auth'] to bypass require login. | ||
* | ||
* @param array $tokens Array of string tokens that by pass require login. | ||
*/ | ||
$tokens = apply_filters( 'altis.security.require_login.bypass_tokens', $tokens ); | ||
|
||
if ( | ||
isset( $_GET[ QUERY_ARG ] ) && | ||
in_array( $_GET[ QUERY_ARG ], array_values( $tokens ), true ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a security feature, this needs to use constant-time comparison of strings to avoid timing attacks; ideally |
||
) { | ||
$allowed[] = $page; | ||
} | ||
|
||
return $allowed; | ||
} |
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 "Qualys" is here, is that referencing SSL Labs? If so, authentication isn't necessary for that in any case.