Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Java Web Application Security - Denver JUG 2013


Published on

During this presentation, you'll learn how to implement authentication in your Java web applications using good ol' Java EE 6 Security, Spring Security and Apache Shiro. You'll also learn how to secure your REST API with OAuth and lock it down with SSL.

After learning how to integrate security, I'll show how to use Zed Attack Proxy to pentest your app and fix vulnerabilities.

Published in: Technology

Java Web Application Security - Denver JUG 2013

  1. 1. Java Web Application Security Matt Raible @mraiblePhotos by Trish - © 2013 Raible Designs
  2. 2. Who is Matt Raible? Father, Skier, Cyclist Web Framework ConnoisseurFounder of AppFuse Blogger on © 2013 Raible Designs
  3. 3. Why am I here?Purpose To learn more about Java webapp security and transform myself into a security expert.Goals Show how to implement Java webapp security. Show how to penetrate a Java webapp. Show how to fix vulnerabilities. © 2013 Raible Designs
  4. 4. Why are you here?For the free beer?Because you care aboutsecurity?Have you used Java EE 6,Spring Security or ApacheShiro?What do you want to getfrom this talk? © 2013 Raible Designs
  5. 5. Session AgendaSecurity Development Java EE 6, Spring Security, Apache Shiro SSL and TestingVerifying Security OWASP Top 10 & Zed Attack ProxyCommercial Tools and ServicesConclusion Develop Penetrate Protect Relax © 2013 Raible Designs
  6. 6. Develop © 2013 Raible Designs
  7. 7. Dynamic Language Support?If it deploys on Tomcat, it has a web.xml Grails JRuby on Rails Lift Play! Framework © 2013 Raible Designs
  8. 8. Java EE 6Security constraints defined in web.xml web resource collection - URLs and methods authorization constraints - role names user data constraint - HTTP or HTTPSUser Realm defined by App ServerDeclarative or Programmatic AuthenticationAnnotations Support © 2013 Raible Designs
  9. 9. Java EE 6 Demo © 2013 Raible Designs
  10. 10. Servlet 3.0 HttpServletRequest authenticate(response) login(user, pass) logout() getRemoteUser() isUserInRole(name) © 2013 Raible Designs
  11. 11. Servlet 3.0 and JSR 250Annotations @ServletSecurity @HttpMethodConstraint @HttpConstraint @RolesAllowed @PermitAll @DenyAll © 2013 Raible Designs
  12. 12. Java EE Security Limitations No error messages for failed logins No Remember Me Container has to be configured Doesn’t support regular expressions for URLs © 2013 Raible Designs
  13. 13. Spring Security Filter defined in web.xml Separate security context file loaded by Spring Defines URLs, Roles and Authentication Providers Defines UserService (provided or custom) Password Encoding Remember Me © 2013 Raible Designs
  14. 14. Spring Security Demo © 2013 Raible Designs
  15. 15. Securing Methods<global-method-security secured-annotations="enabled"/> @Secured("IS_AUTHENTICATED_ANONYMOUSLY") public Account readAccount(Long id); @Secured("IS_AUTHENTICATED_ANONYMOUSLY") public Account[] findAccounts(); @Secured("ROLE_TELLER") public Account post(Account account, double amount);<global-method-security jsr250-annotations="enabled"/> © 2013 Raible Designs
  16. 16. Securing Methods 3.x<global-method-security pre-post-annotations="enabled"/> @PreAuthorize("isAnonymous()") public Account readAccount(Long id); @PreAuthorize("isAnonymous()") public Account[] findAccounts(); @PreAuthorize("hasAuthority(ROLE_TELLER)") public Account post(Account account, double amount); © 2013 Raible Designs
  17. 17. Spring Security Limitations Authentication mechanism in WAR Securing methods only works on Spring beans My remember me example doesn’t work © 2013 Raible Designs
  18. 18. Apache ShiroFilter defined in web.xmlshiro.ini loaded from classpath [main], [urls], [roles]CryptographySession Management © 2013 Raible Designs
  19. 19. Apache Shiro Demo © 2013 Raible Designs
  20. 20. Apache Shiro LimitationsLimited DocumentationGetting Roles via LDAPnot supportedNo out-of-box supportfor KerberosREST Support needswork © 2013 Raible Designs
  21. 21. Testing with SSLCargo doesn’t support http andhttps at same timeJetty and Tomcat plugins workfor bothPass & maven-failsafe-plugin as<systemPropertyVariables> © 2013 Raible Designs
  22. 22. Ajax Login © 2013 Raible Designs
  23. 23. Securing a REST APIUse Basic or FormAuthenticationUse Developer KeysUse OAuth © 2013 Raible Designs
  24. 24. OAuth © 2013 Raible Designs
  25. 25. REST Security and OAuth Demo © 2013 Raible Designs
  26. 26. Integrating OAuth with AppFuse and REST © 2013 Raible Designs
  27. 27. REST Security ResourcesImplementing REST Authentication implementing-rest-authentication/Swagger ApiAuthorizationFilter master/samples/java-jaxrs © 2013 Raible Designs
  28. 28. REST Security ResourcesSpring Security OAuth- version 1.0.1Spring Social- version 1.0.2 Facebook, Twitter, LinkedIn, TripIt, and GitHub Bindings © 2013 Raible Designs
  29. 29. PenetrateOWASP Testing Guide and Code Review GuideOWASP Top 10OWASP Zed Attack ProxyBurp SuiteOWASP WebGoat © 2013 Raible Designs
  30. 30. OWASPThe Open Web Application Security Project (OWASP) isa worldwide not-for-profit charitable organizationfocused on improving the security of software.At OWASP you’ll find free and open ... Application security tools, complete books, standard security controls and libraries, cutting edge research © 2013 Raible Designs
  31. 31. Penetration Testing Demo © 2013 Raible Designs
  32. 32. Fixing ZAP Vulnerabilities<session-config> <session-timeout>15</session-timeout> <cookie-config> <http-only>true</http-only> <secure>true</secure> </cookie-config> <tracking-mode>COOKIE</tracking-mode></session-config><form action="${ctx}/j_security_check" id="loginForm" method="post" autocomplete="off"> © 2013 Raible Designs
  33. 33. 7 Security (Mis)Configurationsin web.xml1. Error pages not configured2. Authentication & Authorization Bypass3. SSL Not Configured4. Not Using the Secure Flag © 2013 Raible Designs
  34. 34. 7 Security (Mis)Configurations5. Not Using the HttpOnly Flag6. Using URL Parameters for Session Tracking7. Not Setting a Session Timeout © 2013 Raible Designs
  35. 35. OWASP Top 10 for 20101. Injection2. Cross-Site Scripting (XSS)3. Broken Authentication and Session Management4. Insecure Direct Object References5. Cross-Site Request Forgery (CSRF) © 2013 Raible Designs
  36. 36. OWASP Top 10 for 20106. Security Misconfiguration7. Insecure Cryptographic Storage8. Failure to Restrict URL Access9. Insufficient Transport Layer Protection10.Unvalidated Redirects and Forwards © 2013 Raible Designs
  37. 37. Protect[SWAT] ChecklistFirewallsIDS and IDPsAuditsPenetration TestsCode Reviews with StaticAnalysis Tools © 2013 Raible Designs
  38. 38. © 2013 Raible Designs
  39. 39. Firewalls Stateless Firewalls Stateful Firewalls Invented by Nir Zuk at Check Point in the mid-90s Web App Firewalls Inspired by the 1996 PHF CGI exploit WAF Market $234m in 2010 © 2013 Raible Designs
  40. 40. Gartner on Firewalls © 2013 Raible Designs
  41. 41. Content Security Policy An HTTP Header with whitelist of trusted content Bans inline <script> tags, inline event handlers and javascript: URLs No eval(), new Function(), setTimeout or setInterval Supported in Chrome 16+, Safari 6+, and Firefox 4+, and (very) limited in IE 10 © 2013 Raible Designs
  42. 42. Content Security Policy © 2013 Raible Designs
  43. 43. RelaxWeb App Firewalls: Imperva, F5, Breach Open Source: WebNight and ModSecurityStateful Firewalls: Juniper, Check Point, Palo AltoIDP/IDS: Sourcefire, TippingPoint Open Source: SnortAudits: ENY, PWC, Grant ThorntonPen Testing: WhiteHat, Trustwave, Electric Alchemy Open Source: OWASP ZAPStatic Analysis: Fortify, Veracode © 2013 Raible Designs
  44. 44. Remember...“Security is a quality, and as all other quality, it isimportant that we build it into our apps while we aredeveloping them, not patching it on afterwards likemany people do.” -- Erlend OftedalFrom a comment on my blog: © 2013 Raible Designs
  45. 45. Action! Use OWASP and Open Source Security Frameworks Don’t be afraid to contribute! Follow the Security Street Fighter Blog Use OWASP ZAP to pentest your apps Don’t be afraid of security! © 2013 Raible Designs
  46. 46. Additional ReadingSecuring a JavaScript-based Web Application Zalewski’s “The Tangled Web” © 2013 Raible Designs
  47. 47. Additional ResourcesOWASP Denver Next Meeting: Wednesday, February 20, 6-8pmFront Range OWASP Security Conference March 28 - 29 in DenverDavid Campbell of Electric Alchemy © 2013 Raible Designs
  48. 48. Questions?Contact Information @mraibleMy Presentations © 2013 Raible Designs