+ All Categories
Home > Technology > Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

Date post: 22-Jan-2018
Category:
Upload: andreas-falk
View: 221 times
Download: 0 times
Share this document with a friend
56
SICHER IN DIE CLOUD MIT ANGULAR UND SPRING BOOT 22. MAI 2017 1
Transcript
Page 1: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SICHER IN DIE CLOUDMIT ANGULAR UND SPRING BOOT

22. MAI 2017

1

Page 2: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANDREAS FALKNOVATEC CONSULTING GMBH

[email protected]

@NT_AQE, @andifalk

2

Page 3: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ARCHITECTURE /THREAT MODEL

3 . 1

Page 4: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

3 . 2

Page 5: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SQLInjection CSRF XSS OWASP OAuth2 OpenID-

Connect AbUser-Stories Authentication

Authorization Secure Coding Security-

Testing SSO DoS Sensitive-DataData-Privacy Crypto Code-Reviews Threat-

Modeling Architecture Dependencies DASTSAML SAST DevSecOps

3 . 3

Page 6: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SQLInjection CSRF XSS OAuth2 OpenID-

Connect Authentication AuthorizationSecure Coding Security-Testing Sensitive-

Data

3 . 4

Page 7: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

HTTPS://GITHUB.COM/OWASP/TOP103 . 5

Page 8: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

APP SECURITYVERIFICATION STANDARD

PRO ACTIVE CONTROLS

https://github.com/OWASP/ASVS

https://www.owasp.org/index.php/OWASP_Proactive_Controls

3 . 6

Page 9: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANGULAR

4 . 1

Page 10: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANGULARJS = ANGULAR 1ANGULAR = ANGULAR 2.X, 4.X, ...

4 . 2

Page 11: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

A3: CROSS-SITE SCRIPTING (XSS)

4 . 3

Page 12: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANGULAR JS SECURITY

https://angularjs.blogspot.de/2016/09/angular-16-expression-sandbox-removal.html

4 . 4

Page 13: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANGULAR SECURITY“...The basic idea is to implement

automatic, secure escaping for allvalues that can reach the DOM... Bydefault, with no specific action fordevelopers, Angular apps must be

secure...”https://github.com/angular/angular/issues/8511

4 . 5

Page 14: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANGULAR XSSPROTECTION

ANGULAR TEMPLATE = SAFEINPUT VALUES = UNSAFE

4 . 6

Page 15: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANGULAR COMPONENTTYPESCRIPT

@Component({ selector: 'app-root', templateUrl: 'app.component.html', styleUrls: ['app.component.css'] }) export class AppComponent {

untrustedHtml:string = '<em><script>alert("hello")</script></em>';

}

4 . 7

Page 16: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ANGULAR TEMPLATEHTML BINDINGS

<h2>Binding of potentially dangerous HTML-snippets</h2>

<h3>Encoded HTML snippet</h3> <h3 class="trusted">{{untrustedHtml}}</h3>

<h3>Sanitized HTML snippet</h3> <h3 class="trusted" [innerhtml]="untrustedHtml"></h3>

4 . 8

Page 17: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

UNSAFE ANGULAR API'S

ElementRef: Direct access to DOM!

DomSanitizer: Deactivates XSS-Protection!

Do NOT use!https://angular.io/docs/ts/latest

4 . 9

Page 18: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

DEMO

4 . 10

Page 19: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

BACKEND

5 . 1

Page 20: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

A1: INJECTION

5 . 2

Page 21: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

PERSISTENT XSS + INJECTIONSSTRONG TYPING + BEAN VALIDATION

@Entity public class Person extends AbstractPersistable<Long> {

@NotNull @Pattern(regexp = "^[A-Za-z0-9- ]{1,30}$") private String lastName;

@NotNull @Enumerated(EnumType.STRING) private GenderEnum gender; ... }

5 . 3

Page 22: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SQL INJECTIONSSPRING DATA JPA: USE PREPARED STATEMENTS@Query( "select u from User u where u.username = " + " :username and u.password = :password") User findByUsernameAndPassword( @Param("username") String username, @Param("password") String password);

5 . 4

Page 23: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

A8: CROSS-SITE REQUEST FORGERY (CSRF)

5 . 5

Page 24: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

DOUBLE SUBMIT CSRF TOKEN

5 . 6

Page 25: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SPRING SECURITYSECURE BY DEFAULT

Authentication required for all HTTP endpoints

Session Fixation Protection

Session Cookie (HttpOnly, Secure)

CSRF Protection

Security Response Header

5 . 7

Page 26: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SPRING SECURITY CSRFCONFIGURATION

