SlideShare a Scribd company logo
PCICompliancefor
HipstersOr, How I Learned to Stop Worrying and Love
Regulatory Compliance
Phillip Jackson
Magento Practice Lead, Something Digital
1 — ©2016 Philwinkle LLC SunshinePHP 2016
Or, Lots of boring stuff
and
then some Gulp and
Node
2 — ©2016 Philwinkle LLC SunshinePHP 2016
@philwinkle
github.com/philwinkle
3 — ©2016 Philwinkle LLC SunshinePHP 2016
@magetalk
4 — ©2016 Philwinkle LLC SunshinePHP 2016
somethingdigital.com/careers
5 — ©2016 Philwinkle LLC SunshinePHP 2016
1.IfIdon'tstorecredit
cardsPCIdoesn'tapply
6 — ©2016 Philwinkle LLC SunshinePHP 2016
FALSE7 — ©2016 Philwinkle LLC SunshinePHP 2016
ThisiswhyPCIsucks
8 — ©2016 Philwinkle LLC SunshinePHP 2016
Auditssuckmore
9 — ©2016 Philwinkle LLC SunshinePHP 2016
Whatthistalkisabout:
· What is PCI?
· Identifying ways that users and
programmers can break compliance
· Finding problems before they go to
production
· Introducing tools to aide you in your
journey
10 — ©2016 Philwinkle LLC SunshinePHP 2016
Whatthistalkisnot:
· A comprehensive survey of all of PCI
(or any standard)
· Every organization is different
· There is no one-size fits all solution
· Really has nothing to do with hipsters
11 — ©2016 Philwinkle LLC SunshinePHP 2016
PCIisnotalawora
regulation
12 — ©2016 Philwinkle LLC SunshinePHP 2016
Itisastandardcreatedby
majorcreditcardissuers,
banks
13 — ©2016 Philwinkle LLC SunshinePHP 2016
Incaseyou'rebored:
tl;dr don't accept payments you don't
have to do any of this!
14 — ©2016 Philwinkle LLC SunshinePHP 2016
thistalkisabout
toolkits
15 — ©2016 Philwinkle LLC SunshinePHP 2016
theproblemisthere
arenone
16 — ©2016 Philwinkle LLC SunshinePHP 2016
atSDwehaveto
buildthemand
maintainthem
17 — ©2016 Philwinkle LLC SunshinePHP 2016
Aboutme:
· eCommerce developer since ~2000
· Magento Developer since late 2007
· I am not a PCI expert
· I am a lazy developer
18 — ©2016 Philwinkle LLC SunshinePHP 2016
Quickoverviewof
PCI
19 — ©2016 Philwinkle LLC SunshinePHP 2016
Self-governance
20 — ©2016 Philwinkle LLC SunshinePHP 2016
Reviewof12steps
21 — ©2016 Philwinkle LLC SunshinePHP 2016
PCI's12stepprogram1
- Install and maintain firewall
- Don't use vendor-supplied defaults for system passwords and other security parameters
- Protect stored data
- Encrypt the transmission of cardholder data and sensitive information across public networks
- Use and regularly update antivirus software
- Develop and maintain secure systems and applications
- Restrict access to data by business need-to-know
- Assign a unique ID to each person with computer access
- Restrict physical access to cardholder data
- Track and monitor all access to network resources and cardholder data
- Regularly test security systems and processes
- Maintain a policy that addresses information security
1
February 2016 PCI v3.1 https://www.pcisecuritystandards.org/documents/PCIDSSv3-1.pdf
22 — ©2016 Philwinkle LLC SunshinePHP 2016
We'regoingtotalkabout2ofthesetoday
- Protect stored data
- Develop and maintain secure systems and applications
23 — ©2016 Philwinkle LLC SunshinePHP 2016
Protectstoreddata
24 — ©2016 Philwinkle LLC SunshinePHP 2016
Warning:Thisisarabbit
hole
25 — ©2016 Philwinkle LLC SunshinePHP 2016
Whatconstitutes"storeddata"anyways?
Writing things to memory (setting them
in a var) is technically "storing" the
value
26 — ©2016 Philwinkle LLC SunshinePHP 2016
Whatconstitutes"storeddata"anyways?
But it is allowed with specific
provisions:
- It is **not** stored in non-volatile memory (e.g. Hard drive)
OR
- It **is** stored safely depending on the type of data that it is
27 — ©2016 Philwinkle LLC SunshinePHP 2016
Password One-way hash
Credit Card Number Strong
Encryption
CVV Never
28 — ©2016 Philwinkle LLC SunshinePHP 2016
Storeddata:
The entire 15 or 16 digits of a credit
card number
(The last 4 digits of the card is not considered
cardholder data)
Customer authentication credentials
(password, auth key, app id,
biometrics)
29 — ©2016 Philwinkle LLC SunshinePHP 2016
Safestorage
30 — ©2016 Philwinkle LLC SunshinePHP 2016
Safe(Intentional)Storage
The obvious question (in February
2016):
Which algo to use?
OWASP suggests use of PBKDF2, bcrypt
or scrypt for password storage2
Hashes: Use the built-in password_hash algorithm2
Magento stores can use PBKDF2 with a module for drop in encryption replacement via
PHPCryptLib with https://github.com/ikonoshirt/pbkdf2 by @fabian_ikono
31 — ©2016 Philwinkle LLC SunshinePHP 2016
bad:
$password = md5($salt . $_REQUEST['password']);
better:
$password = password_hash($_REQUEST['password']);
32 — ©2016 Philwinkle LLC SunshinePHP 2016
Is this storing the card safely?
$ccNumber = $_GET['cc_number'];
$payment->setCreditCard($ccNumber);
$payment->save();
33 — ©2016 Philwinkle LLC SunshinePHP 2016
A bit better (but increases your
burden):
$ccNumber = $helper->encrypt($_GET['cc_number']);
$payment->setCreditCard($ccNumber);
$payment->save();
34 — ©2016 Philwinkle LLC SunshinePHP 2016
ButIdon'tstore
creditcards?
35 — ©2016 Philwinkle LLC SunshinePHP 2016
Storageeveninvolatile
memoryisstillstorage,
butmaynotviolatePCI.
36 — ©2016 Philwinkle LLC SunshinePHP 2016
There is no way to protect against this
in your application:
$ curl --data "cc_number=4111111111111111" yourawesomesite.com
result:
$_POST['cc_number'] //bullocks
37 — ©2016 Philwinkle LLC SunshinePHP 2016
This is why the standard dictates things
like SSL
...and Antivirus (yes even on your
Production hardware)
38 — ©2016 Philwinkle LLC SunshinePHP 2016
Side note: a WAF (web application
firewall) is invaluable to your
application
ModSecurity is OSS. If you're on AWS
there is a WAF appliance.
39 — ©2016 Philwinkle LLC SunshinePHP 2016
In general don't do this. You increase
your risk and therefore scope. Rather
use methods provided by the bank to
store the card with use of a token.
40 — ©2016 Philwinkle LLC SunshinePHP 2016
Logging
41 — ©2016 Philwinkle LLC SunshinePHP 2016
Proving that developers still have the
power to potentially create risky
scenarios.
class Payment implements PaymentInterface
{
public function authorizeAndCapture(LoggerInterface $logger)
{
//log the request son
$logger->log($_GET);
}
}
42 — ©2016 Philwinkle LLC SunshinePHP 2016
We can guard against those scenarios
using interpolation brute force:
class SuperSafeLogger implements LoggerInterface
{
use PsrLogLoggerTrait;
public function log($level, $message, array $context = array());
{
$message = preg_replace('d{15,16}','****************', $message);
}
}
43 — ©2016 Philwinkle LLC SunshinePHP 2016
Logs usually get backed up or shipped
off to another service for analysis. Is
this transfer done via SSL?
This can create windows of opportunity
to fall out of compliance.
44 — ©2016 Philwinkle LLC SunshinePHP 2016
So we know how to store things that we
expect to contain sensitive data. What
about things that we don't expect to
contain a credit card?
array(3) {
["firstname"]=>
string(7) "Phillip"
["lastname"]=>
string(7) "Jackson"
["address"]=>
array(5) {
["street1"]=>
string(16) "4111111111111111"
["street2"]=>
string(0) "234"
["city"]=>
string(15) "West Palm Beach"
["region"]=>
string(2) "FL"
["postcode"]=>
string(5) "33411"
}
}
45 — ©2016 Philwinkle LLC SunshinePHP 2016
Client-side input validation helps.
In this case we can qualify by using the
inverse of the filter_var to ensure
fields are not numeric:
if(filter_var($street1, FILTER_VALIDATE_INT)){
throw new Exception('!!!!!')
}
46 — ©2016 Philwinkle LLC SunshinePHP 2016
Or, just fix your UX.
47 — ©2016 Philwinkle LLC SunshinePHP 2016
Developingsecuresystems
48 — ©2016 Philwinkle LLC SunshinePHP 2016
This goes beyond just the credit card
data
49 — ©2016 Philwinkle LLC SunshinePHP 2016
At SD we use a number of techniques to
ensure compliance:
· Peer review
· Mentor review
· Scrutinizer
· Unit tests
· Integration tests
50 — ©2016 Philwinkle LLC SunshinePHP 2016
Peerreview
51 — ©2016 Philwinkle LLC SunshinePHP 2016
PCI6.3.2:
#1. Code changes are reviewed by
individuals other than the originating
code author, and by individuals
knowledgeable about code-review
techniques and secure coding
practices.
52 — ©2016 Philwinkle LLC SunshinePHP 2016
PCI6.3.2:
#2. Code reviews ensure code is
developed according to secure coding
guidelines
53 — ©2016 Philwinkle LLC SunshinePHP 2016
PCI6.3.2:
#3. Appropriate corrections are
implemented prior to release.
54 — ©2016 Philwinkle LLC SunshinePHP 2016
PCI6.3.2:
#4. Code-review results are reviewed
and approved by management prior to
release.
55 — ©2016 Philwinkle LLC SunshinePHP 2016
What to focus on in code review?
· Don't trust the user
· Don't trust the programmer
In short, filter in, escape out.
56 — ©2016 Philwinkle LLC SunshinePHP 2016
Filter in
$unsafe = $_GET['unsafe'];
if(!filter_var($unsafe, FILTER_VALIDATE_INT)){
throw new Exception('¯_( )_/¯');
}
$pdo->bind($query, $unsafe);
Escape out
echo $helper->escape($unsafe); //Or just use TWIG.
57 — ©2016 Philwinkle LLC SunshinePHP 2016
In this case filter_var is not just
here for the protection of our
application but for the protection of
the customer.
58 — ©2016 Philwinkle LLC SunshinePHP 2016
XSS59 — ©2016 Philwinkle LLC SunshinePHP 2016
Most XSS attacks come from plain old
run-of-the-mill echoing $_GET
60 — ©2016 Philwinkle LLC SunshinePHP 2016
But honestly peer review can't catch
everything
61 — ©2016 Philwinkle LLC SunshinePHP 2016
IntroducingPHPCS
62 — ©2016 Philwinkle LLC SunshinePHP 2016
PHP CodeSniffer is an invaluable tool
for testing code for common issues but
you need a good set of sniffs to find
code which breaks from best
practice®™
Caution: having the right sniffs is
crucial
63 — ©2016 Philwinkle LLC SunshinePHP 2016
ugly.php:
<?php
//let's introduce an XSS
echo $_GET['unsafe'];
?>
64 — ©2016 Philwinkle LLC SunshinePHP 2016
Output of PHPCS default:
FILE: /Users/pjackson/ugly.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
2 | ERROR | Missing file doc comment
----------------------------------------------------------------------
Time: 47ms; Memory: 3Mb
65 — ©2016 Philwinkle LLC SunshinePHP 2016
I prefer to use the default Magento ECG
ruleset with Magento:
phpcs --standard=vendor/magento-ecg/coding-standard/Ecg/ ugly.php
results in
FILE: /Users/pjackson/Desktop/xss-vuln/ugly.php
----------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
4 | WARNING | Use of echo language construct is discouraged.
4 | ERROR | Direct use of $_GET Superglobal detected.
----------------------------------------------------------------------
Time: 43ms; Memory: 2.75Mb
66 — ©2016 Philwinkle LLC SunshinePHP 2016
Let'shipsterizeit
67 — ©2016 Philwinkle LLC SunshinePHP 2016
IntroducingGulp
68 — ©2016 Philwinkle LLC SunshinePHP 2016
Gulp is a task runner. We use it to
automate all kinds of things.
Specifically to run audit tools to catch
mistakes before they make it up to git.
(Because Scrutinizer is slow !)
69 — ©2016 Philwinkle LLC SunshinePHP 2016
In gulpfile.js:
gulp.task('default', function() {
gulp.watch('src/**/*.php').on('change', function(file) {
gulp.src(file.path)
.pipe(phpcs({
bin: '/usr/local/bin/phpcs',
standard: 'vendor/magento-ecg/coding-standard/Ecg/',
warningSeverity: 0
}))
.pipe(notify());
});
});
70 — ©2016 Philwinkle LLC SunshinePHP 2016
Breakdown
· We create a watch task for all PHP files
· When a PHP file is changed we send
that file to PHPCS
· We run PHPCS with the ECG standard
(mentioned earlier)
· We can optionally choose to use a
system notification on error
71 — ©2016 Philwinkle LLC SunshinePHP 2016
Yes your IDE can do this, too.
72 — ©2016 Philwinkle LLC SunshinePHP 2016
Even better is FloeDesignTechnologies/
phpcs-security-audit:
--------------------------------------------------------------------------------
FOUND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
6 | WARNING | Possible XSS detected with . on echo
73 — ©2016 Philwinkle LLC SunshinePHP 2016
Can your IDE do this?
74 — ©2016 Philwinkle LLC SunshinePHP 2016
IntroducingCasperJS
75 — ©2016 Philwinkle LLC SunshinePHP 2016
CasperJS is a headless Webkit
scriptable with a Javscript API.
Casper is good at navigating pages and
submitting forms.
76 — ©2016 Philwinkle LLC SunshinePHP 2016
XSSSniffing
casper.start('http://127.0.0.1:8080/search.php', function() {
this.fill('form#search', {
'searchTerm': '<script>alert(1);</script>'
}, true);
});
casper.then(function() {
this.evaluateOrDie(function() {
return /<script/.test(document.body.innerText);
}, 'XSS Vulnerability detected');
});
77 — ©2016 Philwinkle LLC SunshinePHP 2016
Putting it all together
78 — ©2016 Philwinkle LLC SunshinePHP 2016
gulp.task('xss', function() {
var casper = require('casper').create();
casper.userAgent('Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36...blahblah');
casper.start();
casper.start('http://127.0.0.1:8080/search.php', function() {
this.fill('form#contact-form', {
'searchTerm': '<script>alert(1);</script>'
}, true);
});
casper.then(function() {
this.evaluateOrDie(function() {
return /<script/.test(document.body.innerText);
}, 'XSS Vulnerability detected');
})
});
79 — ©2016 Philwinkle LLC SunshinePHP 2016
To put this in perspective this can be
the type of break you may not find
through peer review and may only
discover when your PCI audit tool is
running in production.
80 — ©2016 Philwinkle LLC SunshinePHP 2016
Consider this code (don't ever do this):
function request()
{
foreach($_test as $key=>$var){
yield [$var=>$key];
}
}
Later:
foreach(request() as $pairs){
echo $pairs['unsafe'];
}
81 — ©2016 Philwinkle LLC SunshinePHP 2016
Wrappingup
82 — ©2016 Philwinkle LLC SunshinePHP 2016
There are a number of tools in the
frontend ops stack today that can
assist creating secure code.
83 — ©2016 Philwinkle LLC SunshinePHP 2016
PCI Compliant code (or any standards
compliant code) can still be susceptible
to attack.
84 — ©2016 Philwinkle LLC SunshinePHP 2016
Closing
85 — ©2016 Philwinkle LLC SunshinePHP 2016
Q&A86 — ©2016 Philwinkle LLC SunshinePHP 2016
Thankyou!@philwinkle
Slides at github.com/philwinkle/pci-
for-hipsters
https://joind.in/16775
87 — ©2016 Philwinkle LLC SunshinePHP 2016

More Related Content

PCI Compliance for Hipsters

  • 1. PCICompliancefor HipstersOr, How I Learned to Stop Worrying and Love Regulatory Compliance Phillip Jackson Magento Practice Lead, Something Digital 1 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 2. Or, Lots of boring stuff and then some Gulp and Node 2 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 3. @philwinkle github.com/philwinkle 3 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 4. @magetalk 4 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 5. somethingdigital.com/careers 5 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 7. FALSE7 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 8. ThisiswhyPCIsucks 8 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 9. Auditssuckmore 9 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 10. Whatthistalkisabout: · What is PCI? · Identifying ways that users and programmers can break compliance · Finding problems before they go to production · Introducing tools to aide you in your journey 10 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 11. Whatthistalkisnot: · A comprehensive survey of all of PCI (or any standard) · Every organization is different · There is no one-size fits all solution · Really has nothing to do with hipsters 11 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 12. PCIisnotalawora regulation 12 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 14. Incaseyou'rebored: tl;dr don't accept payments you don't have to do any of this! 14 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 15. thistalkisabout toolkits 15 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 16. theproblemisthere arenone 16 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 17. atSDwehaveto buildthemand maintainthem 17 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 18. Aboutme: · eCommerce developer since ~2000 · Magento Developer since late 2007 · I am not a PCI expert · I am a lazy developer 18 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 19. Quickoverviewof PCI 19 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 20. Self-governance 20 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 21. Reviewof12steps 21 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 22. PCI's12stepprogram1 - Install and maintain firewall - Don't use vendor-supplied defaults for system passwords and other security parameters - Protect stored data - Encrypt the transmission of cardholder data and sensitive information across public networks - Use and regularly update antivirus software - Develop and maintain secure systems and applications - Restrict access to data by business need-to-know - Assign a unique ID to each person with computer access - Restrict physical access to cardholder data - Track and monitor all access to network resources and cardholder data - Regularly test security systems and processes - Maintain a policy that addresses information security 1 February 2016 PCI v3.1 https://www.pcisecuritystandards.org/documents/PCIDSSv3-1.pdf 22 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 23. We'regoingtotalkabout2ofthesetoday - Protect stored data - Develop and maintain secure systems and applications 23 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 24. Protectstoreddata 24 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 25. Warning:Thisisarabbit hole 25 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 26. Whatconstitutes"storeddata"anyways? Writing things to memory (setting them in a var) is technically "storing" the value 26 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 27. Whatconstitutes"storeddata"anyways? But it is allowed with specific provisions: - It is **not** stored in non-volatile memory (e.g. Hard drive) OR - It **is** stored safely depending on the type of data that it is 27 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 28. Password One-way hash Credit Card Number Strong Encryption CVV Never 28 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 29. Storeddata: The entire 15 or 16 digits of a credit card number (The last 4 digits of the card is not considered cardholder data) Customer authentication credentials (password, auth key, app id, biometrics) 29 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 30. Safestorage 30 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 31. Safe(Intentional)Storage The obvious question (in February 2016): Which algo to use? OWASP suggests use of PBKDF2, bcrypt or scrypt for password storage2 Hashes: Use the built-in password_hash algorithm2 Magento stores can use PBKDF2 with a module for drop in encryption replacement via PHPCryptLib with https://github.com/ikonoshirt/pbkdf2 by @fabian_ikono 31 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 32. bad: $password = md5($salt . $_REQUEST['password']); better: $password = password_hash($_REQUEST['password']); 32 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 33. Is this storing the card safely? $ccNumber = $_GET['cc_number']; $payment->setCreditCard($ccNumber); $payment->save(); 33 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 34. A bit better (but increases your burden): $ccNumber = $helper->encrypt($_GET['cc_number']); $payment->setCreditCard($ccNumber); $payment->save(); 34 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 35. ButIdon'tstore creditcards? 35 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 37. There is no way to protect against this in your application: $ curl --data "cc_number=4111111111111111" yourawesomesite.com result: $_POST['cc_number'] //bullocks 37 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 38. This is why the standard dictates things like SSL ...and Antivirus (yes even on your Production hardware) 38 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 39. Side note: a WAF (web application firewall) is invaluable to your application ModSecurity is OSS. If you're on AWS there is a WAF appliance. 39 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 40. In general don't do this. You increase your risk and therefore scope. Rather use methods provided by the bank to store the card with use of a token. 40 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 41. Logging 41 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 42. Proving that developers still have the power to potentially create risky scenarios. class Payment implements PaymentInterface { public function authorizeAndCapture(LoggerInterface $logger) { //log the request son $logger->log($_GET); } } 42 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 43. We can guard against those scenarios using interpolation brute force: class SuperSafeLogger implements LoggerInterface { use PsrLogLoggerTrait; public function log($level, $message, array $context = array()); { $message = preg_replace('d{15,16}','****************', $message); } } 43 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 44. Logs usually get backed up or shipped off to another service for analysis. Is this transfer done via SSL? This can create windows of opportunity to fall out of compliance. 44 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 45. So we know how to store things that we expect to contain sensitive data. What about things that we don't expect to contain a credit card? array(3) { ["firstname"]=> string(7) "Phillip" ["lastname"]=> string(7) "Jackson" ["address"]=> array(5) { ["street1"]=> string(16) "4111111111111111" ["street2"]=> string(0) "234" ["city"]=> string(15) "West Palm Beach" ["region"]=> string(2) "FL" ["postcode"]=> string(5) "33411" } } 45 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 46. Client-side input validation helps. In this case we can qualify by using the inverse of the filter_var to ensure fields are not numeric: if(filter_var($street1, FILTER_VALIDATE_INT)){ throw new Exception('!!!!!') } 46 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 47. Or, just fix your UX. 47 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 48. Developingsecuresystems 48 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 49. This goes beyond just the credit card data 49 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 50. At SD we use a number of techniques to ensure compliance: · Peer review · Mentor review · Scrutinizer · Unit tests · Integration tests 50 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 51. Peerreview 51 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 52. PCI6.3.2: #1. Code changes are reviewed by individuals other than the originating code author, and by individuals knowledgeable about code-review techniques and secure coding practices. 52 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 53. PCI6.3.2: #2. Code reviews ensure code is developed according to secure coding guidelines 53 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 54. PCI6.3.2: #3. Appropriate corrections are implemented prior to release. 54 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 55. PCI6.3.2: #4. Code-review results are reviewed and approved by management prior to release. 55 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 56. What to focus on in code review? · Don't trust the user · Don't trust the programmer In short, filter in, escape out. 56 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 57. Filter in $unsafe = $_GET['unsafe']; if(!filter_var($unsafe, FILTER_VALIDATE_INT)){ throw new Exception('¯_( )_/¯'); } $pdo->bind($query, $unsafe); Escape out echo $helper->escape($unsafe); //Or just use TWIG. 57 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 58. In this case filter_var is not just here for the protection of our application but for the protection of the customer. 58 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 59. XSS59 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 60. Most XSS attacks come from plain old run-of-the-mill echoing $_GET 60 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 61. But honestly peer review can't catch everything 61 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 62. IntroducingPHPCS 62 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 63. PHP CodeSniffer is an invaluable tool for testing code for common issues but you need a good set of sniffs to find code which breaks from best practice®™ Caution: having the right sniffs is crucial 63 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 64. ugly.php: <?php //let's introduce an XSS echo $_GET['unsafe']; ?> 64 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 65. Output of PHPCS default: FILE: /Users/pjackson/ugly.php ---------------------------------------------------------------------- FOUND 1 ERROR AFFECTING 1 LINE ---------------------------------------------------------------------- 2 | ERROR | Missing file doc comment ---------------------------------------------------------------------- Time: 47ms; Memory: 3Mb 65 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 66. I prefer to use the default Magento ECG ruleset with Magento: phpcs --standard=vendor/magento-ecg/coding-standard/Ecg/ ugly.php results in FILE: /Users/pjackson/Desktop/xss-vuln/ugly.php ---------------------------------------------------------------------- FOUND 1 ERROR AND 1 WARNING AFFECTING 1 LINE ---------------------------------------------------------------------- 4 | WARNING | Use of echo language construct is discouraged. 4 | ERROR | Direct use of $_GET Superglobal detected. ---------------------------------------------------------------------- Time: 43ms; Memory: 2.75Mb 66 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 67. Let'shipsterizeit 67 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 68. IntroducingGulp 68 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 69. Gulp is a task runner. We use it to automate all kinds of things. Specifically to run audit tools to catch mistakes before they make it up to git. (Because Scrutinizer is slow !) 69 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 70. In gulpfile.js: gulp.task('default', function() { gulp.watch('src/**/*.php').on('change', function(file) { gulp.src(file.path) .pipe(phpcs({ bin: '/usr/local/bin/phpcs', standard: 'vendor/magento-ecg/coding-standard/Ecg/', warningSeverity: 0 })) .pipe(notify()); }); }); 70 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 71. Breakdown · We create a watch task for all PHP files · When a PHP file is changed we send that file to PHPCS · We run PHPCS with the ECG standard (mentioned earlier) · We can optionally choose to use a system notification on error 71 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 72. Yes your IDE can do this, too. 72 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 73. Even better is FloeDesignTechnologies/ phpcs-security-audit: -------------------------------------------------------------------------------- FOUND 1 WARNING(S) AFFECTING 1 LINE(S) -------------------------------------------------------------------------------- 6 | WARNING | Possible XSS detected with . on echo 73 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 74. Can your IDE do this? 74 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 75. IntroducingCasperJS 75 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 76. CasperJS is a headless Webkit scriptable with a Javscript API. Casper is good at navigating pages and submitting forms. 76 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 77. XSSSniffing casper.start('http://127.0.0.1:8080/search.php', function() { this.fill('form#search', { 'searchTerm': '<script>alert(1);</script>' }, true); }); casper.then(function() { this.evaluateOrDie(function() { return /<script/.test(document.body.innerText); }, 'XSS Vulnerability detected'); }); 77 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 78. Putting it all together 78 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 79. gulp.task('xss', function() { var casper = require('casper').create(); casper.userAgent('Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36...blahblah'); casper.start(); casper.start('http://127.0.0.1:8080/search.php', function() { this.fill('form#contact-form', { 'searchTerm': '<script>alert(1);</script>' }, true); }); casper.then(function() { this.evaluateOrDie(function() { return /<script/.test(document.body.innerText); }, 'XSS Vulnerability detected'); }) }); 79 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 80. To put this in perspective this can be the type of break you may not find through peer review and may only discover when your PCI audit tool is running in production. 80 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 81. Consider this code (don't ever do this): function request() { foreach($_test as $key=>$var){ yield [$var=>$key]; } } Later: foreach(request() as $pairs){ echo $pairs['unsafe']; } 81 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 82. Wrappingup 82 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 83. There are a number of tools in the frontend ops stack today that can assist creating secure code. 83 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 84. PCI Compliant code (or any standards compliant code) can still be susceptible to attack. 84 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 85. Closing 85 — ©2016 Philwinkle LLC SunshinePHP 2016
  • 86. Q&A86 — ©2016 Philwinkle LLC SunshinePHP 2016