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

Death to Cookies, Long Live Tokens

Death to Cookies, Long Live Tokens

Matias Woloski

February 13, 2014
Tweet

More Decks by Matias Woloski

Other Decks in Programming

Transcript

  1. Browser Database Today’s applications Web Server (Scala) API (Ruby) API

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

    sql)* ! * default config, cookie only is possible 2
  3. Cookies are coupled to the web framework, if you try

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

     name="csrf"                action="http://example.org/account/edit"                method="post"                target="hidden">   <input  type="hidden"  name="email"  value="[email protected]"  />   <script>document.csrf.submit();</script> 6
  5. Browser Database Today Web Server (Scala) API (Ruby) API (Node)

    Phones Tablets Realtime (Sockets) API (Facebook) JWT JWT JWT JWT JWT AT JWT
  6. JWT JSON Web Tokens eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJleHAiOj EzOTIzMjMzNDAsImlhdCI6MTM5MjMxNjE0MH0.ceL8XM8RS_d6ipJ9Ys9nv1IJ1 809D5YCL_yoroPKHzo {    

           "typ":"JWT",          "alg":"HS256"   } {            "foo":"bar",     "exp":  1392323340,     "iat":  1392316140   } signature  =  HMACSHA256(         base64UrlEncode(header)           .           base64UrlEncode(payload),           ‘secret’) = header payload signature