73
SPRINGONE2GX WASHINGTON, DC Unless otherwise indicated, these slides are © 2013-2015 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ The State of Securing RESTful APIs with Spring By Rob Winch @rob_winch

State of Securing RESTful APIs with Spring

Embed Size (px)

Citation preview

Page 1: State of Securing RESTful APIs with Spring

SPRINGONE2GX WASHINGTON, DC

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

The State of Securing RESTful APIs with Spring

By Rob Winch @rob_winch

Page 2: State of Securing RESTful APIs with Spring
Page 3: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Authentication

3

Page 4: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Naïve approach…

4

https://api.example.com?username=rob&password=secret

Page 5: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

“ Come on Bender. It's up to you to make your own decisions in life. That's what's separates people and robots from animals .. and animal robots! Fry

Futurama

5

Page 6: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

RFC-7231 Sensitive Information

6

Authors of services ought to avoid GET-based forms for the submission of sensitive data … - RFC-7231: Section 9.4

Page 7: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Basic Authentication

7

Page 8: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Basic Authentication

8

Page 9: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Digest Authentication

9

Page 10: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Digest Authentication

10

Page 11: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Digest Authentication

11

Page 12: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Transport Layer Security (TLS)

•  Confidentiality

•  Integrity

12

Page 13: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

13

13

Page 14: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Checking TLS

https://www.ssllabs.com/ssltest/

https://shaaaaaaaaaaaaa.com/

14

Page 15: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

TLS Performance

•  Computational overhead

•  Latency overhead

•  Cache

15

Page 16: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 16

“On our production frontend machines, SSL/TLS

accounts for less than 1% of the CPU load, less than 10 KB of memory per connection and less than 2% of

network overhead.

- Adam Langley, Google

Page 17: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 17

“We have found that modern software-based TLS

implementations running on commodity CPUs are fast enough to handle heavy HTTPS traffic load

without needing to resort to dedicated cryptographic hardware.

- Doug Beaver, Facebook

Page 18: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 18

“HTTP keepalives and session resumption mean

that most requests do not require a full handshake, so handshake operations do not dominate our CPU

usage.

- Jacob Hoffman-Andrews, Twitter

Page 19: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

TLS Optimize

•  TLS Resumption

•  Latency

•  Online Certificate Status Protocol (OCSP)

•  Cloudflare

19

Page 20: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Optimizing TLS

Is TLS Fast Yet.com

20

Page 21: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

HTTP Basic over HTTPS?

21

oclHashcat

Hash Type Speed

SHA1 42.408 Bh/s

SHA256 16.904 Bh/s

SHA512 5.2 Bh/s

Ubuntu 14.04, 64 bit ForceWare 346.29 X NVidia Titan X

Page 22: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Introduce Session

22

username=winch&name=Rob+Winch!

Page 23: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Encrypting the Session

23

Base64(IV, aes_cbc(k,IV,plainText)) !•  k  –  a  secret  key  only  known  to  server  •  aes_cbc  –  encrypts  the  plainText  using  AES/CBC  with  the  

provided  IV  •  plainText  –  format  of  username=winch&name=Rob+Winch  

Page 24: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Your handwriting is atrocious, not encrypted

24

Page 25: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Introduce Session

username=winch&name=Rob+Winch!

username=admin&name=Rob+Winch!

Can change properly encrypted value below:

To have the following Plaintext

25

Page 26: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 26

2:03 PM - 27 Jul 2015

Page 27: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 27

10:54 AM - 28 May 2015

Page 28: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

JWT Header

{"alg":"HS256","typ":"JWT"}

28

Page 29: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Page 30: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

“… each request from client to server must contain

all of the information necessary to understand the request, and cannot take advantage of any stored

context on the server.

- Roy Fielding, Architectural Styles and

the Design of Network-based Software Architectures

30

Page 31: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Representational STATE transfer

“ … session state can be transferred by the

server to another service such as a database to maintain a persistent state for a period and

allow authentication

-  Wikipedia

31

Page 32: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 32

Page 33: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Code Slide

33

public interface HttpSession { …}

Page 34: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 34

Page 35: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Customizing the Cookie

35

<session-config> <cookie-config> <name>SESSION</name> </cookie-config></session-config>

Page 36: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Spring Session

36

@Configuration@EnableRedisHttpSessionpublic class Config { @Bean public JedisConnectionFactory connectionFactory() { return new JedisConnectionFactory(); }}

Page 37: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Spring Session

37

