SlideShare a Scribd company logo
1 of 54
Download to read offline
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

More Related Content

Similar to Secure input and output handling in Magento

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 2017Anna Völkl
 
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...Meet Magento Italy
 
Rasha atta abd elsalam
Rasha atta abd elsalamRasha atta abd elsalam
Rasha atta abd elsalamRasha Atta
 
Max Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMax Yekaterinenko - Magento 2 & Quality
Max Yekaterinenko - Magento 2 & QualityMeet Magento Italy
 
Patch Tuesday Analysis - July 2016
Patch Tuesday Analysis - July 2016Patch Tuesday Analysis - July 2016
Patch Tuesday Analysis - July 2016Ivanti
 
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 2Sergii Shymko
 
PCI Compliance for Hipsters
PCI Compliance for HipstersPCI Compliance for Hipsters
PCI Compliance for HipstersPhillip Jackson
 
Xss mitigation php [Repaired]
Xss mitigation php [Repaired]Xss mitigation php [Repaired]
Xss mitigation php [Repaired]Tinashe Makuti
 
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 strategiesMeet Magento Italy
 
Extension Submission to Marketplace
Extension Submission to MarketplaceExtension Submission to Marketplace
Extension Submission to MarketplaceWagento Kangiya
 
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 FastCatalyst
 
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)vinaikopp
 
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?Mage Titans ES
 
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 10Barry Dorrans
 
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 PHPIgnacio Martín
 
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?Simo Ahava
 
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 AResourcePool
 
Patch Tuesday Analysis - September 2016
Patch Tuesday Analysis - September 2016Patch Tuesday Analysis - September 2016
Patch Tuesday Analysis - September 2016Ivanti
 

Similar to Secure input and output handling in Magento (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
 

Recently uploaded

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 

Recently uploaded (20)

What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 

Secure input and output handling in Magento

  • 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