Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The WP source shows that wp_filter_kses and wp_filter_post_kses are passed data that's "expected to be escaped with slashes."

On the other hand, wp_kses_data is passed data that's "expected to not be escaped" and wp_kses_post has code that looks like wp_kses_data.

How safe is it to pass unknown (in terms of escaped with slashes) data to these functions?

Can the first set be preferred over the second or is preferring the second set safer?

Or is this a case where you absolutely need to know the condition of your data in terms of slashed?

--update--

I'm now figuring that if you don't know whether the data is escaped you could use wp_kses_data( stripslashes_deep( $data ) ); and run the return though addslashes() if you need escaped in the end.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

From the codex:

wp_filter_kses should generally be preferred over wp_kses_data because wp_magic_quotes escapes $_GET, $_POST, $_COOKIE, $_SERVER, and $_REQUEST fairly early in the hook system, shortly after 'plugins_loaded' but earlier then 'init' or 'wp_loaded'.

The first set is then preferred. More of a question of, "is stripping slashes more secure than not?" They both use the same allowed HTML. Well yeah it depends, in absolute cases, but I would assume that it is more secure to than not to.

Basic useage of kses:

$filtered = wp_kses($unfiltered, $allowed_html, $allowed_protocols);

All of the wordpress kses functions then just do

$filtered = wp_kses($unfiltered, $allowedtags);

SO:

$filtered = wp_kses_data($unfiltered);
$filtered = wp_filter_kses($unfiltered); // does the same, but will also slash escape the data

the post variations use a different set of tags; those allowed for use by non-admins.

share|improve this answer
    
I actually wrote that part in the codex based on core.trac.wordpress.org/ticket/17089 ... but that's for when you know the data is escaped (because of wp_magic_quotes). What I don't know is what to do if you don't know the state of the data... –  WraithKenny Jun 16 '11 at 14:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.