Java Web Security Antipatterns

Similar documents
Real World Java Web Security

Sichere Webanwendungen mit Java

Security starts in the head(er)

Sichere Software- Entwicklung für Java Entwickler

How to break in. Tecniche avanzate di pen testing in ambito Web Application, Internal Network and Social Engineering

Using Foundstone CookieDigger to Analyze Web Session Management

Application Security. Petr Křemen.

Web Application Report

Criteria for web application security check. Version

BASELINE SECURITY TEST PLAN FOR EDUCATIONAL WEB AND MOBILE APPLICATIONS

Where every interaction matters.

Enterprise Application Security Workshop Series

Secure development and the SDLC. Presented By Jerry

WEB SECURITY CONCERNS THAT WEB VULNERABILITY SCANNING CAN IDENTIFY

SECURITY DOCUMENT. BetterTranslationTechnology

Kenna Platform Security. A technical overview of the comprehensive security measures Kenna uses to protect your data

Zed E-Commerce and WebCRM 7.5. Release Notes 11/29/2011

MONETA.Assistant API Reference

Session Management in Web Applications

JVA-122. Secure Java Web Development

Magento Security and Vulnerabilities. Roman Stepanov

Pierce County IT Department GIS Division Xuejin Ruan Dan King

Detecting Web Application Vulnerabilities Using Open Source Means. OWASP 3rd Free / Libre / Open Source Software (FLOSS) Conference 27/5/2008

Web Application Security Guidelines for Hosting Dynamic Websites on NIC Servers

Protecting Web Applications and Users

FileCloud Security FAQ

The Top Web Application Attacks: Are you vulnerable?

Web application security

Authentication and Session Management. JIM MANICO Secure Coding Instructor

Web Application Vulnerability Testing with Nessus

What is Web Security? Motivation

Kentico CMS security facts

DISA's Application Security and Development STIG: How OWASP Can Help You. AppSec DC November 12, The OWASP Foundation

Check list for web developers

Application Security Policy

Lecture 11 Web Application Security (part 1)

OWASP AND APPLICATION SECURITY

WHITE PAPER. FortiWeb and the OWASP Top 10 Mitigating the most dangerous application security threats

CrashPlan Security SECURITY CONTEXT TECHNOLOGY

Web Application Security Assessment and Vulnerability Mitigation Tests

! Resident of Kauai, Hawaii

OWASP Top Ten Tools and Tactics

Security vulnerabilities in new web applications. Ing. Pavol Lupták, CISSP, CEH Lead Security Consultant

Web Security - Hardening estudy

Secure Coding in Node.js

Data Breaches and Web Servers: The Giant Sucking Sound

Security features of ZK Framework

Testing the OWASP Top 10 Security Issues

SyncThru TM Web Admin Service Administrator Manual

A detailed walk through a CAS authentication

Managing Data on the World Wide-Web

Web Application Guidelines

Is Drupal secure? A high-level perspective on web vulnerabilities, Drupal s solutions, and how to maintain site security

Members of the UK cyber security forum. Soteria Health Check. A Cyber Security Health Check for SAP systems

Columbia University Web Security Standards and Practices. Objective and Scope

CSE598i - Web 2.0 Security OWASP Top 10: The Ten Most Critical Web Application Security Vulnerabilities

Chapter 7 Transport-Level Security

Ethical Hacking as a Professional Penetration Testing Technique

elearning for Secure Application Development

WEB APPLICATION SECURITY

From the Intranet to Mobile. By Divya Mehra and Stian Thorgersen

NETWORK SECURITY: How do servers store passwords?

Mobile Application Security

FINAL DoIT v.4 PAYMENT CARD INDUSTRY DATA SECURITY STANDARDS APPLICATION DEVELOPMENT AND MAINTENANCE PROCEDURES

The Security of MDM systems. Hack In Paris 2013 Sebastien Andrivet

Certified Secure Web Application Security Test Checklist

Salesforce1 Mobile Security Guide

Passing PCI Compliance How to Address the Application Security Mandates

Sitefinity Security and Best Practices

Web Application Firewall on SonicWALL SRA

SENSE Security overview 2014

Thick Client Application Security

Bug Report. Date: March 19, 2011 Reporter: Chris Jarabek

