Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Keeping it Clean: Sanitizing, Validating, and E...
Search
Robin Cornett
May 03, 2016
Technology
120
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Keeping it Clean: Sanitizing, Validating, and Escaping in WordPress
Robin Cornett
May 03, 2016
More Decks by Robin Cornett
See All by Robin Cornett
Accessibility Matters to You, Too
robincornett
0
440
Do You Even Need a Page Builder Anymore?
robincornett
0
36
Choosing and Managing WordPress Plugins
robincornett
0
190
The Genesis Framework Meets the Block Editor
robincornett
0
57
Mailchimp and Your Blog
robincornett
0
220
An Introduction to Chrome Dev Tools
robincornett
0
350
Front Pages and Home Pages and Posts Pages, Oh My!
robincornett
0
120
Extending WordPress with Custom Content Types
robincornett
0
260
What's New in WordPress 4.6
robincornett
0
44
Other Decks in Technology
See All in Technology
多摩川(.dev)ランニング入門 / Tamagawa.dev#3
fujiwara3
2
130
Continuous Delivery! It is not what you think it is
tdpauw
0
110
本番に近いテストをもっと手軽に - Postmanで広がるAPIテストの世界 / Expanding the World of API Testing with Postman
yokawasa
1
220
AIエージェントを雇う前に決める5つのこと
knishioka
1
140
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
470
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
130
人気商品が「ちゃんと買える」をつくる ー ECの負荷改善
ykagano
1
190
APIセキュリティを組織で実現するには~注力する点と設計・実装に入れたい対策~
riiimparm
3
870
IDperturb: Enhancing Variation in Synthetic Face Generation via Angular Perturbation
sansantech
PRO
0
100
少人数データチームのDevin活用実践事例
runandy16
2
150
Bet AI Day 2026丨Agentは、「金融」という巨大産業の何を変えられるのか
layerx
PRO
0
530
【Oracle AI Spotlight ウェビナー】AWSか、Azureか、Google Cloudか。その議論にオラクルを含める意義。
oracle4engineer
PRO
1
190
Featured
See All Featured
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
410
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
270
Embracing the Ebb and Flow
colly
88
5.2k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
320
Thoughts on Productivity
jonyablonski
76
5.3k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Optimising Largest Contentful Paint
csswizardry
37
3.9k
Building Applications with DynamoDB
mza
96
7.2k
Abbi's Birthday
coloredviolet
3
9.6k
Transcript
KEEPING IT CLEAN Sanitizing, Validating, and Escaping in WordPress
ASSUME THAT EVERYONE AROUND YOU IS LYING (or clueless, confused,
lost, can’t/won’t read, crazy)
FOUR STAGES OF DATA SAFETY Sanitization Validation Conditions Escaping Universal
Actions Specific Actions INPUT OUTPUT
INPUT: SANITIZE FOR SANITY Save the Right Kind of Data
DISPLAY FEATURED IMAGE FOR GENESIS
MANAGE YOUR EXPECTATIONS If a value is supposed to be
a number, make sure it’s saved as a number. If it’s supposed to be an image ID, make sure it’s a number. If it’s supposed to be a URL, make sure it’s a URL. …
BE RUTHLESS When you have a range of data that
can be entered, make sure you sanitize it.
LITTLE BOBBY TABLES source: http:/ /xkcd.com/327/
SANITIZE Make sure what’s saved to the database is the
correct format.
CORE SANITIZING FUNCTIONS Example functions: sanitize_email() sanitize_file_name() sanitize_html_class() sanitize_key() sanitize_meta()
sanitize_mime_type() sanitize_option() sanitize_sql_orderby() sanitize_text_field() sanitize_title() sanitize_title_for_query() sanitize_title_with_dashes() sanitize_user()
ALSO CONSIDER: (bool) (int) intval() array_map() htmlspecialchars_decode() stripslashes() esc_url_raw( $url,
(array) $protocols = null )
INPUT: VALIDATE FOR LOGIC Make Sure the Data Makes Sense
BE RUTHLESS Follow the whitelist philosophy with data validation, and
only allow the user to input data of your expected type. If it's not the proper type, discard it.
BUT DOES IT MAKE SENSE? If a number needs to
fall within a certain range, make sure it does.
BUT DOES IT MAKE SENSE?
OUTPUT: IT DEPENDS Use Conditionals To Make Smart Decisions
MAYBE I WILL, MAYBE I WON’T Use both WordPress conditionals
and your own to make sure you’re only printing data when you can or should. http:/ /codex.wordpress.org/Con ditional_Tags
USE ALL THE TOOLS YOU CAN Make sure you’re debugging:
define( 'WP_DEBUG', true ); define( 'SCRIPT_DEBUG', true ); Use plugins like Query Monitor, Debug Bar, or Hookr
OUTPUT: ESCAPE ALL THE THINGS
None
ESCAPE ALL THE THINGS “Escaping changes possibly evil content into
safe content.” source: https:/ /css-tricks.com/introduction-to-wordpress-front-end-security-escaping-the-things/
ESCAPING FUNCTIONS •intval( $int ) or (int) $int •absint( $int
) •wp_kses( (string) $fragment, (array) $allowed_html, (array) $protocols = null ) •wp_rel_nofollow( (string) $html ) •wp_kses_allowed_html( (string) $context ) •esc_html( $text ) •esc_html__() •esc_html_e() •esc_textarea() •sanitize_text_field() •esc_attr( $text ) •esc_attr__() •esc_attr_e() •esc_js( $text ) •esc_url( $url, (array) $protocols = null ) •esc_url_raw( $url, (array) $protocols = null ) •urlencode( $scalar ) •urlencode_deep( $array ) •validate_file( (string) $filename, (array) $allowed_files = "" ) •wp_redirect($location, $status = 302) •wp_safe_redirect($location, $status = 302) •sanitize_title( $title ) •sanitize_user( $username, $strict = false ) •balanceTags( $html ) or force_balance_tags( $html ) •tag_escape( $html_tag_name ) •sanitize_html_class( $class, $fallback ) •is_email( $email_address )
BE RUTHLESS Escape data as much as possible on output
to avoid XSS and malformed HTML.
SOURCES https:/ /css-tricks.com/introduction-to-wordpress-front-end-security-escaping- the-things/ https:/ /vip.wordpress.com/2014/06/20/the-importance-of-escaping-all-the- things/ https:/ /codex.wordpress.org/Validating_Sanitizing_and_Escaping_User_Data https:/
/ninjaforms.com/mr-mrs-null-form-validation-story/ http:/ /codex.wordpress.org/Conditional_Tags
THANK YOU robincornett.com @robincornett