-
Notifications
You must be signed in to change notification settings - Fork 159
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
Switch to using $_REQUEST
directly instead of filter_input()
and remove backup_2fa
#527
Switch to using $_REQUEST
directly instead of filter_input()
and remove backup_2fa
#527
Conversation
… these are not fields that need sanitization. Either they match an expected value or they don't.
Interesting, I never knew It this ChatGPT reply about all there is to know?
|
That response is mostly accurate, although there are some things that I don't believe are truthful (such as The best description is IMHO that: filter_input() only works on the raw input to PHP, it does not use the php user-space super globals, it only uses the data passed to the php sapi process at the start of the request. That has some benefits, in that it enforces code not alter the source-of-truth for the request, but has the downside of making unit testing harder. - $request_nonce = filter_input( INPUT_GET, self::USER_SETTINGS_ACTION_NONCE_QUERY_ARG, FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) );
+ $request_nonce = isset( $_REQUEST[ self::USER_SETTINGS_ACTION_NONCE_QUERY_ARG ] ) ? filter_var( $_REQUEST[ self::USER_SETTINGS_ACTION_NONCE_QUERY_ARG ], FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) ) : ''; Using the PHP7+ null-coalescing operator can make it similar though: - $request_nonce = filter_input( INPUT_GET, self::USER_SETTINGS_ACTION_NONCE_QUERY_ARG, FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) );
+ $request_nonce = filter_var( $_REQUEST[ self::USER_SETTINGS_ACTION_NONCE_QUERY_ARG ] ?? '', FILTER_CALLBACK, array( 'options' => 'sanitize_key' ) ); In other words, while the My experience of the filter extension is a bit biased, as back in the early PHP 5.x era where it was a new feature, it was very hard to rely upon due to it being disabled sometimes, and security vulnerabilities / bugs existed in older versions which although you may have called There's another reason for the change here though too - running |
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 the backup_2fa
stuff is necessary.
The $_REQUEST
stuff looks good, though, and I agree that filter_input()
adds minimal value, and makes testing harder in an environment like WP.
87985df
to
b1f6adb
Compare
Currently there's two different routes into the 2FA credentials window,
action=validate_2fa
andaction=backup_2fa
, these are exactly the same, except that the former uses POST and the latter uses GET.This is partially caused by the usage of
filter_input()
which has other problems for us, such as being unable to be unit tested.This PR simplifies it by combining
action=validate_2fa
andaction=backup_2fa
and simplifying the resulting code.This is part of an initial work towards #484.