What makes JSON Web Tokens (JWT) secure?

Sdílet
Vložit
  • čas přidán 7. 09. 2024
  • There’s a lot you have to think about when building frontend applications - routing, performance, animations, etc. Security often takes the back seat (not cool!)
    Between cookies, tokens, keeping users authenticated, and handling resource access, security can become quite tricky. This talk looks at the implementation detail and usage of the popular methods of authorization: JWT(JSON web tokens) and see what makes it secure in the first place?
    The talk covers:
    1. What is JWT?
    2. When should you use JSON Web Tokens?
    3. Structure + Implementation
    4. Usage
    5. What makes them secure?
    6. Can JWT be hacked?
    Siddharth works on Design systems at Auth0. He runs frontend.army and stackstickers.shop on the side. Past: Frontend architect at Practo
    Slides and summary on: hasgeek.com/js...

Komentáře • 69

  • @SomjitNag
    @SomjitNag Před měsícem

    This video is brilliant. The speaker's expertise shines through! relevant even after so many years, which is saying something for a tech video!

  • @NT-qv1ix
    @NT-qv1ix Před 2 lety +4

    One thing that is worth to be pointed out is at 8:22, the lecturer said the createHmac() is doing encryption, it should be a slip of tongue. As HMAC stands for Hash-based Message Authentication Code, and the Node API doc also express the same meaning. Do remember: *Hash !== Encryption*

  • @ninadsubba5365
    @ninadsubba5365 Před 3 lety +11

    0:21 JavaScript web tokens?

  • @ozzyfromspace
    @ozzyfromspace Před 3 lety +2

    I liked the section on jwt vulnerabilities. These are good things to ponder 🤓🙏🏽

  • @insaneviruss
    @insaneviruss Před 3 lety +2

    Wow. Loved it. Thanks for deep explaination and the vulnerabilities section!

  • @mikeyinger4204
    @mikeyinger4204 Před 2 lety

    That was a half hour well spent. Thanks.

  • @m4ynor
    @m4ynor Před 4 lety +3

    16:05 JWT is vulnerable both to CSRF and XSS. The first when storing token in a cookie, the second when storing in the local storage

    • @mathijsv6221
      @mathijsv6221 Před 3 lety +1

      So if you'd store the jwt in a HttpOnly cookie and secure your api with CSRF tokens, you should be alright, right?

  • @anotherrohit
    @anotherrohit Před 5 lety +15

    HI siddharth - "The attacker can see the contents of the token, but cannot change it" Isn't the contents of the token enough for them to reuse the token as is against the API, why should they care about changing it if they already have the access token and can use to access the APIs at least till the validity of the token does not expire. Can you let me know how we can call this secure if they get the token and are enabled to use the API with the help of the token..

    • @TZCoder
      @TZCoder Před 5 lety +1

      This is correct JWT does not encrypt the data in the token it only signs the data so if a token arrives at the server the server can be sure that it(the server) was the one that originally generated the token. So https/SSL has to be used to prevent someone from reading the token. Another issue is tokens don't have any mechanism to revoke them, so even if you know it has been compromised it will remain valid until expiry date.

    • @dummypg6129
      @dummypg6129 Před 4 lety +1

      Is it suppose to be encrypted it with a secret key? Which both front and backend knows it.

    • @TZCoder
      @TZCoder Před 4 lety +5

      @@dummypg6129 Its not encrypted, it relies on the fact that the connection should be encrypted i.e TLS/SSL Https

    • @tmarsha4
      @tmarsha4 Před 4 lety +1

      ​@@dummypg6129 Only the backend knows it. It decrypts it with the secret key and if it ends up with the same hashed result it knows the data is exactly the same AND the hash they sent also is correct. If a user gets the secret key then yes, all JWT's are compromised. The solution? Change the secret key. Done.

    • @iambhanu7
      @iambhanu7 Před 4 lety +1

      @@TZCoder I really wonder why nobody (training videos/articles) explicitly mentions that these tokens MUST be used along with https/SSL for it to be really secure. Or is it not the case ?

  • @vicbarbu
    @vicbarbu Před 2 lety +1

    "How does it compare to SAML?" "I have no idea". This says a lot lol.

  • @gavingonzalez7174
    @gavingonzalez7174 Před 3 lety +1

    Man I learn so much, thank you

  • @metalbroga
    @metalbroga Před 3 lety +3

    How the “silent background authentication “ works? What do I send to the api to generate a new token?

  • @velakuruday
    @velakuruday Před 3 lety

    Nice speaker. Clearly explained!

  • @NikhilBhalwankar
    @NikhilBhalwankar Před 2 lety

    Indeed a very good explaination. Thanks.

  • @barwalgayatri4655
    @barwalgayatri4655 Před 2 lety

    Great Info Than kyou very much .Explained very well in details\

  • @santosh567890
    @santosh567890 Před 3 lety +3

    He totally missed the public key matching standard for JWT. Every token should have a kid or x5t claim in the header, this will act as an identifier to the key to be used for validating the signature. The x5t or kid is the base64(SHA1(public-key)).

  • @amitbaijal421
    @amitbaijal421 Před 3 lety +1

    Nice video - very informative

  • @lkprasanna
    @lkprasanna Před 2 lety

    If a client had access to two apis, can i use the same access token for both apis? Since the client app has access to both apis and the claims are not different between the two apis, what is the security impact of reusing the same access token

  • @qcmira2024
    @qcmira2024 Před 2 lety

    Great video ! I learned a lot, thanks!

  • @ringoaikocascade
    @ringoaikocascade Před 3 lety +1

    15:05 I don't understand. Cookies are the way to transfer and store some data, and jwt is the format of the data to be sent in whatever format. They're not comparable.

    • @softwarelivre2389
      @softwarelivre2389 Před 2 lety

      He meant 'session' instead of 'cookie'. Weird mistake but yeah

  • @hackersguild8445
    @hackersguild8445 Před 4 lety

    Very indepth. Nice content

  • @nikhilpatil9654
    @nikhilpatil9654 Před 5 lety +1

    Thank you very much, sir !

  • @karthibalaji3817
    @karthibalaji3817 Před 4 lety +1

    Great content !. splendid.

  • @Baha2490
    @Baha2490 Před 3 lety +1

    7:12 Looks like 32 alphanum chars, not random ASCII chars, so less than 2^192 possibilities instead of 2^256.
    "256-bit secret" is a bit misleading if that's the case (it's only the length, not the strength).

  • @shivangitomar5557
    @shivangitomar5557 Před 2 lety

    Amazing!

  • @mohammadashrafulalam8205

    How to generate json web token from Zip password protected file; please help me.

  • @paypal7880
    @paypal7880 Před 2 lety

    Nice video. Make more

  • @toddtroll2220
    @toddtroll2220 Před 3 lety

    Stopped listening after 2 minutes because the accent is to heavy for me as non native English speaker. But gave thumbs up because I appreciate talks like this.

  • @vasianurag9701
    @vasianurag9701 Před 3 lety

    Can't someone steal the token (by accessing your network requests, extract the header) and use that token to access the API's? How does it solve anything?

    • @griffithe2438
      @griffithe2438 Před 3 lety +1

      As far as I know, not, if you are using an security communication over TLS.

    • @brod515
      @brod515 Před 3 lety +2

      no one should steal the JWT just like no one should steal your cookies.

  • @m4ynor
    @m4ynor Před 4 lety

    27:10 How the server will use the public RSA key? It should use the private one. Am I wrong?

    • @manikantaraju9137
      @manikantaraju9137 Před 3 lety

      He might have overlooked, it should be private to sign when it's RSA

    • @brod515
      @brod515 Před 3 lety +1

      no he is basically saying that is a bug. he is showing how using rsa encryption with the public and private key pair can cause a problem. The JWT is signed using the private key and has to be verified using the public key. so even when it's the server verifying it needs to used the public key. he explained earlier @13:18 why this might be done (basically because you can share the public key with multiple servers but you wouldn't want to do that with a single private key).
      The problem with this is that some can take advantage of the fact they know the server is verifying with publicKey. they can just modify the payload and sign it again using the publicKey and claim that the algorithm is HS256; basically saying we are using a shared key, and guess what, we have the key it's the publicKey.

  • @LemuelUhuru
    @LemuelUhuru Před 5 lety +1

    At JWT.io it states to sign the token like hMAC(header + payload + secret) but with the npm library you used, it signs as hMAC(payload + secret). Why aren't we included the header here?

    • @nicklesseos
      @nicklesseos Před 5 lety +2

      because the library does that for you...

    • @dailyshorts1562
      @dailyshorts1562 Před 3 lety

      may be because generally header contains algorithm and here already he mentioned not to pass algo with header and pass a white list otherwise anyone can make algo to none and jwt is just a joke than nothing else

  • @smitch_yt
    @smitch_yt Před 5 lety

    Thank you :D

  • @paypal7880
    @paypal7880 Před 2 lety

    1:58 hull , back to json web tokens. hehehe. What was that.

  • @ishi92
    @ishi92 Před 5 lety +1

    amazing content! Thanks !!

  • @dhanitrianggara1772
    @dhanitrianggara1772 Před 2 lety

    it would be better and safer, if the json web token and rest api were encrypted and decrypted sir

  • @XbattlepopeX
    @XbattlepopeX Před 4 lety

    Its all about the salt

  • @imyounick
    @imyounick Před 4 lety

    Good, but nothing is secure in a web application.
    1.For encrypting payload to send from Client to server, we need secret on both client side and server side.
    Attacker can easily get keys from dev tools.
    2.Once the attacker gets the secret key and IV key also a stolen token you cannot go anything except deactivating your user.
    3.No matter what your data can be masked/changed using above 2 points.

    • @ringoaikocascade
      @ringoaikocascade Před 3 lety

      how do you access httpOnly cookie in dev tools?

    • @imyounick
      @imyounick Před 3 lety

      @@ringoaikocascade In chrome dev tools ,filter XHR Request from Network tab if any of request sends cookie it will show up in Cookies tab.

    • @ringoaikocascade
      @ringoaikocascade Před 3 lety

      @@imyounick so it's a manual work then. How do you get someone else's httponly cookie?

    • @imyounick
      @imyounick Před 3 lety

      @@ringoaikocascade Same answer, manually is only way. Consider RDP hack

    • @ringoaikocascade
      @ringoaikocascade Před 3 lety +3

      @@imyounick If I have access to someone else's credit card, or somehow let me use the card, and I use it to buy whatever I want, that doesn't mean credit card itself is not secure.

  • @OskarCeso
    @OskarCeso Před 5 lety +9

    the sound is terrible omg how can people watch and like this. This is a video platform the sound is 50% of this ....

    • @CarlosEduardo-cq1wv
      @CarlosEduardo-cq1wv Před 5 lety +1

      the accent very weird as well

    • @niektuytel7861
      @niektuytel7861 Před 5 lety +4

      @@CarlosEduardo-cq1wv but what he say is usefull for hackers i thinks this is not to secure its possible i think
      kind regards niek tuytel

    • @isynciswim7382
      @isynciswim7382 Před 5 lety +15

      The sound is fine to me, and his accent is not bad at all. I don't what the problem is. Are you guys just hating on him?

    • @trophieboi1820
      @trophieboi1820 Před 4 lety +2

      @@isynciswim7382 Yes they are , there's a stigma to Indian accent...as an Indian I know it.

    • @GreenyDe
      @GreenyDe Před 4 lety

      im not a native english speaker but i understand him perfectly fine, also the content was great!

  • @mr.javascript1320
    @mr.javascript1320 Před 3 lety

    lol he said javascript web token.......wat a NOOOB