ANGULAR SUPPORT@Configuration public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {

@Override protected void configure(HttpSecurity http) throws Exception { … http .csrf().csrfTokenRepository( CookieCsrfTokenRepository.withHttpOnlyFalse() ); }

5 . 8

Page 27: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

WHO AM I?A2: BROKEN AUTHENTICATION AND SESSION

MANAGEMENT

A10: UNDERPROTECTED APIS

5 . 9

Page 28: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

AUTHENTICATIONSTATEFUL OR STATELESS?

Session Cookie Token (Bearer, JWT)

With each Request (on same domain)

Manually as Header

Potential CSRF! No CSRF possible

One domain Cross domain (CORS)

Sensitive Info (HTTPS) Sensitive Info (HTTPS)

5 . 10

Page 29: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

OAUTH 2 = AUTHORIZATION

5 . 11

Page 30: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

OPENID CONNECT = AUTHENTICATON

5 . 12

Page 31: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

OAUTH 2 / OPENID CONNECT RESOURCE@EnableResourceServer @Configuration public class OAuth2Configuration { @Bean public JwtAccessTokenConverterConfigurer jwtAccessTokenConverterConfigurer() { return new MyJwtConfigurer(...); } static class MyJwtConfigurer implements JwtAccessTokenConverterConfigurer { @Override public void configure( JwtAccessTokenConverter converter) {...} }}

OAuth 2.0 Threat Model and Security Considerations

5 . 13

Page 32: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

IMPLICIT GRANT

Validate...

...issuer identifier

...audiance (client id)

...signature (public key)

...expiration time Implicit Client Implementer’s Guide

OAuth 2.0 Threat Model and Security Considerations5 . 14

Page 33: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

CLIENT CREDENTIALS GRANT

5 . 15

Page 34: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

RESOURCE OWNER GRANTPOST /token Host: localhost:9090 Accept: application/json Content-type: application/x-www-form-encoded Authorization: Basic b2F1dGgtY2xpZW50LTE6b2F1dGgt... grant_type=password&scope=openid&username=adm&password=secret

DO NOT USE!

5 . 16

Page 35: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

WHAT CAN I ACCESS?A4: BROKEN ACCESS CONTROL

A10: UNDERPROTECTED APIS

5 . 17

Page 36: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

AUTHORIZATION OF REST APIROLE BASED

public class UserBoundaryService {

@PreAuthorize("hasRole('ADMIN')") public List<User> findAllUsers() {...}

}

5 . 18

Page 37: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

AUTHORIZATION OF REST APIPERMISSION BASED

public class TaskBoundaryService {

@PreAuthorize("hasPermission(#taskId, 'TASK', 'WRITE')") public Task findTask(UUID taskId) {...}

}

5 . 19

Page 38: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

AUTHORIZATION OF REST APIINTEGRATION TEST

public class AuthorizationIntegrationTest {

@WithMockUser(roles = "ADMIN") @Test public void verifyFindAllUsersAuthorized() {...}

@WithMockUser(roles = "USER") @Test(expected = AccessDeniedException.class) public void verifyFindAllUsersUnauthorized() {...}

}

5 . 20

Page 39: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

DEMO

5 . 21

Page 40: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

WHAT ABOUT THECLOUD?

6 . 1

Page 41: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

GOOD OLD FRIENDS ...UNDMORE...

CSRF XSS SQL Injection Session Fixation VulnerableDependencies Weak Passwords Broken Authorization

Sensitive Data Exposure

Distributed DoSEconomic DoS

6 . 2

Page 42: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

WEAK PASSWORDS

6 . 3

Page 43: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

A6: SENSITIVE DATA EXPOSURE

https://github.com/OWASP/Top10

6 . 4

Page 44: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SPRING CLOUD CONFIG

Externalized configuration in a distributed system

HTTP, resource-based API

Supports property file and YAML formats

Encrypt and decrypt property values

https://cloud.spring.io/spring-cloud-config

6 . 5

Page 45: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

6 . 6

Page 46: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SECRET STORAGEKEY REVOCATION

KEY ROLLINGAUDIT LOGS

https://www.vaultproject.io/

6 . 7

Page 47: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SPRING CLOUD SERVICESSECURITY

6 . 8

Page 48: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

SO WHAT IS DIFFERENT

IN THE CLOUD?

6 . 9

Page 49: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

6 . 10

Page 50: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ROTATE, REPAIR, REPAVEJUSTIN SMITH

“What if every server inside my datacenter had a maximum lifetime of twohours? This approach would frustrate

malware writers...”

6 . 11

Page 51: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

ONE MORE THING...

7 . 1

Page 52: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

A7: INSUFFICIENT ATTACK PROTECTION

7 . 2

Page 53: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

7 . 3

Page 54: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

TEST YOUR APPLICATIONBEFORE THE ATTACKER DOES

OWASP ZAP (https://github.com/zaproxy/zaproxy)Burp Suite Free Ed. (https://portswigger.net/burp)NMap (https://nmap.org)SQLMap (http://sqlmap.org)

7 . 4

Page 55: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

REFERENCES

All images used are from and are published under

All used logos are trademarks of respective companies

OWASP Top 10 2017 (https://github.com/OWASP/Top10)Application Security Verification Standard (https://github.com/OWASP/ASVS)Pro Active Controls (https://www.owasp.org/index.php/OWASP_Proactive_Controls)Angular Sandbox Removal (https://angularjs.blogspot.de/2016/09/angular-16-expression-sandbox-removal.html)Angular Security Tracking Issue (https://github.com/angular/angular/issues/8511)OAuth 2.0 Threat Model and Security Considerations (https://tools.ietf.org/html/rfc6819)Implicit Client Implementer’s Guide (https://openid.net/specs/openid-connect-implicit-1_0.html)Rotate, Repair, Repave (https://thenewstack.io/cloud-foundrys-approach-security-rotate-repair-repave)Spring Cloud Config (https://cloud.spring.io/spring-cloud-config/)Spring Cloud Vault (https://cloud.spring.io/spring-cloud-vault)Vault (https://www.vaultproject.io)

Pixabay Creative Commons CC0 license.

8

Page 56: Sicher in die Cloud mit Angular und Spring Boot (Karlsruher Entwicklertag 2017)

Q&Ahttp://www.novatec-gmbh.de http://blog.novatec-gmbh.de

[email protected]

@NT_AQE, @andifalk

9


Recommended