Security Advice Needed

by 12 comments
I am creating a wordpress multiser or network site with forms on each blogs dashboard where the admin can enter content.

There are two textare boxes and one text input box in the form and it is being saved as post metadata using a _POST action.

What would you suggest I use to sanitize the data that is being saved? And, where would this sanitizing function go?

#programming #advice #needed #security
  • Profile picture of the author SteveSRS
    Check out PDO it auto sanitizes (when used correctly!!)
  • Profile picture of the author SteveJohnson
    This page: Data Validation « WordPress Codex discusses data validation in WP. There are a number of WP functions that will do what you need. Also, you should check the docs on WP nonces: WordPress Nonces « WordPress Codex. Your form processing function verifies the nonce to ensure that whatever submitted the form data has the authority to do so.

    Also, it sounds like you're trying to create a dashboard widget? If so, this page: Dashboard Widgets API « WordPress Codex might help.

    Does update_meta() run data submitted through kses?
    No, it does not. The only sanitization of data occurs when the UPDATE statement is prepared. You need to do your own validation first.
  • Profile picture of the author SteveJohnson
    The sanitize_meta function is just an empty hook, it doesn't do anything on its own. You build your own sanitizing filter (function) for a specific meta key, and run it by adding the filter to the sanitize_meta function. You would use this kind of filter most often when you're needing to validate/sanitize a custom field that a user would enter.

    In your case, it would be easier to just build your filter into the function that saves the meta data.

    Let's say you want to allow only the limited HTML that is allowed in a comment. It's as simple as this:

    $meta_data = wp_kses_data( $_POST['meta_data'] );
    update_post_meta( $post->ID, 'meta_key', $meta_data );

    ( Function Reference/wp kses data « WordPress Codex )

    It's kind of difficult to guide you without seeing exactly what you're doing.
  • Profile picture of the author lordspace
    For my fields I use strip_tags and trim to make sure HTML tags are removed.
    Is it text content that goes in the text fields?
  • Profile picture of the author SteveSRS
    lordspace that is def not enough for insertion in a database...

Next Topics on Trending Feed