public class Initializer extends AbstractHttpSessionApplicationInitializer { public Initializer() { super(Config.class); }}

Page 38: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Spring Session

38

public class Initializer extends AbstractHttpSessionApplicationInitializer { public Initializer() { super(Config.class); }}

Page 39: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Spring Session

39

<filter> <filter-name> springSessionRepositoryFilter </filter-name> <filter-class> org.springframework.web.filter.DelegatingFilterProxy </filter-class></filter><filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern></filter-mapping>

Page 40: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 40

Page 41: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

DEMO Spring Session

41

Page 42: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SessionRepositoryFilter

42

public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain { ServletRequest request = new SessionRepositoryRequestWrapper(req); … chain.doFilter(request, response);}

Page 43: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

SessionRepositoryRequestWrapper

43

public HttpSession getSession() { // return custom HttpSession }

Page 44: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

OAuth 2.0?

•  When working within a sandbox

•  Limiting liability

44

Page 45: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 45

Page 46: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

http .authorizeRequests() .antMatchers("/public/**").permitAll() .antMatchers("/admin/**").hasRole("ADMIN") .anyRequest().authenticated()

Authorization

46

Page 47: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Authorization

47

@PostAuthorize("returnObject?.to?.id == principal.id")Message findOne(Long id);

Page 48: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Authorization

48

@PreAuthorize("#message?.from?.id == principal.id")<S extends Message> S save(Message message);

Page 49: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Permissions

49

@PostAuthorize("hasPermission(returnObject,'read')")Message findOne(Long id);

Page 50: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Permissions

50

@PreAuthorize("hasPermission(#message,’write')")<S extends Message> S save(Message message);

Page 51: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/ 51

public interface PermissionEvaluator … { boolean hasPermission(Authentication authentication, Object targetDomainObject, Object permission); boolean hasPermission(Authentication authentication, Serializable targetId, String targetType, Object permission);}

Page 52: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Queries?

52

@Query("select m from Message m where m.to.id = ?#{principal.id}") Iterable<Message> inbox();

Page 53: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Queries?

53

@Query("select m from Message m where m.to.id = ?#{principal.id}") Page<Message> inbox(Pageable pageable);

Page 54: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Future Work?

54

@EnableAclSecurity public interface SecuredMessageRepository extends MessageRepository {}// Vote for it! DATACMNS-293 SEC-2409

Page 55: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

DEMO CSRF

55

Page 56: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

56

Page 57: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

57

Page 58: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

58

Page 59: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

“When do I use CSRF protection?

59

Page 60: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

“... but my application uses JSON

60

Page 61: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

61

<form ... method="post" enctype="text/plain"> <input type='hidden' name=’{"summary":"Hi", … "ignore_me":"' value='test"}' /></form>

Page 62: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

62

{ "summary": "Hi", "message": "New Message", "to": "[email protected]", "ignore_me": "=test"}

Page 63: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

“… but my application is stateless

63

Page 64: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

64

Page 65: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

“…and I use a custom header for authentication and ignore cookies

65

Page 66: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

CSRF Protection

•  Use proper HTTP Verbs

•  Configure CSRF Protection

•  Include the CSRF Token

66

Page 67: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Including the CSRF Token

67

@RequestMapping("/csrf”) public CsrfToken csrf(CsrfToken token) { return token;}

Page 68: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

DEMO Clickjacking

68

Page 69: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Security HTTP Response Headers

69

Page 70: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Security HTTP Response Headers

70

Page 71: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Security HTTP Response Headers

71

Page 72: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Related Talks

•  Hands on Spring Security 4.1 – Wed at 8:30am

•  Spring MVC 4.2: New and Noteworthy – Wed at 10:30am

•  A How to Guide to Security in the PAAS Cloud – Wed at 4:30pm

•  Securing Microservices with Spring Cloud Security – Thurs at 10:30am

72

Page 73: State of Securing RESTful APIs with Spring

Unless otherwise indicated, these s l ides are © 2013-2015 Pivotal Software, Inc. and l icensed under a Creat ive Commons Attr ibut ion-NonCommercial l icense: ht tp: / /creat ivecommons.org/ l icenses/by-nc/3.0/

Learn More. Stay Connected.

•  Use TLS

•  Authentication Should Have State

•  Use Proper Authorization

•  Use a Framework Because Individuals Cannot Provide Good Security

Twitter: @rob_winch

YouTube: spring.io/video

LinkedIn: spring.io/linkedin

Google Plus: spring.io/gplus

73