SlideShare a Scribd company logo
Secure input and output handling - Mage Titans Manchester 2016
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
What this talk is all about:
★ Cross-Site Scripting (XSS)
★ Frontend input validation
★ Backend input validation
★ Output escaping
Once upon a
time...
Academic titles - what we expected
BA PhD
BSc MA
DI MSc
Mag. MBA
Dr. LL.M.
Academic titles - what we got
We were
lucky but...
XSS is real.
index.php?name=Anna
index.php?name=Anna<script>alert('EVIL');</script>
“XSS flaws occur whenever an application takes
untrusted data and sends it to a web browser without
proper validation or escaping. XSS allows attackers to
execute scripts in the victim’s browser which can hijack
user sessions, deface web sites, or redirect the user to
malicious sites.”
Source: https://www.owasp.org/index.php/Category:OWASP_Top_Ten_Project
65%
of all websites globally suffer from XSS
Source: http://security.stackexchange.com/questions/129447/why-does-xss-affect-so-many-websites
XSS in latest SUPEEs
SUPEE-7405
● 20 vulnerabilities
● 7 XSS (2 critical, 1 high, 2
medium, 2 low)
SUPEE-8788
● 17 vulnerabilities
● 4 XSS (1 high, 4 medium)
Every feature adds a risk.
⬇
Every input/output adds a risk.
Input
⬇
Process
⬇
Output
Source: http://transferready.co.uk/index.php/blog/function-machines/
Source: http://transferready.co.uk/index.php/blog/function-machines/
e-mail address
password
Logged in
customer
Security-Technology, Department of Defense
Computer Security Initiative, 1980
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.
Source: http://blogs.technet.com/b/rhalbheer/archive/2011/01/14/real-physical-security.aspx
Input
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.
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
app/code/Magento/Ui/
view/base/web/js/lib/
validation/rules.js
M
2
min_text_length
max_text_length
stripped-min-length
validate-no-html-tags
required-entry
validate-alphanum-with-spaces
validate-email
validate-password
validate-url
validate-number
validate-range
validate-date
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
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
<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
Bonus
<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
Source: https://quadhead.de/cola-hack-sicherheitsluecke-auf-meinecoke-de/
Why frontend validation is not enough...
Don’t trust the user.
Don’t trust the input!
Secure input and output handling - Mage Titans Manchester 2016
EAV Backend validation input rules
Magento 1
Mage_Eav_Attribute_Data_Abstract
Magento 2
MagentoEavModelAttributeDataAbstractData
MagentoEavModelAttributeDataAbstractData
Input Validation Rules:
alphanumeric - numeric - alpha - email - url - date
M
2
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
Output
Is input validation not enough?!
Magento 2 Templates
XSS security
getXXXHtml()
<?php echo $block->getTitleHtml() ?>
<?php echo $block->getHtmlTitle() ?>
<?php echo $block->escapeHtml($block->getTitle()) ?>
M
2
Magento 2 Templates XSS security
Type casting and PHP function count()
<h1><?php echo (int)$block->getId() ?></h1>
<?php echo count($var); ?>
M
2
Magento 2 Templates XSS security
Output in single or double quotes
<?php echo 'some text' ?>
<?php echo "some text" ?>
M
2
Magento 2 Templates XSS security
Use specific escape functions
<a href="<?php echo $block->escapeXssInUrl(
$block->getUrl()) ?>">
<?php echo $block->getAnchorTextHtml() ?>
</a>
M
2
Magento 2 Templates XSS security
Use these. Also Magento does it!
$block->escapeHtml()
$block->escapeQuote()
$block->escapeXssInUrl()
M
2
$block->escapeHtml()
String output that should not contain HTML
M
2
MagentoFrameworkEscaper
/**
* Escape string for HTML context. allowedTags will not be escaped, except
the following: script, img, embed,
* iframe, video, source, object, audio
*
* @param string|array $data
* @param array|null $allowedTags
* @return string|array
*/
public function escapeHtml($data, $allowedTags = null)
{
...
...
}
$block->escapeHtml()
String output that should not contain HTML
$block->escapeXssInUrl() ⇒ $block->escapeUrl()
URL output
$block->escapeQuote()
Escape quotes inside html attributes
M
2
Secure input and output handling - Mage Titans Manchester 2016
Testing
Static XSS Test
XssPhtmlTemplateTest.php in
devtestsstatictestsuiteMagentoTestPhp
See
http://devdocs.magento.com/guides/v2.0/frontend-dev
-guide/templates/template-security.html
$ magento dev:tests:run static
$ magento dev:tests:run static
What happened to the
little attribute?!
Weird customers and customer data was removed
Frontend validation added - Dropdown (whitelist)
would have been an option too
Server side validation added
Output escaped
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
Questions?
Right here, right now
or later @rescueAnn
Thank you! ❤

More Related Content

PPTX
ZeroNights 2018 | I <"3 XSS
PPTX
Anatomy of business logic vulnerabilities
PPTX
Pentesting Modern Web Apps: A Primer
PPTX
Dom based xss
PPTX
Directory Traversal & File Inclusion Attacks
PDF
Tuning TCP and NGINX on EC2
PDF
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
PDF
Magento 2 Design Patterns
ZeroNights 2018 | I <"3 XSS
Anatomy of business logic vulnerabilities
Pentesting Modern Web Apps: A Primer
Dom based xss
Directory Traversal & File Inclusion Attacks
Tuning TCP and NGINX on EC2
X-XSS-Nightmare: 1; mode=attack XSS Attacks Exploiting XSS Filter
Magento 2 Design Patterns

What's hot (20)

PPTX
Cross site scripting
PPTX
ASP.NET Web Security
PDF
Grokking TechTalk #20: PostgreSQL Internals 101
PPTX
Rate limiting
PPTX
Web Application Penetration Testing Introduction
PPTX
Caching
PDF
Spring Framework - AOP
PDF
HTTP Security Headers
PDF
Sql Injection Myths and Fallacies
PDF
Browser Caching
PPTX
Blazor - An Introduction
PPTX
XXE: How to become a Jedi
PDF
Cross Site Scripting Going Beyond the Alert Box
PDF
Modern API Security with JSON Web Tokens
PPTX
Introduction to Microservices Patterns
PPTX
Introduction to path traversal attack
PDF
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
PDF
Caching for Microservices Architectures: Session I
PPTX
Cross site scripting
ASP.NET Web Security
Grokking TechTalk #20: PostgreSQL Internals 101
Rate limiting
Web Application Penetration Testing Introduction
Caching
Spring Framework - AOP
HTTP Security Headers
Sql Injection Myths and Fallacies
Browser Caching
Blazor - An Introduction
XXE: How to become a Jedi
Cross Site Scripting Going Beyond the Alert Box
Modern API Security with JSON Web Tokens
Introduction to Microservices Patterns
Introduction to path traversal attack
C* Summit 2013: The World's Next Top Data Model by Patrick McFadin
Caching for Microservices Architectures: Session I
Ad

Similar to Secure input and output handling - Mage Titans Manchester 2016 (20)

PDF
Secure input and output handling - ViennaPHP
PPTX
04. xss and encoding
PPTX
Hackers versus Developers and Secure Web Programming
PPTX
JavaScript security and tools evolution at 2017 OWASP Taiwan Week
PPT
Developing Secure Applications and Defending Against Common Attacks
DOC
Attackers Vs Programmers
PPT
Penetration Testing Basics
PDF
T04505103106
PDF
Web Application Security
PDF
Owasp top 10_openwest_2019
DOCX
Pantallas escaneo Sitio Web
ODP
OWASP Secure Coding
PDF
Secure input and output handling - Magento Meetup Vienna Edition
PPT
香港六合彩
PPTX
Different types of attacks in internet
KEY
Do it-yourself-audits
PPTX
Application Security Architecture and Threat Modelling
PDF
Input validation errors
PDF
Become a Security Ninja
PDF
Protecting web apps
Secure input and output handling - ViennaPHP
04. xss and encoding
Hackers versus Developers and Secure Web Programming
JavaScript security and tools evolution at 2017 OWASP Taiwan Week
Developing Secure Applications and Defending Against Common Attacks
Attackers Vs Programmers
Penetration Testing Basics
T04505103106
Web Application Security
Owasp top 10_openwest_2019
Pantallas escaneo Sitio Web
OWASP Secure Coding
Secure input and output handling - Magento Meetup Vienna Edition
香港六合彩
Different types of attacks in internet
Do it-yourself-audits
Application Security Architecture and Threat Modelling
Input validation errors
Become a Security Ninja
Protecting web apps
Ad

More from Anna Völkl (8)

PDF
Magento Live UK 2015: Security Essentials Seminar
PDF
Schnell, schön, sicher: Technische Konzeption und Betrieb sicherer E-Commerce...
PDF
Magento Security Best Practises - MM17PL
PDF
Magento Security Best Practises - MM17DE
PDF
Secure development environment @ Meet Magento Croatia 2017
PDF
Secure input and output handling - Meet Magento Romania 2016
PDF
Magento Application Security [EN]
PDF
Magento Application Security [DE]
Magento Live UK 2015: Security Essentials Seminar
Schnell, schön, sicher: Technische Konzeption und Betrieb sicherer E-Commerce...
Magento Security Best Practises - MM17PL
Magento Security Best Practises - MM17DE
Secure development environment @ Meet Magento Croatia 2017
Secure input and output handling - Meet Magento Romania 2016
Magento Application Security [EN]
Magento Application Security [DE]

Recently uploaded (20)

PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
medical staffing services at VALiNTRY
PPTX
ai tools demonstartion for schools and inter college
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administration Chapter 2
PPTX
Transform Your Business with a Software ERP System
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
top salesforce developer skills in 2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
Introduction to Artificial Intelligence
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
L1 - Introduction to python Backend.pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
AI in Product Development-omnex systems
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Operating system designcfffgfgggggggvggggggggg
medical staffing services at VALiNTRY
ai tools demonstartion for schools and inter college
2025 Textile ERP Trends: SAP, Odoo & Oracle
Odoo Companies in India – Driving Business Transformation.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administration Chapter 2
Transform Your Business with a Software ERP System
Upgrade and Innovation Strategies for SAP ERP Customers
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
top salesforce developer skills in 2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Introduction to Artificial Intelligence
Softaken Excel to vCard Converter Software.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
L1 - Introduction to python Backend.pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PTS Company Brochure 2025 (1).pdf.......
AI in Product Development-omnex systems

Secure input and output handling - Mage Titans Manchester 2016