SlideShare a Scribd company logo
1 of 63
Download to read offline
#DevoxxPL @DanielDeogun
Designing Software with Security in Mind?
Daniel Deogun
Omegapoint
Platinum Sponsors:
About Me
• Daniel Deogun
• Sr Consultant, Omegapoint, Stockholm, Sweden
• Started to play with Java in 1997
• Worked in various domains;
• Medtech
• Telecom
• Gambling
• Web
• Strong advocate of DDD, TDD, and Domain Driven Security
• Passionate about high quality software and design
Hypothesis
“Crafting software with good design principles along
with a security mindset, significantly reduces the
number of security flaws in an application.”
- Daniel Deogun
Important Questions
?
Important Questions
?
What distinguishes secure software from insecure software?
Important Questions
How should one treat legacy code?
?
What distinguishes secure software from insecure software?
Important Questions
How should one treat legacy code?
?
What distinguishes secure software from insecure software?
Is it really possible to design secure software?
Important Questions
How should one treat legacy code?
Is security a quality aspect or is quality a security aspect?
?
What distinguishes secure software from insecure software?
Is it really possible to design secure software?
OWASP top 10
A1 - Injection
A2 - Broken Authentication and Session Management
A3 - Cross-Site Scripting (XSS)
A4 - Insecure Direct Object References
A5 - Security Misconfiguration
A6 - Sensitive Data Exposure
A7 - Missing Function Level Access Control
A8 - Cross-Site Request Forgery (CSRF)
A9 - Using Components with Known Vulnerabilities
A10 - Unvalidated Redirects and Forwards
OWASP top 10
A1 - Injection
A3 - Cross-Site Scripting (XSS)
A1 - Injection
“Injection flaws, such as SQL, OS, and LDAP injection occur
when untrusted data is sent to an interpreter as part of a
command or query. The attacker’s hostile data can trick the
interpreter into executing unintended commands or
accessing data without proper authorization.”
- OWASP top 10
Example
Address
Regeringsgatan
Street
56
Number
111 56
ZIP Code
Stockholm
City
Sweden
Country
The Code…
public void register(String street, String number, String zip, String city, String country) {
//do stuff
}
The Code…
public void register(String street, String number, String zip, String city, String country) {
//do stuff
}
Examples of illegal input…
The Code…
public void register(String street, String number, String zip, String city, String country) {
//do stuff
}
Examples of illegal input…
register(“Regeringsgatan”, “56”, “111 56”, “Sweden”, “Stockholm”)
Parameters swapped by mistakeIssue:
The Code…
public void register(String street, String number, String zip, String city, String country) {
//do stuff
}
Examples of illegal input…
register(“Regeringsgatan”, “or 1=1”, null, “Sweden”, “Stockholm”)
Null parameters, SQL injection, illegal dataIssues:
The Code…
public void register(String street, String number, String zip, String city, String country) {
//do stuff
}
Examples of illegal input…
register(StringUtils.repeat("X", 999999999), “56”, “111 56”, “Stockholm”, “Sweden”)
“Unbounded” inputIssue:
Treat it as a
Validation Problem
• Illegal data should be rejected through validation
• White list input validation
• Verify boundary conditions
• Input is validated at each entry point
• Create a strong security barrier
[Bodiam Castle]
Validation Example
public void register(String street, String number, String zip, String city, String country) {
notNull(street);
isTrue(street.length() < 101);
matchesPattern("^[a-zA-Z åäöÅäö]{3,100}$", street);
notNull(number);
isTrue(number.length() < 4);
matchesPattern("^[d]{1,3}[a-zA-Z]?$", number);
notNull(zip);
isTrue(zip.length() < 7);
matchesPattern("^d{5}|(d{3} d{2})$", zip);
//more validation…
addressRepository.add(street + “ “ + number, zip, city, country);
}
Treat it as a
Validation Problem
Upsides
+ Prevent illegal data from being processed
+ Detects illegal data as early as possible
+ Focuses on legal input values
[Bodiam Castle]
Treat it as a
Validation Problem
Upsides
+ Prevent illegal data from being processed
+ Detects illegal data as early as possible
+ Focuses on legal input values
[Bodiam Castle]
Downsides
- Validation and data are separated
- Validation logic is often duplicated
- Tends to focus on structural correctness and ignore invariants
Second Order
Injection Flaw
“An attack vector with structurally correct data
that exploits missing invariant checks between
input parameters or application state”
- Daniel Deogun
Second Order
Injection Flaw
“An attack vector with structurally correct data
that exploits missing invariant checks between
input parameters or application state”
- Daniel Deogun
register(“Regeringsgatan”, “56”, “111 56”, “Gothenburg”, “Sweden”)
Structurally correct but violates city - zip code invariantIssue:
Domain Driven Security
• Founded by Dan Bergh Johnsson and Dr. John Wilander
• Introduced at JavaPolis (later named Devoxx) in 2006
• Brings in the power of Domain Driven Design into the
realm of security
• All input data is mapped to value objects
• Combines structural correctness and invariant checks
• Validation and data are kept together
[Matrix Code]
What’s the Meaning of
the Address Data?
111 56
City reference in ZIP code
Geographical
Location
56
House number
Street name
Country
Conceptual
Address Model
Address
City
StreetName
Number
Country
ZIP Code
Conceptual
Address Model
Address
City
StreetName
Number
Country
ZIP Code
• Invariants
- City must exist in Country
- Street must exist in City
- Building with number must exist on street
- ZIP code and City must match
public void register(String street, String number, String zip, String city, String country) {
notNull(street);
isTrue(street.length() < 101);
matchesPattern("^[a-zA-Z åäöÅäö]{3,100}$", street);
notNull(number);
isTrue(number.length() < 4);
matchesPattern("^[d]{1,3}[a-zA-Z]?$", number);
notNull(zip);
isTrue(zip.length() < 7);
matchesPattern("^d{5}|(d{3} d{2})$", zip);
//more validation…
addressRepository.add(street + “ “ + number, zip, city, country);
}
Modeling Example
Modeling Example
public class ZipCode {
private final String value;
public ZipCode(final String value) {
this.value = validated(value);
}
private static String validated(final String value) {
notNull(value);
isTrue(value.length() < 7);
matchesPattern("^d{5}|(d{3} d{2})$", value);
return value;
}
//methods with domain logic…
}
Modeling Example
public class Address {
private final Street street;
private final BuildingNumber buildingNumber;
private final ZipCode zipCode;
private final City city;
private final Country country;
public Address(final Street street, final BuildingNumber buildingNumber,
final ZipCode zipCode, final City city, final Country country) {
this.street = notNull(street);
this.buildingNumber = notNull(buildingNumber);
this.zipCode = notNull(zipCode);
this.city = notNull(city);
this.country = notNull(country);
validateInvariant(city, country);
validateInvariant(street, city);
validateInvariant(buildingNumber, street);
validateInvariant(zipCode, city);
}
Modeling Example
public void register(final Street street, final BuildingNumber number, final Zip zip,
final City city, final Country country) {
notNull(street);
notNull(number);
notNull(zip);
notNull(city);
notNull(country);
addressRepository.add(new Address(street, number, zip, city, country));
}
Treat it as a
Modeling Problem and use DDS
Upsides
+ Tight coupling between data and validation
+ Promotes white list validation and invariant checks
+ Use of domain objects reduces duplicated validation
+ Helps to prevent second order security weaknesses
Treat it as a
Modeling Problem and use DDS
Upsides
+ Tight coupling between data and validation
+ Promotes white list validation and invariant checks
+ Use of domain objects reduces duplicated validation
+ Helps to prevent second order security weaknesses
Downsides
- Involves business and domain experts
- May seem less flexible
- May cause problems with test data
What About
Prepared Statements?
• Are prepared statements redundant when using validated
domain objects?
Application
What About
Prepared Statements?
• Are prepared statements redundant when using validated
domain objects?
Application
• So, yes we definitely should use prepared statements
when interacting with a persistence context
• Prepared statements separate syntactical constructs and data
A3 - XSS
Cross Site Scripting
“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.”
- OWASP top 10
DDD - Bounded Contexts
Shipping Context
Customer Context
Support Context
DDD - Bounded Contexts
Shipping Context
Customer Context
Support Context
• Bounded context is a central pattern in DDD
• Trying to create one unified model of a large
domain is bound to fail
• Bounded contexts are DDD’s way of dealing with large domains
• Mapping interrelationships between contexts is imperative since it
reveals how data flows in the application
Example - Coder’s Blog
• Let’s say we’re running a website where anyone can ask
questions about code
• Is it possible to avoid XSS?
Example - Coder’s Blog
Stored XSS
<script>alert(’42’)</script> Browser
Stored XSS &
Broken Context Mapping
<script>alert(’42’)</script>
Write Context Read Context
Browser
Preventing XSS
• Context maps reveals how data flows between contexts
• One cannot rely on white list validation since “evil input” is
valid input
• Proper escaping is needed in the read context to prevent
data from the write context to be interpreted as code
The Reactive Manifesto
• The Reactive Manifesto (http://www.reactivemanifesto.org/)
• Reactive Systems are
• Responsive
• Resilient
• Elastic
• Message Driven
Responsive
“The system responds in a timely manner if at all possible. …
Responsive systems focus on providing rapid and consistent
response times, establishing reliable upper bounds so they
deliver a consistent quality of service. …”
Reactive Systems
Resilient
“The system stays responsive in the face of failure. … any
system that is not resilient will be unresponsive after a failure.
Resilience is achieved by replication, containment, isolation
and delegation. Failures are contained within each
component, isolating components from each other and thereby
ensuring that parts of the system can fail and recover without
compromising the system as a whole. …”
Reactive Systems
Reactive Systems
Elastic
“The system stays responsive under varying workload.
Reactive Systems can react to changes in the input rate by
increasing or decreasing the resources allocated to service
these inputs. This implies designs that have no contention
points or central bottlenecks, resulting in the ability to shard
or replicate components and distribute inputs among them. …”
It’s All About Feedback
• The hacker needs feedback
• A system that behaves strangely due to some input reveals its
internal vulnerabilities
• Let’s look at some good craftsmanship patterns…
Circuit Breakers
“Circuit Breaker is the fundamental pattern for protecting your
system from all manner of Integration Points problems.”
- Michael T. Nygard, Release It!, April 2007
Bulkheads
“Bulkheads are effective at maintaining service, or partial service,
even in the face of failures. They are especially useful in service-
oriented architectures, where the loss of a single service could
have repercussions throughout the enterprise.”
- Michael T. Nygard, Release It!, April 2007
Sensitive Value -
One Time Read Only
public final class SensitiveValue {
private final AtomicReference<String> value;
public SensitiveValue(final String value) {
this.value = new AtomicReference<>(validated(value));
}
private static String validated(final String value) {
//Validation of input value
return value;
}
public String value() {
return notNull(value.getAndSet(null), "Sensitive value has already been consumed");
}
@Override
public boolean equals(final Object o) {
throw new UnsupportedOperationException("Not allowed on sensitive value");
}
@Override
public int hashCode() {
throw new UnsupportedOperationException("Not allowed on sensitive value");
}
@Override
public String toString() {
return "SensitiveValue value = *****";
}
}
“Evil” Test
@RunWith(Theories.class)
public class ValueObjectTest {
private interface IllegalValue {String value();}
@DataPoints
public static IllegalValue[] input() {
return new IllegalValue[]{
() -> null,
() -> "",
() -> " ",
() -> "A",
() -> "AA",
() -> " AA ",
() -> "1234567890",
() -> "<script>alert('42')</script>",
() -> "' or '1'='1"
};
}
@Rule
public ExpectedException exception = ExpectedException.none();
@Theory
public void should_be_illegal(final IllegalValue illegal) {
exception.expect(ValidationException.class);
new ValueObject(illegal.value());
}
Stack Traces
java.sql.SQLException: Closed Connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1170)
at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323)
at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:86)
at org.springframework.orm.hibernate.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:529)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransact
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionMana
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAs
Stack Traces
java.sql.SQLException: Closed Connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1170)
at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323)
at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:86)
at org.springframework.orm.hibernate.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:529)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransact
at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionMana
at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAs
Hide It!
Oops!
That’s embarrassing.
We’ve seem to have made an error.
Sorry for the inconvenience…
[Head in Hands]
Legacy Code
[Room in a mess]
Cyclomatic Complexity
• Published in 1976 by Thomas J. McCabe “A Complexity Measure” i
IEEE Transactions on Software Engineering, Vol. SE-2 No. 4
• A measurement of the number of linearly independent paths through a
program's source code.
public void reserveRoomFor(String meeting, String owner, String roomName,
Calendar start, Calendar end, String... invitees) {
final List<Booking> bookings = repository.getBookingsFor(roomName);
if(bookings != null && !bookings.isEmpty()) {
for(Booking booking : bookings) {
if(booking.collidesWith(new Booking(start, end, meeting, roomName, owner))) {
throw new AlreadyReservedException(start, end, roomName, meeting, owner);
}
}
}
repository.store(new Booking(start, end, meeting, roomName, owner));
if(dispatcher == null) {
dispatcher = Platform.instance().eventDispatcher();
}
dispatcher.notify(invitees, new Booking(start, end, meeting, roomName, owner));
}
Cyclomatic Complexity
Cyclomatic Complexity
public void reserveRoomFor(final Meeting meeting, final Room room) {
notNull(meeting);
notNull(room);
repository.store(booking(meeting, room));
dispatcher.notify(meeting.invitees, booking(meeting, room));
}
private Booking booking(final Meeting meeting, final Room room) {
return new Booking(meeting, room);
}
Key Take Aways
• Designing software is difficult
• Security spans across the entire application while development tends to be
from “top to bottom” in an application
• By using good design principles, security becomes a natural part of
development. Not a separate task.
Hypothesis
“Crafting software with good design principles along
with a security mindset, significantly reduces the
number of security flaws in an application.”
- Daniel Deogun
Hypothesis
“Crafting software with good design principles along
with a security mindset, significantly reduces the
number of security flaws in an application.”
- Daniel Deogun
Plausible
Thanks
@DanielDeogun
References
• [Bodiam Castle - https://flic.kr/p/5BjV8] by Phillip Capper under license https://creativecommons.org/licenses/by/2.0/
• [Matrix Code - https://flic.kr/p/2Poor] by David.Asch under license https://creativecommons.org/licenses/by-nc-nd/2.0/
• [OWASP top 10] https://www.owasp.org/index.php/Top_10_2013-Top_10
• [Reactive Manifesto] http://www.reactivemanifesto.org/
• [Head in Hands - https://flic.kr/p/7p7raq] by Alex Proimos under license https://creativecommons.org/licenses/by-nc/2.0/
• [Questions - https://flic.kr/p/9ksxQa] by Damián Navas under license https://creativecommons.org/licenses/by-nc-nd/2.0/
• [Room in a mess - https://flic.kr/p/FSrZU] by yan yan under license https://creativecommons.org/licenses/by/2.0/
• [Historic Log Books - https://flic.kr/p/bjViT7] by PSNH under license https://creativecommons.org/licenses/by-nd/2.0/

More Related Content

What's hot

Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017Omegapoint Academy
 
Practical Cryptography and Security Concepts for Developers
Practical Cryptography and Security Concepts for DevelopersPractical Cryptography and Security Concepts for Developers
Practical Cryptography and Security Concepts for DevelopersGökhan Şengün
 
Steve Jones - Encrypting Data
Steve Jones - Encrypting DataSteve Jones - Encrypting Data
Steve Jones - Encrypting DataRed Gate Software
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesChema Alonso
 
Time-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesTime-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesChema Alonso
 
Time-Based Blind SQL Injection
Time-Based Blind SQL InjectionTime-Based Blind SQL Injection
Time-Based Blind SQL Injectionmatt_presson
 
MongoDB Stich Overview
MongoDB Stich OverviewMongoDB Stich Overview
MongoDB Stich OverviewMongoDB
 
Sql Considered Harmful
Sql Considered HarmfulSql Considered Harmful
Sql Considered Harmfulcoderanger
 
The Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active DirectoryThe Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active DirectoryWill Schroeder
 
SQL Injection Tutorial
SQL Injection TutorialSQL Injection Tutorial
SQL Injection TutorialMagno Logan
 
DDS-Security Interoperability Demo - March 2018
DDS-Security Interoperability Demo - March 2018DDS-Security Interoperability Demo - March 2018
DDS-Security Interoperability Demo - March 2018Gerardo Pardo-Castellote
 
ReCertifying Active Directory
ReCertifying Active DirectoryReCertifying Active Directory
ReCertifying Active DirectoryWill Schroeder
 
Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Max De Marzi
 
Managing your black friday logs - Code Europe
Managing your black friday logs - Code EuropeManaging your black friday logs - Code Europe
Managing your black friday logs - Code EuropeDavid Pilato
 

What's hot (19)

Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017Domain Primitives In Action - Explore DDD 2017
Domain Primitives In Action - Explore DDD 2017
 
Practical Cryptography and Security Concepts for Developers
Practical Cryptography and Security Concepts for DevelopersPractical Cryptography and Security Concepts for Developers
Practical Cryptography and Security Concepts for Developers
 
JWTs and JOSE in a flash
JWTs and JOSE in a flashJWTs and JOSE in a flash
JWTs and JOSE in a flash
 
Steve Jones - Encrypting Data
Steve Jones - Encrypting DataSteve Jones - Encrypting Data
Steve Jones - Encrypting Data
 
Time-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy QueriesTime-Based Blind SQL Injection Using Heavy Queries
Time-Based Blind SQL Injection Using Heavy Queries
 
Time-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy QueriesTime-Based Blind SQL Injection using Heavy Queries
Time-Based Blind SQL Injection using Heavy Queries
 
MisuseCases
MisuseCasesMisuseCases
MisuseCases
 
Time-Based Blind SQL Injection
Time-Based Blind SQL InjectionTime-Based Blind SQL Injection
Time-Based Blind SQL Injection
 
Greensql2007
Greensql2007Greensql2007
Greensql2007
 
MongoDB Stich Overview
MongoDB Stich OverviewMongoDB Stich Overview
MongoDB Stich Overview
 
Sql Considered Harmful
Sql Considered HarmfulSql Considered Harmful
Sql Considered Harmful
 
Not so blind SQL Injection
Not so blind SQL InjectionNot so blind SQL Injection
Not so blind SQL Injection
 
The Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active DirectoryThe Unintended Risks of Trusting Active Directory
The Unintended Risks of Trusting Active Directory
 
SQL Injection Tutorial
SQL Injection TutorialSQL Injection Tutorial
SQL Injection Tutorial
 
DDS-Security Interoperability Demo - March 2018
DDS-Security Interoperability Demo - March 2018DDS-Security Interoperability Demo - March 2018
DDS-Security Interoperability Demo - March 2018
 
ReCertifying Active Directory
ReCertifying Active DirectoryReCertifying Active Directory
ReCertifying Active Directory
 
Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1Neo4j Stored Procedure Training Part 1
Neo4j Stored Procedure Training Part 1
 
2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh2nd-Order-SQLi-Josh
2nd-Order-SQLi-Josh
 
Managing your black friday logs - Code Europe
Managing your black friday logs - Code EuropeManaging your black friday logs - Code Europe
Managing your black friday logs - Code Europe
 

Similar to Designing software with security in mind?

Designing software with security in mind
Designing software with security in mindDesigning software with security in mind
Designing software with security in mindOmegapoint Academy
 
Secure code
Secure codeSecure code
Secure codeddeogun
 
MVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data libertyMVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data libertycsmyth501
 
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data LibertyMVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data Libertycsmyth501
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revisedMongoDB
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessMongoDB
 
Data Privacy with Apache Spark: Defensive and Offensive Approaches
Data Privacy with Apache Spark: Defensive and Offensive ApproachesData Privacy with Apache Spark: Defensive and Offensive Approaches
Data Privacy with Apache Spark: Defensive and Offensive ApproachesDatabricks
 
DevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by DesignDevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by DesignDaniel Sawano
 
Locking the Doors -7 Pernicious Pitfalls to avoid with Java
Locking the Doors -7 Pernicious Pitfalls to avoid with JavaLocking the Doors -7 Pernicious Pitfalls to avoid with Java
Locking the Doors -7 Pernicious Pitfalls to avoid with JavaSteve Poole
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualWerner Keil
 
[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced Features
[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced Features[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced Features
[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced FeaturesAndrew Liu
 
Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...Maxime Beugnet
 
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...MongoDB
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
EclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameEclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameThodoris Bais
 
Domain Driven Security at Internetdagarna-2014
Domain Driven Security at Internetdagarna-2014Domain Driven Security at Internetdagarna-2014
Domain Driven Security at Internetdagarna-2014Dan BerghJohnsson
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?Trisha Gee
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik
 

Similar to Designing software with security in mind? (20)

Designing software with security in mind
Designing software with security in mindDesigning software with security in mind
Designing software with security in mind
 
Coding Security: Code Mania 101
Coding Security: Code Mania 101Coding Security: Code Mania 101
Coding Security: Code Mania 101
 
Secure code
Secure codeSecure code
Secure code
 
MVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data libertyMVP Cloud OS Week Track 1 9 Sept: Data liberty
MVP Cloud OS Week Track 1 9 Sept: Data liberty
 
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data LibertyMVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
MVP Cloud OS Week: 9 Sept, Track 1 Data Liberty
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
 
Data Privacy with Apache Spark: Defensive and Offensive Approaches
Data Privacy with Apache Spark: Defensive and Offensive ApproachesData Privacy with Apache Spark: Defensive and Offensive Approaches
Data Privacy with Apache Spark: Defensive and Offensive Approaches
 
DevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by DesignDevDays LT 2017 - Secure by Design
DevDays LT 2017 - Secure by Design
 
MongoDB 3.0
MongoDB 3.0 MongoDB 3.0
MongoDB 3.0
 
Locking the Doors -7 Pernicious Pitfalls to avoid with Java
Locking the Doors -7 Pernicious Pitfalls to avoid with JavaLocking the Doors -7 Pernicious Pitfalls to avoid with Java
Locking the Doors -7 Pernicious Pitfalls to avoid with Java
 
NoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 VirtualNoSQL Endgame - Java2Days 2020 Virtual
NoSQL Endgame - Java2Days 2020 Virtual
 
[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced Features
[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced Features[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced Features
[PASS Summit 2016] Azure DocumentDB: A Deep Dive into Advanced Features
 
Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...
 
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
EclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL EndgameEclipseCon 2021 NoSQL Endgame
EclipseCon 2021 NoSQL Endgame
 
Domain Driven Security at Internetdagarna-2014
Domain Driven Security at Internetdagarna-2014Domain Driven Security at Internetdagarna-2014
Domain Driven Security at Internetdagarna-2014
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
 
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and GrailsPhilip Stehlik at TechTalks.ph - Intro to Groovy and Grails
Philip Stehlik at TechTalks.ph - Intro to Groovy and Grails
 

More from Omegapoint Academy

Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018Omegapoint Academy
 
Secure by Design - Jfokus 2018 tutorial
Secure by Design - Jfokus 2018 tutorialSecure by Design - Jfokus 2018 tutorial
Secure by Design - Jfokus 2018 tutorialOmegapoint Academy
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Omegapoint Academy
 
Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?Omegapoint Academy
 
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)Omegapoint Academy
 
Studenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - CraftsmanshipStudenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - CraftsmanshipOmegapoint Academy
 
Agile Enterprise: frukostseminarium
Agile Enterprise: frukostseminariumAgile Enterprise: frukostseminarium
Agile Enterprise: frukostseminariumOmegapoint Academy
 

More from Omegapoint Academy (8)

Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018Domain Primitives in Action - DataTjej 2018
Domain Primitives in Action - DataTjej 2018
 
Secure by Design - Jfokus 2018 tutorial
Secure by Design - Jfokus 2018 tutorialSecure by Design - Jfokus 2018 tutorial
Secure by Design - Jfokus 2018 tutorial
 
Designing Testable Software
Designing Testable SoftwareDesigning Testable Software
Designing Testable Software
 
Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015Failing Continuous Delivery, Devoxx Poland, 2015
Failing Continuous Delivery, Devoxx Poland, 2015
 
Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?Studentkonferens 2015 - Alla pratar om risker, men vad är det?
Studentkonferens 2015 - Alla pratar om risker, men vad är det?
 
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
Studentkonferens 2015 1 + 1 = 1 (The Omegapoint Way)
 
Studenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - CraftsmanshipStudenkonferens 2015 - Craftsmanship
Studenkonferens 2015 - Craftsmanship
 
Agile Enterprise: frukostseminarium
Agile Enterprise: frukostseminariumAgile Enterprise: frukostseminarium
Agile Enterprise: frukostseminarium
 

Recently uploaded

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
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
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
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
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
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 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
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
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
 
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
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 

Recently uploaded (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
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...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
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...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
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 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
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
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
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
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
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 

Designing software with security in mind?

  • 1. #DevoxxPL @DanielDeogun Designing Software with Security in Mind? Daniel Deogun Omegapoint Platinum Sponsors:
  • 2. About Me • Daniel Deogun • Sr Consultant, Omegapoint, Stockholm, Sweden • Started to play with Java in 1997 • Worked in various domains; • Medtech • Telecom • Gambling • Web • Strong advocate of DDD, TDD, and Domain Driven Security • Passionate about high quality software and design
  • 3. Hypothesis “Crafting software with good design principles along with a security mindset, significantly reduces the number of security flaws in an application.” - Daniel Deogun
  • 5. Important Questions ? What distinguishes secure software from insecure software?
  • 6. Important Questions How should one treat legacy code? ? What distinguishes secure software from insecure software?
  • 7. Important Questions How should one treat legacy code? ? What distinguishes secure software from insecure software? Is it really possible to design secure software?
  • 8. Important Questions How should one treat legacy code? Is security a quality aspect or is quality a security aspect? ? What distinguishes secure software from insecure software? Is it really possible to design secure software?
  • 9. OWASP top 10 A1 - Injection A2 - Broken Authentication and Session Management A3 - Cross-Site Scripting (XSS) A4 - Insecure Direct Object References A5 - Security Misconfiguration A6 - Sensitive Data Exposure A7 - Missing Function Level Access Control A8 - Cross-Site Request Forgery (CSRF) A9 - Using Components with Known Vulnerabilities A10 - Unvalidated Redirects and Forwards
  • 10. OWASP top 10 A1 - Injection A3 - Cross-Site Scripting (XSS)
  • 11. A1 - Injection “Injection flaws, such as SQL, OS, and LDAP injection occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization.” - OWASP top 10
  • 13. The Code… public void register(String street, String number, String zip, String city, String country) { //do stuff }
  • 14. The Code… public void register(String street, String number, String zip, String city, String country) { //do stuff } Examples of illegal input…
  • 15. The Code… public void register(String street, String number, String zip, String city, String country) { //do stuff } Examples of illegal input… register(“Regeringsgatan”, “56”, “111 56”, “Sweden”, “Stockholm”) Parameters swapped by mistakeIssue:
  • 16. The Code… public void register(String street, String number, String zip, String city, String country) { //do stuff } Examples of illegal input… register(“Regeringsgatan”, “or 1=1”, null, “Sweden”, “Stockholm”) Null parameters, SQL injection, illegal dataIssues:
  • 17. The Code… public void register(String street, String number, String zip, String city, String country) { //do stuff } Examples of illegal input… register(StringUtils.repeat("X", 999999999), “56”, “111 56”, “Stockholm”, “Sweden”) “Unbounded” inputIssue:
  • 18. Treat it as a Validation Problem • Illegal data should be rejected through validation • White list input validation • Verify boundary conditions • Input is validated at each entry point • Create a strong security barrier [Bodiam Castle]
  • 19. Validation Example public void register(String street, String number, String zip, String city, String country) { notNull(street); isTrue(street.length() < 101); matchesPattern("^[a-zA-Z åäöÅäö]{3,100}$", street); notNull(number); isTrue(number.length() < 4); matchesPattern("^[d]{1,3}[a-zA-Z]?$", number); notNull(zip); isTrue(zip.length() < 7); matchesPattern("^d{5}|(d{3} d{2})$", zip); //more validation… addressRepository.add(street + “ “ + number, zip, city, country); }
  • 20. Treat it as a Validation Problem Upsides + Prevent illegal data from being processed + Detects illegal data as early as possible + Focuses on legal input values [Bodiam Castle]
  • 21. Treat it as a Validation Problem Upsides + Prevent illegal data from being processed + Detects illegal data as early as possible + Focuses on legal input values [Bodiam Castle] Downsides - Validation and data are separated - Validation logic is often duplicated - Tends to focus on structural correctness and ignore invariants
  • 22. Second Order Injection Flaw “An attack vector with structurally correct data that exploits missing invariant checks between input parameters or application state” - Daniel Deogun
  • 23. Second Order Injection Flaw “An attack vector with structurally correct data that exploits missing invariant checks between input parameters or application state” - Daniel Deogun register(“Regeringsgatan”, “56”, “111 56”, “Gothenburg”, “Sweden”) Structurally correct but violates city - zip code invariantIssue:
  • 24. Domain Driven Security • Founded by Dan Bergh Johnsson and Dr. John Wilander • Introduced at JavaPolis (later named Devoxx) in 2006 • Brings in the power of Domain Driven Design into the realm of security • All input data is mapped to value objects • Combines structural correctness and invariant checks • Validation and data are kept together [Matrix Code]
  • 25. What’s the Meaning of the Address Data? 111 56 City reference in ZIP code Geographical Location 56 House number Street name Country
  • 27. Conceptual Address Model Address City StreetName Number Country ZIP Code • Invariants - City must exist in Country - Street must exist in City - Building with number must exist on street - ZIP code and City must match
  • 28. public void register(String street, String number, String zip, String city, String country) { notNull(street); isTrue(street.length() < 101); matchesPattern("^[a-zA-Z åäöÅäö]{3,100}$", street); notNull(number); isTrue(number.length() < 4); matchesPattern("^[d]{1,3}[a-zA-Z]?$", number); notNull(zip); isTrue(zip.length() < 7); matchesPattern("^d{5}|(d{3} d{2})$", zip); //more validation… addressRepository.add(street + “ “ + number, zip, city, country); } Modeling Example
  • 29. Modeling Example public class ZipCode { private final String value; public ZipCode(final String value) { this.value = validated(value); } private static String validated(final String value) { notNull(value); isTrue(value.length() < 7); matchesPattern("^d{5}|(d{3} d{2})$", value); return value; } //methods with domain logic… }
  • 30. Modeling Example public class Address { private final Street street; private final BuildingNumber buildingNumber; private final ZipCode zipCode; private final City city; private final Country country; public Address(final Street street, final BuildingNumber buildingNumber, final ZipCode zipCode, final City city, final Country country) { this.street = notNull(street); this.buildingNumber = notNull(buildingNumber); this.zipCode = notNull(zipCode); this.city = notNull(city); this.country = notNull(country); validateInvariant(city, country); validateInvariant(street, city); validateInvariant(buildingNumber, street); validateInvariant(zipCode, city); }
  • 31. Modeling Example public void register(final Street street, final BuildingNumber number, final Zip zip, final City city, final Country country) { notNull(street); notNull(number); notNull(zip); notNull(city); notNull(country); addressRepository.add(new Address(street, number, zip, city, country)); }
  • 32. Treat it as a Modeling Problem and use DDS Upsides + Tight coupling between data and validation + Promotes white list validation and invariant checks + Use of domain objects reduces duplicated validation + Helps to prevent second order security weaknesses
  • 33. Treat it as a Modeling Problem and use DDS Upsides + Tight coupling between data and validation + Promotes white list validation and invariant checks + Use of domain objects reduces duplicated validation + Helps to prevent second order security weaknesses Downsides - Involves business and domain experts - May seem less flexible - May cause problems with test data
  • 34. What About Prepared Statements? • Are prepared statements redundant when using validated domain objects? Application
  • 35. What About Prepared Statements? • Are prepared statements redundant when using validated domain objects? Application • So, yes we definitely should use prepared statements when interacting with a persistence context • Prepared statements separate syntactical constructs and data
  • 36. A3 - XSS Cross Site Scripting “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.” - OWASP top 10
  • 37. DDD - Bounded Contexts Shipping Context Customer Context Support Context
  • 38. DDD - Bounded Contexts Shipping Context Customer Context Support Context • Bounded context is a central pattern in DDD • Trying to create one unified model of a large domain is bound to fail • Bounded contexts are DDD’s way of dealing with large domains • Mapping interrelationships between contexts is imperative since it reveals how data flows in the application
  • 39. Example - Coder’s Blog • Let’s say we’re running a website where anyone can ask questions about code • Is it possible to avoid XSS?
  • 40. Example - Coder’s Blog Stored XSS <script>alert(’42’)</script> Browser
  • 41. Stored XSS & Broken Context Mapping <script>alert(’42’)</script> Write Context Read Context Browser
  • 42. Preventing XSS • Context maps reveals how data flows between contexts • One cannot rely on white list validation since “evil input” is valid input • Proper escaping is needed in the read context to prevent data from the write context to be interpreted as code
  • 43. The Reactive Manifesto • The Reactive Manifesto (http://www.reactivemanifesto.org/) • Reactive Systems are • Responsive • Resilient • Elastic • Message Driven
  • 44. Responsive “The system responds in a timely manner if at all possible. … Responsive systems focus on providing rapid and consistent response times, establishing reliable upper bounds so they deliver a consistent quality of service. …” Reactive Systems
  • 45. Resilient “The system stays responsive in the face of failure. … any system that is not resilient will be unresponsive after a failure. Resilience is achieved by replication, containment, isolation and delegation. Failures are contained within each component, isolating components from each other and thereby ensuring that parts of the system can fail and recover without compromising the system as a whole. …” Reactive Systems
  • 46. Reactive Systems Elastic “The system stays responsive under varying workload. Reactive Systems can react to changes in the input rate by increasing or decreasing the resources allocated to service these inputs. This implies designs that have no contention points or central bottlenecks, resulting in the ability to shard or replicate components and distribute inputs among them. …”
  • 47. It’s All About Feedback • The hacker needs feedback • A system that behaves strangely due to some input reveals its internal vulnerabilities • Let’s look at some good craftsmanship patterns…
  • 48. Circuit Breakers “Circuit Breaker is the fundamental pattern for protecting your system from all manner of Integration Points problems.” - Michael T. Nygard, Release It!, April 2007
  • 49. Bulkheads “Bulkheads are effective at maintaining service, or partial service, even in the face of failures. They are especially useful in service- oriented architectures, where the loss of a single service could have repercussions throughout the enterprise.” - Michael T. Nygard, Release It!, April 2007
  • 50. Sensitive Value - One Time Read Only public final class SensitiveValue { private final AtomicReference<String> value; public SensitiveValue(final String value) { this.value = new AtomicReference<>(validated(value)); } private static String validated(final String value) { //Validation of input value return value; } public String value() { return notNull(value.getAndSet(null), "Sensitive value has already been consumed"); } @Override public boolean equals(final Object o) { throw new UnsupportedOperationException("Not allowed on sensitive value"); } @Override public int hashCode() { throw new UnsupportedOperationException("Not allowed on sensitive value"); } @Override public String toString() { return "SensitiveValue value = *****"; } }
  • 51. “Evil” Test @RunWith(Theories.class) public class ValueObjectTest { private interface IllegalValue {String value();} @DataPoints public static IllegalValue[] input() { return new IllegalValue[]{ () -> null, () -> "", () -> " ", () -> "A", () -> "AA", () -> " AA ", () -> "1234567890", () -> "<script>alert('42')</script>", () -> "' or '1'='1" }; } @Rule public ExpectedException exception = ExpectedException.none(); @Theory public void should_be_illegal(final IllegalValue illegal) { exception.expect(ValidationException.class); new ValueObject(illegal.value()); }
  • 52. Stack Traces java.sql.SQLException: Closed Connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1170) at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323) at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:86) at org.springframework.orm.hibernate.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:529) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransact at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionMana at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAs
  • 53. Stack Traces java.sql.SQLException: Closed Connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208) at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:1170) at org.apache.tomcat.dbcp.dbcp.DelegatingConnection.rollback(DelegatingConnection.java:368) at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.rollback(PoolingDataSource.java:323) at net.sf.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:86) at org.springframework.orm.hibernate.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:529) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransact at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionMana at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAs
  • 54. Hide It! Oops! That’s embarrassing. We’ve seem to have made an error. Sorry for the inconvenience… [Head in Hands]
  • 56. Cyclomatic Complexity • Published in 1976 by Thomas J. McCabe “A Complexity Measure” i IEEE Transactions on Software Engineering, Vol. SE-2 No. 4 • A measurement of the number of linearly independent paths through a program's source code.
  • 57. public void reserveRoomFor(String meeting, String owner, String roomName, Calendar start, Calendar end, String... invitees) { final List<Booking> bookings = repository.getBookingsFor(roomName); if(bookings != null && !bookings.isEmpty()) { for(Booking booking : bookings) { if(booking.collidesWith(new Booking(start, end, meeting, roomName, owner))) { throw new AlreadyReservedException(start, end, roomName, meeting, owner); } } } repository.store(new Booking(start, end, meeting, roomName, owner)); if(dispatcher == null) { dispatcher = Platform.instance().eventDispatcher(); } dispatcher.notify(invitees, new Booking(start, end, meeting, roomName, owner)); } Cyclomatic Complexity
  • 58. Cyclomatic Complexity public void reserveRoomFor(final Meeting meeting, final Room room) { notNull(meeting); notNull(room); repository.store(booking(meeting, room)); dispatcher.notify(meeting.invitees, booking(meeting, room)); } private Booking booking(final Meeting meeting, final Room room) { return new Booking(meeting, room); }
  • 59. Key Take Aways • Designing software is difficult • Security spans across the entire application while development tends to be from “top to bottom” in an application • By using good design principles, security becomes a natural part of development. Not a separate task.
  • 60. Hypothesis “Crafting software with good design principles along with a security mindset, significantly reduces the number of security flaws in an application.” - Daniel Deogun
  • 61. Hypothesis “Crafting software with good design principles along with a security mindset, significantly reduces the number of security flaws in an application.” - Daniel Deogun Plausible
  • 63. References • [Bodiam Castle - https://flic.kr/p/5BjV8] by Phillip Capper under license https://creativecommons.org/licenses/by/2.0/ • [Matrix Code - https://flic.kr/p/2Poor] by David.Asch under license https://creativecommons.org/licenses/by-nc-nd/2.0/ • [OWASP top 10] https://www.owasp.org/index.php/Top_10_2013-Top_10 • [Reactive Manifesto] http://www.reactivemanifesto.org/ • [Head in Hands - https://flic.kr/p/7p7raq] by Alex Proimos under license https://creativecommons.org/licenses/by-nc/2.0/ • [Questions - https://flic.kr/p/9ksxQa] by Damián Navas under license https://creativecommons.org/licenses/by-nc-nd/2.0/ • [Room in a mess - https://flic.kr/p/FSrZU] by yan yan under license https://creativecommons.org/licenses/by/2.0/ • [Historic Log Books - https://flic.kr/p/bjViT7] by PSNH under license https://creativecommons.org/licenses/by-nd/2.0/