Some of the most common vulnerabilities in web applications are caused by applications not properly inspecting the data that users send in. PHP has an entire suite of tools to help inspected, filter, and sanitize data that comes from the user and other outside parties. Using built-in methods and extra tools you can protect your app from harmful data and users.
20. 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. 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)
30. 30
Rule Types
● Soft Rules – Doesn’t Stop Validation Chain
● Hard Rules – Stop Validation Chain For This
Element
● Stop Rules – Stop All Validation
31. 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. 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. 33
Custom Rules
● Extend AuraFilterAbstractRule
● Implement validate() and sanitize()
● Add to the Rule Locator
34. 34
Check it out
https://github.com/auraphp/Aura.Filter