fix: require token as query param on GET /worker/pending to close LiteSpeed cache bypass
This commit is contained in:
@@ -32,23 +32,27 @@ class Peptide_News_Rest_Worker {
|
|||||||
nocache_headers();
|
nocache_headers();
|
||||||
header( 'X-LiteSpeed-Cache-Control: no-cache' );
|
header( 'X-LiteSpeed-Cache-Control: no-cache' );
|
||||||
|
|
||||||
if ( current_user_can( 'manage_options' ) ) {
|
$token = get_option( 'peptide_news_vps_token', '' );
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$token = get_option( 'peptide_news_vps_token', '' );
|
|
||||||
if ( ! empty( $token ) && class_exists( 'Peptide_News_Encryption' ) ) {
|
if ( ! empty( $token ) && class_exists( 'Peptide_News_Encryption' ) ) {
|
||||||
$decrypted = Peptide_News_Encryption::decrypt( (string) $token );
|
$decrypted = Peptide_News_Encryption::decrypt( (string) $token );
|
||||||
if ( ! empty( $decrypted ) ) {
|
if ( ! empty( $decrypted ) ) {
|
||||||
$token = $decrypted;
|
$token = $decrypted;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$header_auth = $request->get_header( 'x_peptide_news_token' );
|
|
||||||
if ( empty( $header_auth ) ) {
|
if ( WP_REST_Server::READABLE === $request->get_method() ) {
|
||||||
$header_auth = $request->get_param( 'token' );
|
$auth_token = (string) $request->get_param( 'token' );
|
||||||
|
} else {
|
||||||
|
if ( current_user_can( 'manage_options' ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
$auth_token = (string) $request->get_header( 'x_peptide_news_token' );
|
||||||
|
if ( empty( $auth_token ) ) {
|
||||||
|
$auth_token = (string) $request->get_param( 'token' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! empty( $token ) && ! empty( $header_auth ) && hash_equals( (string) $token, (string) $header_auth ) ) {
|
if ( ! empty( $token ) && ! empty( $auth_token ) && hash_equals( (string) $token, $auth_token ) ) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user