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

Incorrect escaping in theming.php #133

Closed
paulschreiber opened this issue Jul 5, 2018 · 6 comments
Closed

Incorrect escaping in theming.php #133

paulschreiber opened this issue Jul 5, 2018 · 6 comments
Labels

Comments

@paulschreiber
Copy link
Contributor

WordPress VIP reviewed version 5.3 of rpb-chessboard. They found the following:

And in templates/misc/theming.php there's uses of sanitize_html_class as an escaping function which need either swapping or wrapping with esc_attr.

paulschreiber pushed a commit to paulschreiber/rpb-chessboard that referenced this issue Jul 5, 2018
@yo35
Copy link
Owner

yo35 commented Jul 7, 2018

Here, I don't see the point. templates/misc/theming.php is meant to output CSS code. Why esc_attr() would be relevant in such context?

@paulschreiber
Copy link
Contributor Author

@tomjn can you clarify?

@tomjn
Copy link

tomjn commented Jul 7, 2018

Sanitising and escaping aren't the same, sanitisation aims to clean up data, escaping is aimed at securing

For example, esc_attr will encode opening and closing brackets, making it safe to for viewing, whereas sanitize_html_class strips out characters.

In the case of CSS, esc_html would also work.

@tomjn
Copy link

tomjn commented Jul 7, 2018

For reference, sanitize_html_class simply passes 2 regular expressions over the value to constrain the characters to a smaller subset:

https://core.trac.wordpress.org/browser/tags/4.9.7/src/wp-includes/formatting.php#L2073

It also passes it through a filter, which can be used to taint the value further

@yo35 yo35 added the bug label Jul 8, 2018
@yo35
Copy link
Owner

yo35 commented Jul 8, 2018

@tomjn I think I see your point. I'm going to replace the sanitize_* with esc_html in the templates used to generate CSS (i.e. templates/misc/theming.php and templates/misc/smallscreens.php).

Still, I have question regarding what is done in templates/misc/smallscreens.php. In this file, I use the following pattern:

<?php echo esc_html( $model->getAComplexCSSSelector() ); ?> {
   /* Some instruction */
}

Here, what is returned by $model->getAComplexCSSSelector() can be any valid CSS selector (see https://www.w3schools.com/cssref/css_selectors.asp). Can be for instance .some-css-class1 > .some-css-class2 or [someattribute="someValue"]. Obviously the esc_html(..) function would not have the expected effect with these two examples.

Hopefully, these special cases do not actually happen in RPB Chessboard. However, how should we handle properly these cases if we have to?

@yo35
Copy link
Owner

yo35 commented Jul 8, 2018

Fix available in 5.3.2.

@yo35 yo35 closed this as completed Jul 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants