SlideShare a Scribd company logo
Cracking the Code to
Secure Software
@DanielDeogun @DanielSawano
Prague, 19-20 October 2017
@DanielDeogun @DanielSawano #SecureByDesign
Daniel Deogun Daniel Sawano
@DanielDeogun @DanielSawano #SecureByDesign
What’s Cracking the Code… all about?
“A mindset and strategy for creating secure
software by focusing on good design”
- Secure by Design
@DanielDeogun @DanielSawano #SecureByDesign
What we’ll cover today
Solve a real security problem using good design
Immutable mutability
Detecting accidental leakage of sensitive data
@DanielDeogun @DanielSawano #SecureByDesign
Case 1: Cross Site Scripting (XSS)
Some website
Webform
Phone #
Input:
+46 8 545 106 90
or
<script>alert(“XSS”)</script>
@DanielDeogun @DanielSawano #SecureByDesign
Stored XSS
<script>alert(“XSS”)</script>
Alert
@DanielDeogun @DanielSawano #SecureByDesign
Reflective XSS
<script>alert(“XSS”)</script>
Reflective XSS
Alert
IllegalArgumentException(“<script>alert(“XSS”)</script>”)
@DanielDeogun @DanielSawano #SecureByDesign
Technical Analysis
“Phone number” isn’t escaped properly when rendered
on the website – hence, it gets interpreted as code!
<script>alert(“XSS”)</script>
Alert
<script>alert(“XSS”)</script>
@DanielDeogun @DanielSawano #SecureByDesign
Technical Solution
Escape phone number so it can be rendered as text
<script>alert(“XSS”)</script>
&lt;script&gt;alert(&ldquo;XSS&rdquo;)&lt;/script&gt;
<script>alert(“XSS”)</script>
@DanielDeogun @DanielSawano #SecureByDesign
Case 2: Buying -1 books
[1]
1 Secure by Design $49.99
-1 Hamlet $40.50
1 Hitchhiker's Guide to the Galaxy $30.00
Shopping Cart
Total $39.49
@DanielDeogun @DanielSawano #SecureByDesign
Analysis
-1 : Integer
-1 : Integer
OrderLine {ISBN, -1}
Math Context
Webshop Context
@DanielDeogun @DanielSawano #SecureByDesign
But Quantity isn’t an integer…
Integers form an Abelian Group
• Closure: a + b = integer
• Associativity: a + (b + c) = (a + b) + c
• Commutativity: a + b = b + a
• Identity: a + 0 = a
• Inverse: a + (−a) = 0
Quantity
• a concept that’s well defined
with strict boundaries
• not closed under addition
• cannot be negative
@DanielDeogun @DanielSawano #SecureByDesign
Domain Primitives
“A value object so precise in its definition that it, by its mere
existence, manifests its validity is called a Domain Primitive.”
- Secure by Design
• Building block that’s native to your domain
• Valid in the current context
• Immutable and resemble a value object in DDD
@DanielDeogun @DanielSawano #SecureByDesign
Quantity as a Domain Primitive
public final class Quantity {
private final int value;
public Quantity(final int value) {
inclusiveBetween(1, 99, value);
this.value = value;
}
//Domain specific quantity operations...
}
@DanielDeogun @DanielSawano #SecureByDesign
Invalid quantities are rejected
-1 : Integer
Quantity: {1 - 99}
OrderLine {ISBN, Quantity}
Math Context
Webshop Context
Only valid quantities are
accepted
Rejected
@DanielDeogun @DanielSawano #SecureByDesign
Domain Primitives
tighten your design
Domain Primitives tighten your design by
explicitly stating requirements and assumptions.
They also make it harder to inject data that
doesn’t meet the expectations.
Let’s see if this pattern allows us to address XSS
attacks implicitly.
@DanielDeogun @DanielSawano #SecureByDesign
We want to prevent invalid
phone numbers…
Webform
Phone #
Input:
+46 8 545 106 90
or
<script>alert(“XSS”)</script>
Alert
public void register(final String phoneNumber) {
// Register phone number logic
}
@DanielDeogun @DanielSawano #SecureByDesign
But String Accepts Anything!
Input:
+46 8 545 106 90
or
<script>alert(“XSS”)</script>
public void register(final String phoneNumber) {
// Register phone number logic
}
Could be anything!
Attackers look at this
Developers mostly look at this to
understand the intention
@DanielDeogun @DanielSawano #SecureByDesign
Use a Domain Primitive Instead
Input:
+46 8 545 106 90
or
<script>alert(“XSS”)</script>
public void register(final PhoneNumber phoneNumber) {
// Register phone number logic
}
Can only be valid phone numbers
by definition!
ü
@DanielDeogun @DanielSawano #SecureByDesign
Domain Primitives prevent XSS
The PhoneNumber domain primitive enforce domain rule validation at
creation time.
This reduces the attack vector to data that meets the rules in the
context where it’s used.
<script>alert(“XSS”)</script> doesn’t meet the rules and
rejected by design.
But what about escaping – do we need it?
@DanielDeogun @DanielSawano #SecureByDesign
But…
[5
… what about performance?
[3
… it becomes a lot of classes!
… isn’t it overly complex?
[4
@DanielDeogun @DanielSawano #SecureByDesign
What we’ll cover today
Solve a real security problem using good design
Immutable mutability
Detecting accidental leakage of sensitive data
ü
@DanielDeogun @DanielSawano #SecureByDesign
CIA
Confidentiality – data must only be disclosed to authorized users
Integrity – data modification is only allowed in an authorized manner
Availability – data must be available when needed
[
@DanielDeogun @DanielSawano #SecureByDesign
Availability and Mutable State
Mutable state makes it difficult to apply horizontal scaling of
an application.
Ensuring availability along with mutable state is hard.
So, is there a design pattern that both facilitates availability
and mutability?
@DanielDeogun @DanielSawano #SecureByDesign
Design Stereotypes in DDD
Value objects are immutable objects that don’t have a conceptual
identity – we only care about its value, e.g. a business card or a $100 bill.
We replace value objects with Domain Primitives to make them secure.
Entities are objects that aren’t identified by their attributes, but rather by
their identity and lifespan – for example, a customer or a court case.
@DanielDeogun @DanielSawano #SecureByDesign
How should we represent
an Order?
An order may change state
(open, closed, paid, etc).
Should it be an entity or
domain primitive?
How can we solve the
problems that comes with
mutability?
1 Secure by Design $49.99
1 Hamlet $40.50
1 Hitchhiker's Guide to the Galaxy $30.00
Shopping Cart
Total $120.49
@DanielDeogun @DanielSawano #SecureByDesign
Entity Snapshots
Entities are often mutable by design, but we don’t need to implement it
as a mutable object in code.
If we separate mutating operations from read operations, the
representation of an entity can be immutable.
This makes the entity “look” like a Domain Primitive that facilitate
availability and scalability!
@DanielDeogun @DanielSawano #SecureByDesign
Order as an Entity Snapshot
Entity Snapshot
Entity Snapshots
Change Entity
OrderUpdateServiceOrderReadService
@DanielDeogun @DanielSawano #SecureByDesign
But…
[5]
… what about performance? … isn’t it overly complex?
[4]
@DanielDeogun @DanielSawano #SecureByDesign
Entity Snapshots
- Removes many of the issues with mutable state such as
- Availability
- Consistency
- Gets all benefits from Domain Primitives
@DanielDeogun @DanielSawano #SecureByDesign
What we’ll cover today
Solve a real security problem using good design
Immutable mutability
Detecting accidental leakage of sensitive data
ü
ü
@DanielDeogun @DanielSawano #SecureByDesign
Accidental Leakage
Typical causes:
• Logs
• Session persistence
• Evolving domain model
@DanielDeogun @DanielSawano #SecureByDesign
Evolving domain model
User
- name
- nickname
- age
User
- name
- nickname
- age
- SSN
Remodeling
@DanielDeogun @DanielSawano #SecureByDesign
Read-once Object
public final class SensitiveValue implements Externalizable {
private transient final AtomicReference<String> value;
public SensitiveValue(final String value) {
// Check domain-specific invariants
this.value = new AtomicReference<>(value);
}
public String value() {
return notNull(value.getAndSet(null), "Sensitive value has already been consumed");
}
@Override
public String toString() {
return "SensitiveValue{value=*****}";
}
@Override
public void writeExternal(final ObjectOutput out) {
throw new UnsupportedOperationException("Not allowed on sensitive value");
}
@Override
public void readExternal(final ObjectInput in) {
throw new UnsupportedOperationException("Not allowed on sensitive value");
}
}
@DanielDeogun @DanielSawano #SecureByDesign
What we’ll cover today
Solve a real security problem using good design
Immutable mutability
Detecting accidental leakage of sensitive data
ü
ü
ü
@DanielDeogun @DanielSawano #SecureByDesign
Summary
Many security weaknesses can be avoided using Secure by Design
- Domain Primitives
- significantly reduce the attack surface
- facilitate security in depth
- reduce the risk of injection attacks
- Read-once objects
- detects accidental data leakage
- Entity Snapshot
- immutable
- takes on similar properties of a domain primitive
- facilitate availability and scalability
@DanielDeogun @DanielSawano #SecureByDesign
bit.ly/secure-by-design
48% E-book Discount Code for GeeCon! sbdgc17
@DanielDeogun @DanielSawano #SecureByDesign
QA
[2]
@DanielDeogun @DanielSawano #SecureByDesign
References
• [1] https://www.flickr.com/photos/stewart/461099066 by Stewart Butterfield under license https://creativecommons.org/licenses/by/2.0/
• [2] https://flic.kr/p/9ksxQa https://creativecommons.org/licenses/by-nc-nd/2.0/
• [3] https://flic.kr/p/2pvb2T https://creativecommons.org/licenses/by/2.0/
• [4] https://flic.kr/p/7Ro4HU https://creativecommons.org/licenses/by/2.0/
• [5] https://flic.kr/p/eGYhMw https://creativecommons.org/licenses/by/2.0/
• [6] CIA, https://goo.gl/images/DRzRcp

More Related Content

PDF
Public key Infrastructure (PKI)
PDF
Jdbc 7
PPTX
Introduction to Public Key Infrastructure
PPT
Cryptography Simplified - Symmetric Key, Public Key, PKI, Digital Signature, ...
PPTX
How to design a digital signature in odoo
PPTX
Digital certificates and information security
PDF
Understanding Digital Certificates & Secure Sockets Layer
PDF
PKI Industry growth in Bangladesh
Public key Infrastructure (PKI)
Jdbc 7
Introduction to Public Key Infrastructure
Cryptography Simplified - Symmetric Key, Public Key, PKI, Digital Signature, ...
How to design a digital signature in odoo
Digital certificates and information security
Understanding Digital Certificates & Secure Sockets Layer
PKI Industry growth in Bangladesh

Similar to GeeCon Prague 2017 - Cracking the Code to Secure Software (20)

PDF
Secure by Design - Jfokus 2018 tutorial
PDF
Making Software Secure by Design
PDF
Designing software with security in mind
PDF
Designing software with security in mind?
PDF
Fighting security trolls_with_high-quality_mindsets
PDF
Domain Primitives in Action - DataTjej 2018
PDF
DevDays LT 2017 - Secure by Design
PDF
Devoxx PL 2017 - Cracking the Code to Secure Software
PDF
Domain Primitives In Action - Explore DDD 2017
PPTX
501 ch 7 advanced attacks
PDF
Secure code
ODP
CISSP Week 13
PDF
Importance of Secure Coding with it’s Best Practices
PPT
Lecture 2 - Security Requirments.ppt
PDF
Data security in the age of GDPR – most common data security problems
PDF
The Principles of Secure Development - BSides Las Vegas 2009
PPTX
MobileDBSecurity.pptx
PDF
Protecting web apps
PDF
Domain driven security_java_zone2016
PPTX
Security engineering
Secure by Design - Jfokus 2018 tutorial
Making Software Secure by Design
Designing software with security in mind
Designing software with security in mind?
Fighting security trolls_with_high-quality_mindsets
Domain Primitives in Action - DataTjej 2018
DevDays LT 2017 - Secure by Design
Devoxx PL 2017 - Cracking the Code to Secure Software
Domain Primitives In Action - Explore DDD 2017
501 ch 7 advanced attacks
Secure code
CISSP Week 13
Importance of Secure Coding with it’s Best Practices
Lecture 2 - Security Requirments.ppt
Data security in the age of GDPR – most common data security problems
The Principles of Secure Development - BSides Las Vegas 2009
MobileDBSecurity.pptx
Protecting web apps
Domain driven security_java_zone2016
Security engineering
Ad

More from Daniel Sawano (12)

PDF
Devoxx PL 2016 - Beyond Lambdas, the Aftermath
PDF
GeeCon 2016 - Beyond Lambdas, the Aftermath
PDF
Spotify 2016 - Beyond Lambdas - the Aftermath
PDF
JDays 2016 - Beyond Lambdas - the Aftermath
PDF
JFokus 2016 - Beyond Lambdas - the Aftermath
PDF
Devoxx, MA, 2015, Failing Continuous Delivery
PDF
Failing Continuous Delivery, Agile Prague 2015
PDF
Failing Continuous Delivery, Devoxx Poland, 2015
PDF
Things Every Professional Programmer Should Know
PDF
Failing Continuous Delivery, JDays, 2015
PDF
Akka Made Our Day
PDF
Reactive Programming With Akka - Lessons Learned
Devoxx PL 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the Aftermath
Spotify 2016 - Beyond Lambdas - the Aftermath
JDays 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the Aftermath
Devoxx, MA, 2015, Failing Continuous Delivery
Failing Continuous Delivery, Agile Prague 2015
Failing Continuous Delivery, Devoxx Poland, 2015
Things Every Professional Programmer Should Know
Failing Continuous Delivery, JDays, 2015
Akka Made Our Day
Reactive Programming With Akka - Lessons Learned
Ad

Recently uploaded (20)

PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Nekopoi APK 2025 free lastest update
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
System and Network Administration Chapter 2
PDF
medical staffing services at VALiNTRY
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
Essential Infomation Tech presentation.pptx
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Odoo POS Development Services by CandidRoot Solutions
Operating system designcfffgfgggggggvggggggggg
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Nekopoi APK 2025 free lastest update
Understanding Forklifts - TECH EHS Solution
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
System and Network Administration Chapter 2
medical staffing services at VALiNTRY
Design an Analysis of Algorithms II-SECS-1021-03
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms I-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Which alternative to Crystal Reports is best for small or large businesses.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Essential Infomation Tech presentation.pptx

GeeCon Prague 2017 - Cracking the Code to Secure Software