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

Using sanitize_text_field can break site_token #114

Open
mahowell opened this issue Aug 3, 2016 · 3 comments
Open

Using sanitize_text_field can break site_token #114

mahowell opened this issue Aug 3, 2016 · 3 comments

Comments

@mahowell
Copy link

mahowell commented Aug 3, 2016

If, for example, the sequence %B2 exists somewhere in the site_token, sanitize_text_field( $_POST['site_token'] ) will strip it out breaking the site_token.

In class-syndication-wp-rest-client.php:
update_post_meta( $site_ID, 'syn_site_token', push_syndicate_encrypt( sanitize_text_field( $_POST['site_token'] ) ) );

Not sure the best way to sanitize this field or if it even needs to be sanitized, but my current workaround:

function syndication_sanitize( $filtered, $str ) {
    if ( is_admin() && ! empty( $_POST ) && 'syn_site' === get_post_type() ) {
        return $str;
    } else {
        return $filtered;
    }
}
add_filter( 'sanitize_text_field', 'syndication_sanitize', 10, 2 );
@mahowell mahowell changed the title sanitize_text_field can break site_token Using sanitize_text_field can break site_token Aug 3, 2016
@emgk
Copy link

emgk commented Jun 1, 2017

The above code snippet is preventing to sanitize the value and can break site.

I have investigated this issue, confirmed that it's a bug. it's sanitizing the token string see the link.
https://github.com/WordPress/WordPress/blob/master/wp-includes/formatting.php#L4746-L4749

@philipjohn
Copy link
Contributor

Thanks both. Do either of you feel like opening a Pull Request to fix this issue?

@wpbt
Copy link

wpbt commented Sep 6, 2021

I have this issue:
need to access reCAPTCHA token in the server.

$token = ( $post['prefid_recaptcha_token'] ) ? sanitize_text_field( $post['prefid_recaptcha_token'] ) : '';

And I'm not sure if using sanitize_text_field() will be appropriate here and can't use sanitize_key() because it will convert all uppercase letters to lowercase and ultimately failing the whole process.

Note: if the token doesn't contain spaces and other special characters, sanitize_text_field() should work most of the times!
Is there any workaround for this?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants