SlideShare ist ein Scribd-Unternehmen logo
1 von 54
Downloaden Sie, um offline zu lesen
Meet Magento Romania 2016 | @rescueAnn
Secure input and output
handling
How not to suck at data
validation and output
Anna Völkl
Meet Magento Romania 2016 | @rescueAnn
Hi, I’m Anna!
I do Magento things
6 years of Magento, PHP since 2004
I love IT & Information Security
Magento Security Best Practises, anyone?!
I work at E-CONOMIX
Magento & Typo3 ❤ Linz, Austria
Meet Magento Romania 2016 | @rescueAnn
What this talk is all about:
★ XSS
★ Frontend input validation
★ Backend input validation
★ Output escaping
Meet Magento Romania 2016 | @rescueAnn
Once upon a time...
Meet Magento Romania 2016 | @rescueAnn
Academic titles - what we expected
BA PhD
BSc MA
DI MSc
Mag. MBA
Dr. LL.M.
Meet Magento Romania 2016 | @rescueAnn
Academic titles - what we got
Meet Magento Romania 2016 | @rescueAnn
XSS is real.
Meet Magento Romania 2016 | @rescueAnn
index.php?name=Anna<script>alert('XSS');</script>
Meet Magento Romania 2016 | @rescueAnn
“Cross-Site Scripting (XSS) attacks occur when:
1. Data enters a Web application through an untrusted
source, most frequently a web request.
2. The data is included in dynamic content that is sent
to a web user without being validated for malicious
content.”
Source: https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
Meet Magento Romania 2016 | @rescueAnn
XSS in latest SUPEEs
SUPEE-8788
● 17 vulnerabilities
● 4 XSS (1 high, 4 medium)
SUPEE-7405
● 20 vulnerabilities
● 7 XSS (2 critical, 1 high, 2 medium, 2 low)
Meet Magento Romania 2016 | @rescueAnn
Every feature adds a risk.
⬇
Every input/output adds a risk.
Meet Magento Romania 2016 | @rescueAnn
Input
⬇
Process
⬇
Output
Meet Magento Romania 2016 | @rescueAnnSource: http://transferready.co.uk/index.php/blog/function-machines/
Meet Magento Romania 2016 | @rescueAnnSource: http://transferready.co.uk/index.php/blog/function-machines/
Meet Magento Romania 2016 | @rescueAnn
e-mail address
password
Logged in
customer
Meet Magento Romania 2016 | @rescueAnn
Security-Technology, Department of Defense Computer
Security Initiative, 1980
Meet Magento Romania 2016 | @rescueAnn
Stop “Last Minute Security”
Do the coding, spend last X hours on „making it secure“
Secure coding doesn't really take longer
Data quality ⇔ software quality ⇔ security
Always keep security in mind.
Meet Magento Romania 2016 | @rescueAnn
Source: http://blogs.technet.com/b/rhalbheer/archive/2011/01/14/real-physical-security.aspx
Meet Magento Romania 2016 | @rescueAnn
Input
Meet Magento Romania 2016 | @rescueAnn
Frontend input validation
● User experience
● Stop unwanted input when it occurs
● Do not bother your server with crazy input
requests
Don't fill up your database with garbage.
Meet Magento Romania 2016 | @rescueAnn
Magento Frontend Validation
Magento 1 (51 validation rules)
js/prototype/validation.js
Magento 2 (74 validation rules)
app/code/Magento/Ui/view/base/web/js
/lib/validation/rules.js
Meet Magento Romania 2016 | @rescueAnn
app/code/Magento/Ui/
view/base/web/js/lib/
validation/rules.js
M
2
Meet Magento Romania 2016 | @rescueAnn
app/code/Magento/Ui/view/base/web/js/lib/
validation/rules.js
min_text_length
max_text_length
max-words
min-words
range-words
letters-with-basic-punc
alphanumeric
letters-only
no-whitespace
zip-range
integer
vinUS
dateITA
dateNL
time
time12h
phoneUS
phoneUK
mobileUK
stripped-min-length
email2
url2
credit-card-types
ipv4
ipv6
pattern
validate-no-html-tags
validate-select
validate-no-empty
validate-alphanum-with-spaces
validate-data
validate-street
validate-phoneStrict
validate-phoneLax
validate-fax
validate-email
validate-emailSender
validate-password
validate-admin-password
validate-url
validate-clean-url
validate-xml-identifier
validate-ssn
validate-zip-us
validate-date-au
validate-currency-dollar
validate-not-negative-number
validate-zero-or-greater
validate-greater-than-zero
validate-css-length
validate-number
validate-number-range
validate-digits
validate-digits-range
validate-range
validate-alpha
validate-code
validate-alphanum
validate-date
validate-identifier
validate-zip-international
validate-state
less-than-equals-to
greater-than-equals-to
validate-emails
validate-cc-number
validate-cc-ukss
required-entry
checked
not-negative-amount
validate-per-page-value-list
validate-new-password
validate-item-quantity
equalTo
M
2
Meet Magento Romania 2016 | @rescueAnn
Add your own validator
define([
'jquery',
'jquery/ui',
'jquery/validate',
'mage/translate'
], function ($) {
$.validator.addMethod('validate-custom-name',
function (value) {
return (value !== 'anna');
}, $.mage.__('Enter valid name'));
});
M
2
Meet Magento Romania 2016 | @rescueAnn
<form>
<div class="field required">
<input type="email" id="email_address"
data-validate="{required:true,
'validate-email':true}"
aria-required="true">
</div>
</form>
Adding frontend-validation
M
2
Meet Magento Romania 2016 | @rescueAnn
Bonus
Meet Magento Romania 2016 | @rescueAnn
<form>
<div class="field required">
<input type="email" id="email_address"
data-validate="{required:true,
'validate-email':true}"
aria-required="true">
</div>
</form>
Adding frontend-validation
M
2
Meet Magento Romania 2016 | @rescueAnnSource: https://quadhead.de/cola-hack-sicherheitsluecke-auf-meinecoke-de/
Why frontend validation is not enough...
Meet Magento Romania 2016 | @rescueAnn
Don’t trust the user.
Don’t trust the input!
Meet Magento Romania 2016 | @rescueAnn
Meet Magento Romania 2016 | @rescueAnn
EAV Backend validation input rules
Magento 1
Mage_Eav_Attribute_Data_Abstract
Magento 2
MagentoEavModelAttributeDataAbstractData
Meet Magento Romania 2016 | @rescueAnn
MagentoEavModelAttributeDataAbstractData
Input Validation Rules:
● alphanumeric
● numeric
● alpha
● email
● url
● date
M
2
Meet Magento Romania 2016 | @rescueAnn
ZendValidator
Standard Validation Classes
Alnum Validator
Alpha Validator
Barcode Validator
Between Validator
Callback Validator
CreditCard Validator
Date Validator
DbRecordExists and
DbNoRecordExists
Validators
Digits Validator
EmailAddress Validator
File Validation Classes
GreaterThan Validator
Hex Validator
Hostname Validator
Iban Validator
Identical Validator
InArray Validator
Ip Validator
Isbn Validator
IsFloat
IsInt
LessThan Validator
NotEmpty Validator
PostCode Validator
Regex Validator
Sitemap Validators
Step Validator
StringLength Validator
Timezone Validator
Uri Validator
Meet Magento Romania 2016 | @rescueAnn
Output
Meet Magento Romania 2016 | @rescueAnn
Is input validation not enough?!
Meet Magento Romania 2016 | @rescueAnn
Magento 2 Templates
XSS security
Meet Magento Romania 2016 | @rescueAnn
getXXXHtml()
<?php echo $block->getTitleHtml() ?>
<?php echo $block->getHtmlTitle() ?>
<?php echo
$block->escapeHtml($block->getTitle()) ?>
M
2
Magento 2 Templates XSS security
Meet Magento Romania 2016 | @rescueAnn
Type casting and PHP function count()
<h1><?php echo (int)$block->getId() ?></h1>
<?php echo count($var); ?>
M
2
Magento 2 Templates XSS security
Meet Magento Romania 2016 | @rescueAnn
Output in single or double quotes
<?php echo 'some text' ?>
<?php echo "some text" ?>
M
2
Magento 2 Templates XSS security
Meet Magento Romania 2016 | @rescueAnn
Use specific escape functions
<a href="<?php echo $block->escapeXssInUrl(
$block->getUrl()) ?>">
<?php echo $block->getAnchorTextHtml() ?>
</a>
M
2
Magento 2 Templates XSS security
Meet Magento Romania 2016 | @rescueAnn
Use these. Also Magento does it!
$block->escapeHtml()
$block->escapeQuote()
$block->escapeUrl()
$block->escapeXssInUrl()
M
2
Meet Magento Romania 2016 | @rescueAnn
$block->escapeHtml()
Whitelist: allowed Tags, htmlspecialchars
M
2
Meet Magento Romania 2016 | @rescueAnn
MagentoFrameworkEscaper
M
2
Meet Magento Romania 2016 | @rescueAnn
$block->escapeHtml()
Whitelist: allowed Tags, htmlspecialchars
$block->escapeQuote()
Escape quotes inside html attributes
$addSlashes = false for escaping js inside html
attribute (onClick, onSubmit etc)
M
2
Meet Magento Romania 2016 | @rescueAnn
$block->escapeUrl()
Escape HTML entities in URL
(htmlspecialchars)
$block->escapeXssInUrl()
eliminating 'javascript' + htmlspecialchars
M
2
Meet Magento Romania 2016 | @rescueAnn
Meet Magento Romania 2016 | @rescueAnn
Testing
Meet Magento Romania 2016 | @rescueAnn
Static XSS Test
XssPhtmlTemplateTest.php in
devtestsstatictestsuiteMagentoT
estPhp
See
http://devdocs.magento.com/guides/v2.0/frontend-dev
-guide/templates/template-security.html
Meet Magento Romania 2016 | @rescueAnn
$ magento dev:tests:run static
Meet Magento Romania 2016 | @rescueAnn
$ magento dev:tests:run static
Meet Magento Romania 2016 | @rescueAnn
What happened to the
little attribute?!
Meet Magento Romania 2016 | @rescueAnn
Weird customers and customer data was removed
Frontend validation added - Dropdown (whitelist)
would have been an option too
Server side validation added
Output escaped
Meet Magento Romania 2016 | @rescueAnn
Summary
Think, act and design your software responsibly:
1. Client side validation
2. Server side validation
3. UTF-8 all the way
4. Escape at point of use
5. Use & run tests
Meet Magento Romania 2016 | @rescueAnn
Questions?
Right here, right now
or later @resueAnn