(WAPT) Web Application Penetration Testing

Dashlane Security Whitepaper

Lecture Notes for Advanced Web Security 2015

Recon and Mapping Tools and Exploitation Tools in SamuraiWTF Report section Nick Robbins

APPLICATION SECURITY AND ITS IMPORTANCE

Semantic based Web Application Firewall (SWAF V 1.6) Operations and User Manual. Document Version 1.0

Out of the Fire - Adding Layers of Protection When Deploying Oracle EBS to the Internet

Annual Web Application Security Report 2011

NetBrain Security Guidance

Securing the SSL/TLS channel against man-in-the-middle attacks: Future technologies - HTTP Strict Transport Security and Pinning of Certs

SECURING SELF-SERVICE PASSWORD RESET

Advanced OpenEdge REST/Mobile Security

SSL BEST PRACTICES OVERVIEW

Web Application Penetration Testing

Application Security Testing. Generic Test Strategy

Attack Vector Detail Report Atlassian

1. Introduction. 2. Web Application. 3. Components. 4. Common Vulnerabilities. 5. Improving security in Web applications

Application Security

3. Broken Account and Session Management. 4. Cross-Site Scripting (XSS) Flaws. Web browsers execute code sent from websites. Account Management

WHITE PAPER FORTIWEB WEB APPLICATION FIREWALL. Ensuring Compliance for PCI DSS 6.5 and 6.6

Network Security Essentials Chapter 5

SESSION IDENTIFIER ARE FOR NOW, PASSWORDS ARE FOREVER

Transcription:

Java Web Security Antipatterns JavaOne 2015 Dominik Schadow bridgingit

Failed with nothing but the best intentions

Architect Implement Maintain

Architect Skipping threat modeling

Software that is secure by design Know the web application Know all external entities Know all data flows Identify all risks

Threat model

Avoid design flaws

Good engineering involves thinking about how things can be made to work; the security mindset involves thinking about how things can be made to fail. It involves thinking like an attacker [ ]. Bruce Schneier www.schneier.com/blog/archives/2008/03/the_security_mi_1.html

Implement User passwords stored as plaintext encrypted trivially hashed

Passw0rd$ d281fdbe0555b913d1c29f99143a3ad7bc66cf83 2e2c68bc1e9187cc6919fcb8564f1483 AKNtqLC_DZM32Jk7pgF4FpRVapo6QFEdROpsflwHkw 2q6rfK2mev4fAQFlRXbH2DecJTYLvF3LMD

Passw0rd$ SHA1 d281fdbe0555b913d1c29f99143a3ad7bc66cf83 2e2c68bc1e9187cc6919fcb8564f1483 AKNtqLC_DZM32Jk7pgF4FpRVapo6QFEdROpsflwHkw 2q6rfK2mev4fAQFlRXbH2DecJTYLvF3LMD

Passw0rd$ SHA1 d281fdbe0555b913d1c29f99143a3ad7bc66cf83 MD5 2e2c68bc1e9187cc6919fcb8564f1483 AKNtqLC_DZM32Jk7pgF4FpRVapo6QFEdROpsflwHkw 2q6rfK2mev4fAQFlRXbH2DecJTYLvF3LMD

Passw0rd$ SHA1 d281fdbe0555b913d1c29f99143a3ad7bc66cf83 MD5 2e2c68bc1e9187cc6919fcb8564f1483 AKNtqLC_DZM32Jk7pgF4FpRVapo6QFEdROpsflwHkw 2q6rfK2mev4fAQFlRXbH2DecJTYLvF3LMD AES

Slow down brute force attacks

PBKDF2 Iterations against brute force attacks Available in plain Java

Demo

bcrypt Iterations against brute force attacks Integrated in Spring Security

@Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public PasswordEncoder passwordencoder() { return new BCryptPasswordEncoder(10); } }

@Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public PasswordEncoder passwordencoder() { return new BCryptPasswordEncoder(10); } }

@Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public PasswordEncoder passwordencoder() { return new BCryptPasswordEncoder(10); } }

@Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Bean public PasswordEncoder passwordencoder() { return new BCryptPasswordEncoder(10); } }

scrypt Memory against brute force attacks Best protection against dictionary attacks

Increase # iterations with faster hardware

