SlideShare a Scribd company logo
Don't Trust Your Users 
Chris Tankersley 
ZendCon 2014
2 
Who Am I? 
● A PHP Developer for 10 Years 
● Lots of projects no one uses, 
and a few some do 
● https://github.com/dragonmantank
3 
Everyone Loves a Story 
http://northweststate.edu/about-nscc/
4 
Programming is Just Acronyms 
● DRY – Don't Repeat Yourself 
● KISS – Keep It Simple, Stupid 
● IPO – Input, Process, Output
5 
GIGO – Garbage In, Garbage Out
6 
Users Are a Nice Big Family
7 
Some People Want To Watch 
The World Burn
8 
We Love Contact Forms
9 
Client Side Validation
10 
HTML5 Validation 
<input type="email" required> 
<input type="text" pattern="d{5}([-]d{4})?)">
11 
Browsers Suck 
http://caniuse.com/#search=required
12 
Server Side is Necessary 
http://cucher.iblogger.org/images/as400_family.jpg
13 
Filtering vs Validation
14 
Removes Unwanted 'Stuff'
15 
Filtering changes things 
https://www.flickr.com/photos/httpwwwflickrcompeoplenadar/3349883/sizes/l
16 
Filtering changes things
17 
Validation Judges Things
18 
Most Libraries Do Both
19 
PHP's Filter Module
20 
Some Background 
● Enabled by default since 5.2.0 
● Provides both Validation and Filtering 
● Very easy to use to work with data 
● Exposed via the 7 basic functions
21 
Validation is Easy and Fun! 
<?php 
var_dump(filter_var('755', FILTER_VALIDATE_INT)); 
var_dump(filter_var('755.0', FILTER_VALIDATE_INT)); 
int(755) 
bool(false)
Basic Validation Out of the Box 
22
23 
We can clean up data as well 
filter_var('ID 655', FILTER_SANITIZE_NUMBER_INT); 
string(3) '655'
24 
What can we clean up?
25 
What can we clean up?
26 
Manual Filters 
function myFilter($string) { 
return substr($string, 5); 
} 
$output = filter_var('This is my test string', FILTER_CALLBACK, array( 
'options' => 'myFilter', 
))); 
string(12) 'is my string'
27 
Does big jobs as well
28 
Aura.Filter
29 
Easy To Use
30 
Rule Types 
● Soft Rules – Doesn’t Stop Validation Chain 
● Hard Rules – Stop Validation Chain For This 
Element 
● Stop Rules – Stop All Validation
31 
Validation and Filtering 
● RuleCollection::IS – Must match the rule 
● RuleCollection::IS_NOT – Must not match 
● RuleCollection::IS_BLANK_OR – Must be blank 
or match 
● RuleCollection::FIX – Sanitize The Data 
● RuleCollection::FIX_IS_BLANK_OR – Fix if not 
blank
32 
Bundled Rules 
● Alnum 
● Alpha 
● Between 
● Blank 
● Bool 
● Credit Card 
● DateTime 
● Email 
● Equal To Field 
● Equal To Value 
● Float 
● In Array Keys 
● In Array 
Values 
● Int 
● ipv4 
● Locale 
● Max 
● Min 
● Regex 
● Strict Equals 
● String(length, 
min,max) 
● Trim 
● Upload 
● Url
33 
Custom Rules 
● Extend AuraFilterAbstractRule 
● Implement validate() and sanitize() 
● Add to the Rule Locator
34 
Check it out 
https://github.com/auraphp/Aura.Filter
35 
Use Your Framework's
36 
Zend Framework 2
37 
ZendValidator
38 
ZendValidator
39 
ZendValidator
40 
Model Validation
41 
Symfony2 Validation
Symfony2 Validator 
Read the docs - http://symfony.com/doc/current/book/validation.html 
42
43 
Symfony2 Validator
44 
Use with Forms
45 
Always Look First
46 
One Last Thing
47 
Validation is Hard
48 
Questions?
49 
Thanks! 
● https://joind.in/talk/view/12063 
●@dragonmantank 
● chris@ctankersley.com

More Related Content

PPTX
Learn JavaScript From Scratch
PPTX
Kickstarting Your Mongo Education with MongoDB University
PDF
Typescript for grails
PPTX
Failing at Scale - PNWPHP 2016
PPTX
Don't Trust Your Users
PPTX
Oh Crap, My Code is Slow - Madison PHP 2016
PPTX
From Docker to Production - ZendCon 2016
PDF
A Brief History of Open Source
Learn JavaScript From Scratch
Kickstarting Your Mongo Education with MongoDB University
Typescript for grails
Failing at Scale - PNWPHP 2016
Don't Trust Your Users
Oh Crap, My Code is Slow - Madison PHP 2016
From Docker to Production - ZendCon 2016
A Brief History of Open Source

