Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
38
Choosing and Managing WordPress Plugins
robincornett
0
190
The Genesis Framework Meets the Block Editor
robincornett
0
64
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
46
Other Decks in Technology
See All in Technology
AI時代だからこそ推したい!Gitコマンド再入門
munakata
0
180
しろおびから始める!ログ活用の第一歩
shumei_ito
0
910
事業活動を AI Ready にする攻めと守りのデータエンジニアリング / data-engineering-for-ai-ready-business
pei0804
7
2.7k
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
0
250
触りたくないデータに、どう触るか AI時代のRBACアクセスガバナンス
ivry_presentationmaterials
0
130
自分で立ててみるLLMサービス
y_sera15
0
160
TinyGoでオブザーバビリティ?OpenTelemetryはTinyGoで使えるのか / Is OpenTelemetry available in TinyGo environment?
ymotongpoo
2
140
Running Kotlin + Quarkus with Lambda
nealle
1
450
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
880
ゲームのリアルタイム通信から見た QUIC と MoQ
segadevtech
0
110
契約書画像からの情報抽出に特化した視覚接地モデルを育てる話
sansantech
PRO
1
170
Deep Data Security 機能解説
oracle4engineer
PRO
2
800
Featured
See All Featured
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
320
How to build a perfect <img>
jonoalderson
1
6.1k
The Invisible Side of Design
smashingmag
301
52k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.7k
Ruling the World: When Life Gets Gamed
codingconduct
0
400
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
980
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Google's AI Overviews - The New Search
badams
0
1.6k
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
570
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
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