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

PHP 8.1 compatibility: replace FILTER_SANITIZE_STRING #428

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion class-two-factor-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function init() {
* @return boolean
*/
public function jetpack_rememberme( $rememberme ) {
$action = filter_input( INPUT_GET, 'action', FILTER_SANITIZE_STRING );
$action = filter_input( INPUT_GET, 'action', FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) );

if ( 'jetpack-sso' === $action && $this->jetpack_is_sso_active() ) {
return true;
Expand Down
12 changes: 6 additions & 6 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public static function get_user_update_action_url( $user_id, $action ) {
* @return boolean
*/
public static function is_valid_user_action( $user_id, $action ) {
$request_nonce = filter_input( INPUT_GET, self::USER_SETTINGS_ACTION_NONCE_QUERY_ARG, FILTER_SANITIZE_STRING );
$request_nonce = filter_input( INPUT_GET, self::USER_SETTINGS_ACTION_NONCE_QUERY_ARG, FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) );

return wp_verify_nonce(
$request_nonce,
Expand Down Expand Up @@ -277,7 +277,7 @@ public static function current_user_being_edited() {
* @return void
*/
public static function trigger_user_settings_action() {
$action = filter_input( INPUT_GET, self::USER_SETTINGS_ACTION_QUERY_VAR, FILTER_SANITIZE_STRING );
$action = filter_input( INPUT_GET, self::USER_SETTINGS_ACTION_QUERY_VAR, FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) );
$user_id = self::current_user_being_edited();

if ( ! empty( $action ) && self::is_valid_user_action( $user_id, $action ) ) {
Expand Down Expand Up @@ -537,8 +537,8 @@ public static function show_two_factor_login( $user ) {
*/
public static function backup_2fa() {
$wp_auth_id = filter_input( INPUT_GET, 'wp-auth-id', FILTER_SANITIZE_NUMBER_INT );
$nonce = filter_input( INPUT_GET, 'wp-auth-nonce', FILTER_SANITIZE_STRING );
$provider = filter_input( INPUT_GET, 'provider', FILTER_SANITIZE_STRING );
$nonce = filter_input( INPUT_GET, 'wp-auth-nonce', FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) );
$provider = filter_input( INPUT_GET, 'provider', FILTER_CALLBACK, array( 'options' => 'sanitize_text_field' ) );

if ( ! $wp_auth_id || ! $nonce || ! $provider ) {
return;
Expand Down Expand Up @@ -794,7 +794,7 @@ public static function verify_login_nonce( $user_id, $nonce ) {
*/
public static function login_form_validate_2fa() {
$wp_auth_id = filter_input( INPUT_POST, 'wp-auth-id', FILTER_SANITIZE_NUMBER_INT );
$nonce = filter_input( INPUT_POST, 'wp-auth-nonce', FILTER_SANITIZE_STRING );
$nonce = filter_input( INPUT_POST, 'wp-auth-nonce', FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) );

if ( ! $wp_auth_id || ! $nonce ) {
return;
Expand All @@ -810,7 +810,7 @@ public static function login_form_validate_2fa() {
exit;
}

$provider = filter_input( INPUT_POST, 'provider', FILTER_SANITIZE_STRING );
$provider = filter_input( INPUT_POST, 'provider', FILTER_CALLBACK, array( 'options' => 'sanitize_text_field' ) );
if ( $provider ) {
$providers = self::get_available_providers_for_user( $user );
if ( isset( $providers[ $provider ] ) ) {
Expand Down
4 changes: 2 additions & 2 deletions providers/class-two-factor-backup-codes.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ public function authentication_page( $user ) {
* @return boolean
*/
public function validate_authentication( $user ) {
$backup_code = isset( $_POST['two-factor-backup-code'] ) ? sanitize_text_field( wp_unslash( $_POST['two-factor-backup-code'] ) ) : false;
return $this->validate_code( $user, filter_var( $backup_code, FILTER_SANITIZE_STRING ) );
$backup_code = isset( $_POST['two-factor-backup-code'] ) ? sanitize_text_field( wp_unslash( $_POST['two-factor-backup-code'] ) ) : '';
return $this->validate_code( $user, $backup_code );
kasparsd marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down