Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Make your SPA a maximum security prison - ConFo...

Make your SPA a maximum security prison - ConFoo Version

Martin Gontovnikas

February 18, 2015
Tweet

More Decks by Martin Gontovnikas

Other Decks in Technology

Transcript

  1. Browser Server 1. POST /users/login with username and password 2.

    Creates a User session 3. Returns a logged in cookie to the browser
  2. Browser Server 1. POST /users/login with username and password 2.

    Creates a User session 3. Returns a logged in cookie to the browser 4. Do an authenticated request. Sends the cookie.
  3. Browser Server 1. POST /users/login with username and password 2.

    Creates a User session 3. Returns a logged in cookie to the browser 4. Do an authenticated request. Sends the cookie. 5. Check the session based on the cookie and authenticate the user
  4. Browser Server 1. POST /users/login with username and password 2.

    Creates a User session 3. Returns a logged in cookie to the browser 4. Do an authenticated request. Sends the cookie. 5. Check the session based on the cookie and authenticate the user 6. Sends response to the client
  5. Browser Database Today’s applications Web Server (Scala) API (Ruby) API

    (Node) Phones Tablets Realtime (Sockets) API (Facebook) C M A A A AT
  6. Cookie-based auth keep state in server side session (mongo, redis,

    etc.)* 2 *default config. Cookie only is possible (Play, Rails)
  7. Cookies are coupled to the web framework If you try

    to reuse a cookie issued by Java in Node, not easy 3
  8. Cookies lead to CSRF attacks <iframe  style="display:none"  name="hidden"></iframe>   <form

     name="csrf"                action=“http://bank.com/account/edit"                method="post"                target="hidden">   <input  type="hidden"  name="email"  value="[email protected]"  />   <script>document.csrf.submit();</script> 6
  9. Browser Server 1. POST /users/login with username and password 2.

    Creates a token and saves it in the User table
  10. Browser Server 1. POST /users/login with username and password 2.

    Creates a token and saves it in the User table 3. Returns the Token to the Browser
  11. Browser Server 1. POST /users/login with username and password 2.

    Creates a token and saves it in the User table 3. Returns the Token to the Browser 4. Sends the Token on the Authorization Header.
  12. Browser Server 1. POST /users/login with username and password 2.

    Creates a token and saves it in the User table 3. Returns the Token to the Browser 4. Sends the Token on the Authorization Header. 5. Query user DB for a user with this token. Authenticate user
  13. Browser Server 1. POST /users/login with username and password 2.

    Creates a token and saves it in the User table 3. Returns the Token to the Browser 4. Sends the Token on the Authorization Header. 5. Query user DB for a user with this token. Authenticate user 6. Sends response to the client
  14. Browser Server 1. POST /users/login with username and password 2.

    Creates a JWT with a secret 3. Returns the JWT to the Browser
  15. Browser Server 1. POST /users/login with username and password 2.

    Creates a JWT with a secret 3. Returns the JWT to the Browser 4. Sends the JWT on the Authorization Header.
  16. Browser Server 1. POST /users/login with username and password 2.

    Creates a JWT with a secret 3. Returns the JWT to the Browser 4. Sends the JWT on the Authorization Header. 5. Check JWT signature. Get user information from the JWT.
  17. Browser Server 1. POST /users/login with username and password 2.

    Creates a JWT with a secret 3. Returns the JWT to the Browser 4. Sends the JWT on the Authorization Header. 5. Check JWT signature. Get user information from the JWT. 6. Sends response to the client