Set period of time to change passwords User logs in successfully Period of time expired Calculate new salt Set not changed passwords to null Calculate new hash User tries to log in Update hash & salt Force password reset process

Enforce length limit on password fields

<h:inputsecret id="password" maxlength="1024"> <f:validatelength minimum="10" maximum="1024"/> </h:inputsecret>

<h:inputsecret id="password" maxlength="1024"> <f:validatelength minimum="10" maximum="1024"/> </h:inputsecret>

private byte[] hash(pbekeyspec keyspec) { return secretkeyfactory.generatesecret (keyspec).getencoded(); }

private byte[] hash(pbekeyspec keyspec) { return secretkeyfactory.generatesecret (keyspec).getencoded(); }

Implement Changing password Changing email address

Prevent unintended password change Cross-Site Request Forgery vulnerability Session id knowledge

Implement Disabling pasting passwords Delivering log-in form via HTTP

Disabling pasting into password fields Does not stop any attack Does not provide any more security Does frustrate users

HTTP log in page puts security in jeopardy

Link to dedicated HTTPS log in page

Force HTTPS for the whole page

@WebFilter(urlPatterns = {"/*"}) public class HSTS implements Filter { public void dofilter( ) { HttpServletResponse response = (HttpServletResponse) res; response.addheader( "Strict-Transport-Security", "max-age=31556926"); chain.dofilter(req, response); } // }

@WebFilter(urlPatterns = {"/*"}) public class HSTS implements Filter { public void dofilter( ) { HttpServletResponse response = (HttpServletResponse) res; response.addheader( "Strict-Transport-Security", "max-age=31556926"); chain.dofilter(req, response); } // }

@WebFilter(urlPatterns = {"/*"}) public class HSTS implements Filter { public void dofilter( ) { HttpServletResponse response = (HttpServletResponse) res; response.addheader( "Strict-Transport-Security", "max-age=31556926"); chain.dofilter(req, response); } // }

@WebFilter(urlPatterns = {"/*"}) public class HSTS implements Filter { public void dofilter( ) { HttpServletResponse response = (HttpServletResponse) res; response.addheader( "Strict-Transport-Security", "max-age=31556926"); chain.dofilter(req, response); } // }

@WebFilter(urlPatterns = {"/*"}) public class HSTS implements Filter { public void dofilter( ) { HttpServletResponse response = (HttpServletResponse) res; response.addheader( "Strict-Transport-Security", "max-age=31556926"); chain.dofilter(req, response); } // }

HSTS stops any insecure communication Requires HTTPS connection No effect on HTTP connections All resources via HTTPS Includes scripts, images, Requires valid certificate No self-signed certificates any more

Implement Not logging security events

Logging forensics after an event

Log in and log out is a security event

OWASP Security Logging SECURITY_SUCCESS Successful security check (e.g. successful login) SECURITY_FAILURE Failed security check (e.g. failed login) SECURITY_AUDIT Record security events for audit (e.g. account edited)

Use an always active log level or separate log file

log.warn( SecurityMarkers.SECURITY_AUDIT, "User {} has edited his account, username);

log.warn( SecurityMarkers.SECURITY_AUDIT, "User {} has edited his account, username);

log.warn( SecurityMarkers.SECURITY_AUDIT, "User {} has edited his account, username);

Implement Skipping session configuration Keeping session id after log-in

<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.6</version> <configuration> <failonmissingwebxml> false </failonmissingwebxml> </configuration> </plugin>

<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.6</version> <configuration> <failonmissingwebxml> false </failonmissingwebxml> </configuration> </plugin>

web.xml is a rich source for security configuration

<web-app... version="3.1"> <session-config> <!-- idle timeout after session expires --> <session-timeout>30</session-timeout> <cookie-config> <!-- prevent session id script access --> <http-only>true</http-only> <!-- transfer cookie via https only --> <secure>true</secure> </cookie-config> <!-- session id in cookie, not URL --> <tracking-mode>cookie</tracking-mode> </session-config> </web-app>

<web-app... version="3.1"> <session-config> <!-- idle timeout after session expires --> <session-timeout>30</session-timeout> <cookie-config> <!-- prevent session id script access --> <http-only>true</http-only> <!-- transfer cookie via https only --> <secure>true</secure> </cookie-config> <!-- session id in cookie, not URL --> <tracking-mode>cookie</tracking-mode> </session-config> </web-app>

<web-app... version="3.1"> <session-config> <!-- idle timeout after session expires --> <session-timeout>30</session-timeout> <cookie-config> <!-- prevent session id script access --> <http-only>true</http-only> <!-- transfer cookie via https only --> <secure>true</secure> </cookie-config> <!-- session id in cookie, not URL --> <tracking-mode>cookie</tracking-mode> </session-config> </web-app>

<web-app... version="3.1"> <session-config> <!-- idle timeout after session expires --> <session-timeout>30</session-timeout> <cookie-config> <!-- prevent session id script access --> <http-only>true</http-only> <!-- transfer cookie via https only --> <secure>true</secure> </cookie-config> <!-- session id in cookie, not URL --> <tracking-mode>cookie</tracking-mode> </session-config> </web-app>

<web-app... version="3.1"> <session-config> <!-- idle timeout after session expires --> <session-timeout>30</session-timeout> <cookie-config> <!-- prevent session id script access --> <http-only>true</http-only> <!-- transfer cookie via https only --> <secure>true</secure> </cookie-config> <!-- session id in cookie, not URL --> <tracking-mode>cookie</tracking-mode> </session-config> </web-app>

User usually receives a session id when entering web application

4E01EF46D8446D1C 10CB5C08EDA69DD1

Session hijacking Attacker steals the session id

Session fixation Attacker dictates the session id

Have an always visible logout button

<form th:action="@{/logout}" method="post"> <button type="submit">log out</button> </form>

<form th:action="@{/logout}" method="post"> <button type="submit">log out</button> </form>

<form action="/logout" method="post"> <input type="hidden" name="${_csrf.parametername}" value="${_csrf.token}"/> <input type="submit" value="logout"/> </form>

<form action="/logout" method="post"> <input type="hidden" name="${_csrf.parametername}" value="${_csrf.token}"/> <input type="submit" value="logout"/> </form>

Limit session duration web.xml

Force HTTPS HSTS

Change session id after log in

@WebServlet public class Login extends HttpServlet { protected void dopost(httpservletrequest request, HttpServletResponse response) { //... request.changesessionid(); //... } }

@WebServlet public class Login extends HttpServlet { protected void dopost(httpservletrequest request, HttpServletResponse response) { //... request.changesessionid(); //... } }

@WebServlet public class Login extends HttpServlet { protected void dopost(httpservletrequest request, HttpServletResponse response) { //... request.changesessionid(); //... } }

Invalidate session after log out

@WebServlet public class Logout extends HttpServlet { protected void dopost(httpservletrequest request, HttpServletResponse response) { //... request.getsession().invalidate(); //... } }

@WebServlet public class Logout extends HttpServlet { protected void dopost(httpservletrequest request, HttpServletResponse response) { //... request.getsession().invalidate(); //... } }

Demo

Maintain Using outdated libraries

Frameworks and libraries decline

<reporting> <plugins><plugin> <groupid>org.owasp</groupid> <artifactid>dependency-check-maven</artifactid> <version>1.3.1</version> <reportsets> <reportset> <reports> <report>aggregate</report> </reports> </reportset> </reportsets> </plugin></plugins> </reporting>

Summary

Plan security with threat modeling Think (like an attacker) during implementation Keep 3rd party libraries up-to-date

Enjoy secure programming

Koenigstr. 42 70173 Stuttgart Germany dominik.schadow@bridging-it.de www.bridging-it.de Blog blog.dominikschadow.de Twitter @dschadow Demo Projects github.com/dschadow/javasecurity HTTP Strict Transport Security RFC tools.ietf.org/html/rfc6797 Microsoft Threat Modeling Tool www.microsoft.com/en-us/sdl/adopt/ threatmodeling.aspx Mozilla SeaSponge air.mozilla.org/mozilla-winter-of-securityseasponge-a-tool-for-easy-threat-modeling OWASP Dependency Check www.owasp.org/index.php/ OWASP_Dependency_Check OWASP Security Logging www.owasp.org/index.php/ OWASP_Security_Logging_Project Spring Security projects.spring.io/spring-security Pictures www.dreamstime.com