Weitere ähnliche Inhalte

Ähnlich wie Secure input and output handling - Meet Magento Romania 2016

Xss mitigation php [Repaired]
Xss mitigation php [Repaired]Xss mitigation php [Repaired]
Xss mitigation php [Repaired]
Tinashe Makuti
 

Ähnlich wie Secure input and output handling - Meet Magento Romania 2016 (20)

Secure development environment @ Meet Magento Croatia 2017
Secure development environment @ Meet Magento Croatia 2017Secure development environment @ Meet Magento Croatia 2017
Secure development environment @ Meet Magento Croatia 2017
 
Guillaume Thibaux - Can we win the fight against performance bottlenecks? Les...
Guillaume Thibaux - Can we win the fight against performance bottlenecks? Les...Guillaume Thibaux - Can we win the fight against performance bottlenecks? Les...
Guillaume Thibaux - Can we win the fight against performance bottlenecks? Les...
 
Rasha atta abd elsalam
Rasha atta abd elsalamRasha atta abd elsalam
Rasha atta abd elsalam
 
Brakeman
BrakemanBrakeman
Brakeman
 
Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & Quality
 
Patch Tuesday Analysis - July 2016
Patch Tuesday Analysis - July 2016Patch Tuesday Analysis - July 2016
Patch Tuesday Analysis - July 2016
 
Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2Black Magic of Code Generation in Magento 2
Black Magic of Code Generation in Magento 2
 
