Secure Coding With Wordpress (BarCamp Orlando 2009)

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

2 comments

Comments 1 - 2 of 2 previous next Post a comment

Post a comment
Embed Video
Edit your comment Cancel

4 Favorites

Secure Coding With Wordpress (BarCamp Orlando 2009) - Presentation Transcript

  1. Secure Coding with WordPress Mark Jaquith markjaquith.com coveredwebservices.com
  2. XSS privilege shell execution escalation CSRF SQL injection
  3. Plugin security is hit-or-miss
  4. Mostly miss
  5. SQL Injection
  6. <?php $wpdb->query( \"UPDATE $wpdb->posts SET post_title = '$newtitle' WHERE ID = $my_id\" ); ?>
  7. <?php $newtitle = $wpdb->escape( $newtitle ); $my_id = absint( $my_id ); $wpdb->query( \"UPDATE $wpdb->posts SET post_title = '$newtitle' WHERE ID = $my_id\" ); ?>
  8. $wpdb->update()
  9. <?php $wpdb->update( $wpdb->posts, array( 'post_title' => $newtitle ), array( 'ID' => $my_id ) ); ?>
  10. $wpdb->insert()
  11. <?php $wpdb->insert( $wpdb->posts, array( 'post_title' => $newtitle ) ); ?>
  12. <?php $wpdb->update( $wpdb->posts, array( 'post_title' => $newtitle, 'post_content' => $newcontent ), array( 'ID' => $my_id, 'post_title' => $old_title ) ); ?>
  13. <?php $post_title = 'New Title'; $wheres['ID'] = 123; $wheres['post_title'] = 'Old Title'; $wpdb->update( $wpdb->posts, compact( 'post_title' ), $wheres ); ?>
  14. $wpdb->prepare()
  15. <?php $title = 'Post Title'; $ID = 123; $content = $wpdb->get_var( $wpdb->prepare( \"SELECT post_content FROM $wpdb->posts WHERE post_title = %s AND ID = %d\", $title, $ID ) ); ?>
  16. •Uses sprintf() formatting •%s for strings •%d for integers •You should not quote or escape
  17. Escape late
  18. XSS
  19. <h1> <?php echo $title; ?> </h1>
  20. <?php $title = '<script> pwnage(); </script>' ?> <h1> <?php echo $title; ?> </h1>
  21. Anything that isn’t hardcoded is suspect
  22. Better: Everything is suspect
  23. wp_specialchars()
  24. <?php $title = '<script> pwnage(); </script>' ?> <h1> <?php echo wp_specialchars( $title ); ?> </h1>
  25. <?php $title = '\" onmouseover=\"pwnd();'; ?> <a href=\"#wordcamp\" title=\" <?php echo wp_specialchars( $title ); ?> \"> Link Text </a>
  26. attribute_escape()
  27. <?php $title = '\" onmouseover=\"pwnd();'; ?> <a href=\"#wordcamp\" title=\" <?php echo attribute_escape( $title ); ?> \"> Link Text </a>
  28. <?php $url = 'javascript:pwnage();'; ?> <a href=\" <?php echo attribute_escape( $url ); ?> \"> Link Text </a>
  29. clean_url()
  30. <?php $url = 'javascript:pwnage();'; ?> <a href=\" <?php echo clean_url( $url ); ?> \"> Link Text </a>
  31. sanitize_url(), sister of clean_url()
  32. js_escape()
  33. CSRF
  34. Authorization vs. Intention
  35. Nonces action-, object-, user-specific time limited secret keys
  36. Specific to •WordPress user •Action attempted •Object of attempted action •Time window
  37. wp_nonce_field()
  38. <form action=\"process.php\" method=\"post\"> <?php wp_nonce_field('plugin-action_object'); ?> ... </form>
  39. check_admin_referer( )
  40. <?php // before output goes to browser check_admin_referer('plugin- action_object'); ?>
  41. Still need to use current_user_can()
  42. AJAX CSRF
  43. • wp_create_nonce( 'your_action' ); • &_ajax_nonce=YOUR_NONCE • check_ajax_referer( 'your_action' );
  44. Privilege Escalation
  45. current_user_can()
  46. Set your salts! http://api.wordpress.org/secret-key/1.1/
  47. Stupid shit I see all the time
  48. exec()
  49. <form action=\"<?php echo $_SERVER['REQUEST_URI']; ?>\">
  50. Thank you!

+ Mark JaquithMark Jaquith, 6 months ago

custom

1290 views, 4 favs, 1 embeds more stats

Slightly modified version of my Secure Coding with more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 1290
    • 1280 on SlideShare
    • 10 from embeds
  • Comments 2
  • Favorites 4
  • Downloads 16
Most viewed embeds
  • 10 views on http://www.barcamporlando.org

more

All embeds
  • 10 views on http://www.barcamporlando.org

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories