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
430
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
43
Other Decks in Technology
See All in Technology
モバイルアプリ開発概論2026
recruitengineers
PRO
5
590
SO-101×VLAによる3色キューブのピック&プレース
abeja
0
200
【CEDEC2026】『GRANBLUE FANTASY: Relink - Endless Ragnarok』のバトル制作事例 ~最高のキャラゲーを目指して~
cygames
PRO
0
300
Flutterをカメラで動かしたかった話
sony
1
140
TypeScript入門 2026
recruitengineers
PRO
3
580
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
260
Service Connect 上のサービスに ECS Service の外側から到達できなかった話
ota1022
1
240
Forza Horizon 6 のテレメトリ機能で 自動運転に使えそうな学習データを集める話
henjin0
0
170
Bits AI を制するものは Datadog を制す / The player that controls Bits AI, controls Datadog
kaminashi
0
100
JavaScript 研修 (2026)
recruitengineers
PRO
2
540
AWS ネットワーク構築でハマった(ハマりかけた) 5選とそこから得た教訓
nagisa53
4
220
SmartHR Engineering Team Deck
smarthr
1
2.1k
Featured
See All Featured
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.3k
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
660
Designing for Timeless Needs
cassininazir
1
440
Rails Girls Zürich Keynote
gr2m
96
14k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
490
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
340
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
280
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
330
Building an army of robots
kneath
306
46k
Ruling the World: When Life Gets Gamed
codingconduct
0
300
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