Magento best practices
Magento best practicesMagento best practices
Magento best practices
 
PCI Compliance for Hipsters
PCI Compliance for HipstersPCI Compliance for Hipsters
PCI Compliance for Hipsters
 
Xss mitigation php [Repaired]
Xss mitigation php [Repaired]Xss mitigation php [Repaired]
Xss mitigation php [Repaired]
 
Andrea Zwirner - Magento security and hardening strategies
Andrea Zwirner - Magento security and hardening strategiesAndrea Zwirner - Magento security and hardening strategies
Andrea Zwirner - Magento security and hardening strategies
 
Extension Submission to Marketplace
Extension Submission to MarketplaceExtension Submission to Marketplace
Extension Submission to Marketplace
 
TechSEO Boost 2017: Making the Web Fast
TechSEO Boost 2017: Making the Web FastTechSEO Boost 2017: Making the Web Fast
TechSEO Boost 2017: Making the Web Fast
 
Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)Writing Testable Code (for Magento 1 and 2)
Writing Testable Code (for Magento 1 and 2)
 
Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?Tadhg Bowe - i18n: how can I rephrase that?
Tadhg Bowe - i18n: how can I rephrase that?
 
Don't get stung - an introduction to the OWASP Top 10
Don't get stung - an introduction to the OWASP Top 10Don't get stung - an introduction to the OWASP Top 10
Don't get stung - an introduction to the OWASP Top 10
 