Similar to Don't Trust Your Users (20)

PDF
Benchmarks, performance, scalability, and capacity what's behind the numbers
PDF
Benchmarks, performance, scalability, and capacity what s behind the numbers...
PPTX
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
PDF
Validating big data jobs - Spark AI Summit EU
PDF
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
PDF
Writing Tests Effectively
PDF
Programming for Performance
PDF
Engineering data quality
PDF
Software Craftmanship - Cours Polytech
PDF
Unit testing
PDF
Unit testing in PHP
PDF
Shift-Left Testing: QA in a DevOps World by David Laulusa
PPTX
OutSystems Tips and Tricks
PDF
Test your code
PDF
How MySQL can boost (or kill) your application v2
PPTX
Test-Driven Development.pptx
PDF
3 query tuning techniques every sql server programmer should know
PDF
kranonit S06E01 Игорь Цинько: High load
PDF
Getting started with unit and functional testing
PDF
Adversarial Simulation Nickerson/Gates Wild West Hacking Fest Oct 2017
Benchmarks, performance, scalability, and capacity what's behind the numbers
Benchmarks, performance, scalability, and capacity what s behind the numbers...
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
Validating big data jobs - Spark AI Summit EU
Validating Big Data Jobs—Stopping Failures Before Production on Apache Spark...
Writing Tests Effectively
Programming for Performance
Engineering data quality
Software Craftmanship - Cours Polytech
Unit testing
Unit testing in PHP
Shift-Left Testing: QA in a DevOps World by David Laulusa
OutSystems Tips and Tricks
Test your code
How MySQL can boost (or kill) your application v2
Test-Driven Development.pptx
3 query tuning techniques every sql server programmer should know
kranonit S06E01 Игорь Цинько: High load
Getting started with unit and functional testing
Adversarial Simulation Nickerson/Gates Wild West Hacking Fest Oct 2017
Ad

More from Chris Tankersley (20)

PDF
8 Rules for Better Applications - PHP Tek 2025
PDF
The Art of API Design - PHP Tek 2025, Chris Tankersley
PDF
Docker is Dead: Long Live Containers
PDF
Bend time to your will with git
PDF
Using PHP Functions! (Not those functions, Google Cloud Functions)
PDF
Dead Simple APIs with OpenAPI
PDF
Killer Docker Workflows for Development
PDF
You Got Async in my PHP!
ODP
Docker for Developers - PHP Detroit 2018
ODP
Docker for Developers
ODP
They are Watching You
ODP
BASHing at the CLI - Midwest PHP 2018
PDF
You Were Lied To About Optimization
ODP
Docker for PHP Developers - php[world] 2017
ODP
Docker for PHP Developers - Madison PHP 2017
ODP
Docker for Developers - php[tek] 2017
ODP
Why Docker? Dayton PHP, April 2017
PPTX
OOP Is More Then Cars and Dogs - Midwest PHP 2017
PPTX
From Docker to Production - SunshinePHP 2017
PPTX
Docker for Developers - Sunshine PHP
8 Rules for Better Applications - PHP Tek 2025
The Art of API Design - PHP Tek 2025, Chris Tankersley
Docker is Dead: Long Live Containers
Bend time to your will with git
Using PHP Functions! (Not those functions, Google Cloud Functions)
Dead Simple APIs with OpenAPI
Killer Docker Workflows for Development
You Got Async in my PHP!
Docker for Developers - PHP Detroit 2018
Docker for Developers
They are Watching You
BASHing at the CLI - Midwest PHP 2018
You Were Lied To About Optimization
Docker for PHP Developers - php[world] 2017
Docker for PHP Developers - Madison PHP 2017
Docker for Developers - php[tek] 2017
Why Docker? Dayton PHP, April 2017
OOP Is More Then Cars and Dogs - Midwest PHP 2017
From Docker to Production - SunshinePHP 2017
Docker for Developers - Sunshine PHP
Ad

Recently uploaded (20)

PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Tartificialntelligence_presentation.pptx
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
DP Operators-handbook-extract for the Mautical Institute
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Touch Screen Technology
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Approach and Philosophy of On baking technology
PDF
August Patch Tuesday
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
SOPHOS-XG Firewall Administrator PPT.pptx
Heart disease approach using modified random forest and particle swarm optimi...
1 - Historical Antecedents, Social Consideration.pdf
Zenith AI: Advanced Artificial Intelligence
Tartificialntelligence_presentation.pptx
Web App vs Mobile App What Should You Build First.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
DP Operators-handbook-extract for the Mautical Institute
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Touch Screen Technology
Hindi spoken digit analysis for native and non-native speakers
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Group 1 Presentation -Planning and Decision Making .pptx
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Approach and Philosophy of On baking technology
August Patch Tuesday

Don't Trust Your Users