Server Side Rendering of JavaScript in PHP
Server Side Rendering of JavaScript in PHPServer Side Rendering of JavaScript in PHP
Server Side Rendering of JavaScript in PHP
 
Google Tag Manager - 5 years. What have we learned?
Google Tag Manager - 5 years. What have we learned?Google Tag Manager - 5 years. What have we learned?
Google Tag Manager - 5 years. What have we learned?
 
Hire Magento 2 developer India, Call us for more
Hire Magento 2 developer India, Call us for more Hire Magento 2 developer India, Call us for more
Hire Magento 2 developer India, Call us for more
 
Patch Tuesday Analysis - September 2016
Patch Tuesday Analysis - September 2016Patch Tuesday Analysis - September 2016
Patch Tuesday Analysis - September 2016
 

Kürzlich hochgeladen

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 

Kürzlich hochgeladen (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
SHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions PresentationSHRMPro HRMS Software Solutions Presentation
SHRMPro HRMS Software Solutions Presentation
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban%in Durban+277-882-255-28 abortion pills for sale in Durban
%in Durban+277-882-255-28 abortion pills for sale in Durban
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Secure input and output handling - Meet Magento Romania 2016

  • 1. Meet Magento Romania 2016 | @rescueAnn Secure input and output handling How not to suck at data validation and output Anna Völkl
  • 2. Meet Magento Romania 2016 | @rescueAnn Hi, I’m Anna! I do Magento things 6 years of Magento, PHP since 2004 I love IT & Information Security Magento Security Best Practises, anyone?! I work at E-CONOMIX Magento & Typo3 ❤ Linz, Austria
  • 3. Meet Magento Romania 2016 | @rescueAnn What this talk is all about: ★ XSS ★ Frontend input validation ★ Backend input validation ★ Output escaping
  • 4. Meet Magento Romania 2016 | @rescueAnn Once upon a time...
  • 5. Meet Magento Romania 2016 | @rescueAnn Academic titles - what we expected BA PhD BSc MA DI MSc Mag. MBA Dr. LL.M.
  • 6. Meet Magento Romania 2016 | @rescueAnn Academic titles - what we got
  • 7. Meet Magento Romania 2016 | @rescueAnn XSS is real.
  • 8. Meet Magento Romania 2016 | @rescueAnn index.php?name=Anna<script>alert('XSS');</script>
  • 9. Meet Magento Romania 2016 | @rescueAnn “Cross-Site Scripting (XSS) attacks occur when: 1. Data enters a Web application through an untrusted source, most frequently a web request. 2. The data is included in dynamic content that is sent to a web user without being validated for malicious content.” Source: https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)
  • 10. Meet Magento Romania 2016 | @rescueAnn XSS in latest SUPEEs SUPEE-8788 ● 17 vulnerabilities ● 4 XSS (1 high, 4 medium) SUPEE-7405 ● 20 vulnerabilities ● 7 XSS (2 critical, 1 high, 2 medium, 2 low)
  • 11. Meet Magento Romania 2016 | @rescueAnn Every feature adds a risk. ⬇ Every input/output adds a risk.
  • 12. Meet Magento Romania 2016 | @rescueAnn Input ⬇ Process ⬇ Output
  • 13. Meet Magento Romania 2016 | @rescueAnnSource: http://transferready.co.uk/index.php/blog/function-machines/
  • 14. Meet Magento Romania 2016 | @rescueAnnSource: http://transferready.co.uk/index.php/blog/function-machines/
  • 15. Meet Magento Romania 2016 | @rescueAnn e-mail address password Logged in customer
  • 16. Meet Magento Romania 2016 | @rescueAnn Security-Technology, Department of Defense Computer Security Initiative, 1980
  • 17. Meet Magento Romania 2016 | @rescueAnn Stop “Last Minute Security” Do the coding, spend last X hours on „making it secure“ Secure coding doesn't really take longer Data quality ⇔ software quality ⇔ security Always keep security in mind.
  • 18. Meet Magento Romania 2016 | @rescueAnn Source: http://blogs.technet.com/b/rhalbheer/archive/2011/01/14/real-physical-security.aspx
  • 19. Meet Magento Romania 2016 | @rescueAnn Input
  • 20. Meet Magento Romania 2016 | @rescueAnn Frontend input validation ● User experience ● Stop unwanted input when it occurs ● Do not bother your server with crazy input requests Don't fill up your database with garbage.
  • 21. Meet Magento Romania 2016 | @rescueAnn Magento Frontend Validation Magento 1 (51 validation rules) js/prototype/validation.js Magento 2 (74 validation rules) app/code/Magento/Ui/view/base/web/js /lib/validation/rules.js
  • 22. Meet Magento Romania 2016 | @rescueAnn app/code/Magento/Ui/ view/base/web/js/lib/ validation/rules.js M 2
  • 23. Meet Magento Romania 2016 | @rescueAnn app/code/Magento/Ui/view/base/web/js/lib/ validation/rules.js min_text_length max_text_length max-words min-words range-words letters-with-basic-punc alphanumeric letters-only no-whitespace zip-range integer vinUS dateITA dateNL time time12h phoneUS phoneUK mobileUK stripped-min-length email2 url2 credit-card-types ipv4 ipv6 pattern validate-no-html-tags validate-select validate-no-empty validate-alphanum-with-spaces validate-data validate-street validate-phoneStrict validate-phoneLax validate-fax validate-email validate-emailSender validate-password validate-admin-password validate-url validate-clean-url validate-xml-identifier validate-ssn validate-zip-us validate-date-au validate-currency-dollar validate-not-negative-number validate-zero-or-greater validate-greater-than-zero validate-css-length validate-number validate-number-range validate-digits validate-digits-range validate-range validate-alpha validate-code validate-alphanum validate-date validate-identifier validate-zip-international validate-state less-than-equals-to greater-than-equals-to validate-emails validate-cc-number validate-cc-ukss required-entry checked not-negative-amount validate-per-page-value-list validate-new-password validate-item-quantity equalTo M 2
  • 24. Meet Magento Romania 2016 | @rescueAnn Add your own validator define([ 'jquery', 'jquery/ui', 'jquery/validate', 'mage/translate' ], function ($) { $.validator.addMethod('validate-custom-name', function (value) { return (value !== 'anna'); }, $.mage.__('Enter valid name')); }); M 2
  • 25. Meet Magento Romania 2016 | @rescueAnn <form> <div class="field required"> <input type="email" id="email_address" data-validate="{required:true, 'validate-email':true}" aria-required="true"> </div> </form> Adding frontend-validation M 2
  • 26. Meet Magento Romania 2016 | @rescueAnn Bonus
  • 27. Meet Magento Romania 2016 | @rescueAnn <form> <div class="field required"> <input type="email" id="email_address" data-validate="{required:true, 'validate-email':true}" aria-required="true"> </div> </form> Adding frontend-validation M 2
  • 28. Meet Magento Romania 2016 | @rescueAnnSource: https://quadhead.de/cola-hack-sicherheitsluecke-auf-meinecoke-de/ Why frontend validation is not enough...
  • 29. Meet Magento Romania 2016 | @rescueAnn Don’t trust the user. Don’t trust the input!
  • 30. Meet Magento Romania 2016 | @rescueAnn
  • 31. Meet Magento Romania 2016 | @rescueAnn EAV Backend validation input rules Magento 1 Mage_Eav_Attribute_Data_Abstract Magento 2 MagentoEavModelAttributeDataAbstractData
  • 32. Meet Magento Romania 2016 | @rescueAnn MagentoEavModelAttributeDataAbstractData Input Validation Rules: ● alphanumeric ● numeric ● alpha ● email ● url ● date M 2
  • 33. Meet Magento Romania 2016 | @rescueAnn ZendValidator Standard Validation Classes Alnum Validator Alpha Validator Barcode Validator Between Validator Callback Validator CreditCard Validator Date Validator DbRecordExists and DbNoRecordExists Validators Digits Validator EmailAddress Validator File Validation Classes GreaterThan Validator Hex Validator Hostname Validator Iban Validator Identical Validator InArray Validator Ip Validator Isbn Validator IsFloat IsInt LessThan Validator NotEmpty Validator PostCode Validator Regex Validator Sitemap Validators Step Validator StringLength Validator Timezone Validator Uri Validator
  • 34. Meet Magento Romania 2016 | @rescueAnn Output
  • 35. Meet Magento Romania 2016 | @rescueAnn Is input validation not enough?!
  • 36. Meet Magento Romania 2016 | @rescueAnn Magento 2 Templates XSS security
  • 37. Meet Magento Romania 2016 | @rescueAnn getXXXHtml() <?php echo $block->getTitleHtml() ?> <?php echo $block->getHtmlTitle() ?> <?php echo $block->escapeHtml($block->getTitle()) ?> M 2 Magento 2 Templates XSS security
  • 38. Meet Magento Romania 2016 | @rescueAnn Type casting and PHP function count() <h1><?php echo (int)$block->getId() ?></h1> <?php echo count($var); ?> M 2 Magento 2 Templates XSS security
  • 39. Meet Magento Romania 2016 | @rescueAnn Output in single or double quotes <?php echo 'some text' ?> <?php echo "some text" ?> M 2 Magento 2 Templates XSS security
  • 40. Meet Magento Romania 2016 | @rescueAnn Use specific escape functions <a href="<?php echo $block->escapeXssInUrl( $block->getUrl()) ?>"> <?php echo $block->getAnchorTextHtml() ?> </a> M 2 Magento 2 Templates XSS security
  • 41. Meet Magento Romania 2016 | @rescueAnn Use these. Also Magento does it! $block->escapeHtml() $block->escapeQuote() $block->escapeUrl() $block->escapeXssInUrl() M 2
  • 42. Meet Magento Romania 2016 | @rescueAnn $block->escapeHtml() Whitelist: allowed Tags, htmlspecialchars M 2
  • 43. Meet Magento Romania 2016 | @rescueAnn MagentoFrameworkEscaper M 2
  • 44. Meet Magento Romania 2016 | @rescueAnn $block->escapeHtml() Whitelist: allowed Tags, htmlspecialchars $block->escapeQuote() Escape quotes inside html attributes $addSlashes = false for escaping js inside html attribute (onClick, onSubmit etc) M 2
  • 45. Meet Magento Romania 2016 | @rescueAnn $block->escapeUrl() Escape HTML entities in URL (htmlspecialchars) $block->escapeXssInUrl() eliminating 'javascript' + htmlspecialchars M 2
  • 46. Meet Magento Romania 2016 | @rescueAnn
  • 47. Meet Magento Romania 2016 | @rescueAnn Testing
  • 48. Meet Magento Romania 2016 | @rescueAnn Static XSS Test XssPhtmlTemplateTest.php in devtestsstatictestsuiteMagentoT estPhp See http://devdocs.magento.com/guides/v2.0/frontend-dev -guide/templates/template-security.html
  • 49. Meet Magento Romania 2016 | @rescueAnn $ magento dev:tests:run static
  • 50. Meet Magento Romania 2016 | @rescueAnn $ magento dev:tests:run static
  • 51. Meet Magento Romania 2016 | @rescueAnn What happened to the little attribute?!
  • 52. Meet Magento Romania 2016 | @rescueAnn Weird customers and customer data was removed Frontend validation added - Dropdown (whitelist) would have been an option too Server side validation added Output escaped
  • 53. Meet Magento Romania 2016 | @rescueAnn Summary Think, act and design your software responsibly: 1. Client side validation 2. Server side validation 3. UTF-8 all the way 4. Escape at point of use 5. Use & run tests
  • 54. Meet Magento Romania 2016 | @rescueAnn Questions? Right here, right now or later @resueAnn