Storing Auth Tokens in LocalStorage

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 208

  • @joeplayer8980
    @joeplayer8980 8 หลายเดือนก่อน +347

    This video shattered my trust in circle-providing npm packages.

    • @cdruc
      @cdruc  8 หลายเดือนก่อน +16

      🤣🤣🤣🤣

    • @ruslan_yefimov
      @ruslan_yefimov 8 หลายเดือนก่อน +12

      We can still use ovals though - just be smarter!

    • @michaelbitzer7295
      @michaelbitzer7295 8 หลายเดือนก่อน +5

      Just use squares and cut of the edges, problem solved.

    • @benjidaniel5595
      @benjidaniel5595 8 หลายเดือนก่อน

      I mean it must be good if it’s had 1 billy trilly billy downloads

  • @Cloneee
    @Cloneee 8 หลายเดือนก่อน +127

    It's not about cookies or localStorage, it's about how you handle the validation and protecting methods IN YOUR BACKEND SERVER. When using cookies, there's still XSS, man-in-middle, you can't stop them, just slow them down. The more appropriate way to protect your user is stop using stupid packages from npm and try to use an access token with a refresh token, limit the number of refresh tokens per user, save the user's IP, browser information, and try to use the RTR (refresh token rotation) method.

    • @moosethemucha
      @moosethemucha 8 หลายเดือนก่อน

      Thank you

    • @gadgetboyplaysmc
      @gadgetboyplaysmc 8 หลายเดือนก่อน +3

      For sessions, you wouldn't really need to take care of refresh and access token, right? A refresh token in itself is like a session already.

    • @mikooovsky
      @mikooovsky 8 หลายเดือนก่อน

      this refresh token hype is so funny xd

  • @JakobTheCoder
    @JakobTheCoder 8 หลายเดือนก่อน +4

    Thank you for this video. I saw these videos (same topic) so often and never understood why it is so important, but your example with the package is so good.

  • @Dontcaredidntask-q9m
    @Dontcaredidntask-q9m 8 หลายเดือนก่อน +203

    Saying that a httponly cookie is safe and cant be accessed is extremely misleading and dangerous. They can be accessed by XSS and XHR attacks. Setting a cookie to httponly is one part of your multi-layer defense, on its own its not enough, but combined with other layers it helps make your service more secure

    • @dealloc
      @dealloc 8 หลายเดือนก่อน +14

      Yes but it's easier to mitigate against XSS attacks as you can restrict the cookie through SameSite policy, unlike any JavaScript-accessible storage medium.

    • @cdruc
      @cdruc  8 หลายเดือนก่อน +27

      I agree; more layers are better, of course. I'm not sure about XSS and XHR attacks being able to access httpOnly cookies, though. I thought the httpOnly attribute was specifically designed to offer protection against XSS/XHR attacks. Can you expand or point to an article/page/docs demonstrating this?

    • @vagkalosynakis
      @vagkalosynakis 8 หลายเดือนก่อน

      The httpOnly attribute of a cookie is exactly there to prevent XSS attacks, so you can't access it using that one. I haven't seen XHR attacks and looking online right now, I don't seem to find a way to access an httpOnly cookie as well.

    • @mibi2509
      @mibi2509 8 หลายเดือนก่อน +7

      ​@@cdruc I never heard of a way to read httpOnly from JS that was not a bug in its implementation. Idk what they are on about.

    • @dealloc
      @dealloc 8 หลายเดือนก่อน +23

      @@cdruc The problem is not with XSS specifically (accessing the information directly through JS) but that a script can make a fetch from the website's origin and include the credentials (i.e. HttpOnly cookies). If SameSite is not set to either Lax or Strict, it will include those cookies in the XHR request.
      By default modern browsers will set the SameSite to Lax if it is not explicitly set to None by the website issuing the cookie. So unless you go out of your way to disable it, your users will be safe (also safe against CSRF attacks).

  • @gnorts_mr_alien
    @gnorts_mr_alien 8 หลายเดือนก่อน +13

    yeah I don't agree. if your web app is compromised by a rogue package, it is game over. even if you have a http only cookie, yes, they might not be able to steal the token exactly, but they can still make requests to your backend through the client browser. the cookie will be sent automatically, and they will do what they want to do regardless. they just won't have the token at hand, they'll be able to use it. this is common advice but security theater. with cookies you will have to start to worry about CSRF etc as well. so no method is without its drawbacks. you need to have a threat model. if your threat model is "infected scripts in my site" then neither cookies, nor local storage will save you.

    • @DaSchTour
      @DaSchTour 8 หลายเดือนก่อน +1

      An infected script could even load additional javascript that exploits the requests on your page. Do requests to your server and then send the data to another server. If you have untrusted 3rd party scripts on your page nothing will save you. If you do not sanitize user input also anything can happen.

  • @ouya_expert
    @ouya_expert 8 หลายเดือนก่อน +45

    I remember being onboarded on a government project that stored JWTs in localstorage which required logging in using your national ID. It was a hell of a shock it got through code reviews and the eyes of every dev who went through it.

  • @CristianBilu-q4n
    @CristianBilu-q4n 8 หลายเดือนก่อน +11

    There is another interesting thing that discord does, they store the token in localStorage but:
    1. When they load the page the key is deleted from localStorage and loaded in memory
    2. When a user leaves the website or closes chrome or the discord app they store it again in localStorage so they can get it on the next load.
    This mostly works for web applications that don't require opening in new tabs tho, because opening new tabs of your website means it doesn't know the current auth token as it is not in local storage anymore until you close the tab that currently has access to it.

  • @Sebastian-rn6pb
    @Sebastian-rn6pb 8 หลายเดือนก่อน

    I knew this was a bad idea from hearing it everywhere, but I never understood how the attacks would work. Thank you so much.

  • @MichaelScharf
    @MichaelScharf 8 หลายเดือนก่อน +52

    Well, unless you disallow access to any other domain with using Content Security Policy (CSP): For example `Content-Security-Policy: default-src 'self'; connect-src 'self'` there is no way to send data to another domain

    • @_f0x604
      @_f0x604 8 หลายเดือนก่อน

      Can CORS prevent sending data to another domain name as well?

    • @saiv46
      @saiv46 8 หลายเดือนก่อน

      ​​@@_f0x604Nope. CORS is about _downloading_ data.

    • @trapfethen
      @trapfethen 8 หลายเดือนก่อน +3

      CSP does not govern browser extensions, nor does it protect from relay attacks. Though, the latter requires you to have a relay vulnerability in your server implementation.

    • @tigerofdoom
      @tigerofdoom 8 หลายเดือนก่อน

      @@_f0x604 No, CORS is aimed at stoping Cross-site Request Forgery, tricking the browser into sending the cookies to perform actions on Website B while the user browses Website A. CSP prevents exactly what's described in the video, exfiltrating data from a site with malicious scripts that are injected into the site (XSS).

    • @MichaelScharf
      @MichaelScharf 8 หลายเดือนก่อน +4

      @@trapfethen yes, but browser extensions can inject any code and just read you password as you type. When you have a node app, you also have to make sure that the server cannot send data to a malicious sie.

  • @bartoszkrawczyk4976
    @bartoszkrawczyk4976 8 หลายเดือนก่อน +36

    I see so many articles, like "authentication in React" that says to store it in localStorage. Thanks for making this video, I hope it will reach as many people as possible.

    • @codokit
      @codokit 8 หลายเดือนก่อน

      We need ask react-devs about httpOnly cookies on interviews.

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน +7

      this video is very misleading

    • @whatskookin6429
      @whatskookin6429 8 หลายเดือนก่อน +2

      What you should always do, is read your framework of choice docs. Usually they tell you use local storage is not a good idea.

    • @bartoszkrawczyk4976
      @bartoszkrawczyk4976 8 หลายเดือนก่อน

      @@whatskookin6429 Absolutely! When it comes to security, never trust some random tutorials or articles.

    • @daleryanaldover6545
      @daleryanaldover6545 8 หลายเดือนก่อน +1

      ​@@ieatthighswhy is it misleading, it provides a valid POC attack tho.

  • @Toleich
    @Toleich 8 หลายเดือนก่อน +1

    It's important to remember the fulcrum of security. What are you protecting, and who are you protecting it from?
    Sometimes it's okay to do "bad practices" because the application doesn't require much security. As long as you are consciously making that choice.
    You need to know the rules before you break the rules.

  • @gkiokan
    @gkiokan 8 หลายเดือนก่อน +1

    A long time a go for a very long time this was a good practice. You could also bind the token on a specific IP, so you will be still fine. You could also bind the token with a hardware ID and have another validation mechanism on top of the token match. Everything has it's good and bad side. Even considering the Cookie / Session Auth isn't really sure as you can still steal them with proper tools.

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน

      ITS* good side

    • @unfilledflag
      @unfilledflag 8 หลายเดือนก่อน

      "bind to ip"
      now you break the site for any mobile user that joins or leaves a wifi network

    • @gkiokan
      @gkiokan 8 หลายเดือนก่อน +1

      @@unfilledflagthats a good point but still a small edge case.
      However there are also short lived tokens that could be used with refreshing tokens but this is another hussle and story.
      So maybe just take the hardware UID to compare if the token is coming from the same device if you really want to make your token a bit more secure.

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน

      edit out the spelling mistake you made @@gkiokan

  • @omnilothar
    @omnilothar 8 หลายเดือนก่อน +3

    in devtool you can use breakpoint to tick unload, so when closing tab/window, it will prevent that , so you can check the network after

  • @coldicekiller1352
    @coldicekiller1352 8 หลายเดือนก่อน +2

    hash your Auth token with a browser fingerprint and store it, that way you can't spoof it on other computers, there are some libraries that help you do it but its definitely possible with a custom made function.

    • @gringo5282
      @gringo5282 8 หลายเดือนก่อน +1

      Browser fingerprinting is not reliable and there are a lot of collisions (especially in browsers like Safari on iOS). Trusting a fingerprint is also the equivalent of trusting the client, which is pretty well known as a bad idea. If an attacker has a financial incentive to target your site, they can easily write custom code to spoof the fingerprint itself, thus circumventing the check.

    • @coldicekiller1352
      @coldicekiller1352 8 หลายเดือนก่อน

      @@gringo5282 yeah, its a game of cat and mouse, availability and confidentiality are opposites in terms of cybersecurity and my solution was mostly done to dether "casual" hackers trying to get a simple oauth spoofing technique paired with a token expiration timer, i guess the real answer depends on the sensibility of your data and how secure you want it to be without affecting the user too much, 2fa auth on every single transaction like some crypto exchanges do it comes to mind, lol.

  • @NicJon
    @NicJon 8 หลายเดือนก่อน +15

    Well where should i then store it? Cookies can get stolen the same way??

    • @davidwang7489
      @davidwang7489 8 หลายเดือนก่อน +6

      Not HttpOnly cookies. But any malicious JS running on your site can still do a lot of damage. All of these are mitigations.

    • @atakansenturk563
      @atakansenturk563 8 หลายเดือนก่อน +1

      @@davidwang7489
      So what needs to be done?

  • @fipabrate
    @fipabrate 8 หลายเดือนก่อน +4

    Sure, I will use session storage (just kidding). On a serious note, it's worth noting that if you opt for local storage, all tabs end up sharing the same storage space. This means that if you're logged in as a regular user in one tab, and someone else logs in as an admin in another tab, the first tab unexpectedly assumes admin privileges as well. Just something to keep in mind!

    • @bartwestenenk6088
      @bartwestenenk6088 8 หลายเดือนก่อน +3

      But your second tab will login as your first user, so the admin can never even login.

    • @fipabrate
      @fipabrate 8 หลายเดือนก่อน

      @@bartwestenenk6088 true, but if you logout on second tab and then login as admin

    • @W4nn3
      @W4nn3 8 หลายเดือนก่อน

      The same is true for cookies.

  • @nugenki
    @nugenki 8 หลายเดือนก่อน

    Well done video! The flow on information was really easy for me to follow, with examples and proofs. I will be making this change, and letting others know too, thanks.

  • @kanishkc.2762
    @kanishkc.2762 8 หลายเดือนก่อน

    I hope this goes viral.

  • @rusty_knife
    @rusty_knife 8 หลายเดือนก่อน +8

    While not entirely wrong, this video is definitely misleading... By this logic, storing tokens anywhere on the client device is insecure. Now there are definitely limits on both ends, but they really shouldn't be defined by the libraries which are under your control. If this is your concern then I have bad news for you: it's probably not much harder to just steal the credentials while logging in, which is obviously even worse. And that's just the tip of the iceberg probably...
    The real solution is to vet your libraries properly, which is hard yes, but using a compromised library is dangerous no matter where you store your tokens... Also if you say you should use tokens for mobile apps, then what about compromised libraries in the mobile app? And what about the server, how are you gonna hide things from a malicious library there?
    All that doesn't mean you shouldn't use cookies for authentication if you can though. There are other benefits to that approach - it is basically what they were made for afterall. It's just that they don't really solve the problem described here...

  • @vjzb3
    @vjzb3 8 หลายเดือนก่อน +6

    Super informative and beautifully demonstrated. Thank you for taking the time to make and share with us!

  • @playwo9635
    @playwo9635 8 หลายเดือนก่อน +2

    In a production app yeah sure I agree, but for your average hobby developer not necessarily.
    Its very easy to mess up or just don't know about CSRF and exploiting a site without a CSRF token is a lot easier than finding an XSS vulnerability in a web app built with any modern frontend framework. Supply chain attacks (or just not being careful and installing random packages) is a real threat and if your app is dealing with actually sensitive data you should invest the time to use a cookie based approach 100% of the time

  • @Jamiered18
    @Jamiered18 8 หลายเดือนก่อน +3

    So what you're saying is I can safely keep tokens in local storage... if I just tell users to keep the dev tools open 😉

  • @scrimb
    @scrimb 8 หลายเดือนก่อน +1

    neither cookies nor localstorage tokens will be safe from malicious code in one of your npm packages
    the actual solution is to limit the amount of npm packages you install, and not load your app with a bunch of random packages with 10 downloads

  • @amir_2mi
    @amir_2mi 20 วันที่ผ่านมา

    In that matter there is no difference between browser side cookie vs local storage, the general best practice is to store it as "HttpOnly" server-side, but I do not see that when client and backend are separately developed.

  • @MrRiseful
    @MrRiseful 8 หลายเดือนก่อน +22

    Well wow, malware will simply steal password from login form then

    • @philheathslegalteam
      @philheathslegalteam 8 หลายเดือนก่อน +9

      Exactly. Or just interact with the page on your behalf while serving an absolutely positioned clone of the DOM in front.

    • @unfilledflag
      @unfilledflag 8 หลายเดือนก่อน

      Gonna be hard to do so when using something like OAuth

    • @MrRiseful
      @MrRiseful 8 หลายเดือนก่อน +1

      @@unfilledflag whatever, the spy script will be stealing all data from owner computer, yet won't be able to login from somewhere else

  • @dhuv
    @dhuv 8 หลายเดือนก่อน +1

    I prefer cookies but you cannot make random requests with javascript to other domains. This is especially easy to lock down with CSP. Even though those libraries read local storage, it is difficult to get that out. Maybe with a browser extension but not likely to happen.

  • @xorlop
    @xorlop 8 หลายเดือนก่อน +11

    I feel like the actual issues here were installing random packages that are not vetted and injection.

  • @Gorlik1337
    @Gorlik1337 8 หลายเดือนก่อน +4

    Cookies and tokens are compromised when you have xss. In both scenarios you are fucked-up. Soo this doesn't add more secureness into your app.

    • @zManuel
      @zManuel 8 หลายเดือนก่อน

      Wrong, httpOnly cookies can't be accessed through javascript

  • @mmghv
    @mmghv 8 หลายเดือนก่อน +2

    Cookies are more secure but not 100% safe. if you have an XSS, cookies will not help you much if it's a targeted attack, it won't be as easy as blindly stealing auth tokens from the localStorage but an XSS can still do A LOT.

    • @codokit
      @codokit 8 หลายเดือนก่อน +2

      XSS can do a lot, but it's another topic about CSRF protection.

    • @mmghv
      @mmghv 8 หลายเดือนก่อน +1

      @@codokit If you have an XSS, CSRF protection won't matter anymore because attacks will happen from the same site and not "cross-site", the attacker can make the user visit, fill & submit forms that already have CSRF tokens with them, he might even be able to silently craft & send XHR requests with CSRF tokens on behalf of the user, any cookies will also be sent automatically with the requests. in other words, if you have an XSS, you are screwed.

    • @qbasic16
      @qbasic16 8 หลายเดือนก่อน

      ​@@mmghvadd CORS

  • @anmoljhamb9024
    @anmoljhamb9024 8 หลายเดือนก่อน

    DAMN DUDE. The quality of content is just amazing!! an instant sub from me!

  • @kinositajona
    @kinositajona 8 หลายเดือนก่อน +2

    Good rule of thumb for beginners. Not going to deny it.
    But this is irrelevant for any site with even the most simple of Content Security Policies.

  • @AjeshDSthegr8
    @AjeshDSthegr8 8 หลายเดือนก่อน

    Reverse psychology works, you just earned a sub

  • @0.lennart
    @0.lennart 8 หลายเดือนก่อน +1

    What about static frontends without ssr? There is no way to use a httponly cookie because you have to access it from js

  • @BolverBlitz
    @BolverBlitz 8 หลายเดือนก่อน +1

    I like your sarcasm, but you should devently make some warnings for new devs.
    Like you said, cookies are automaticly within every request. So also in the once made by mallicus code or xss
    So cookies are even more of a issue than localstorage.
    The "HTTP Only" Cookie was once an attempt to make it secure, but you just call fetch in js and the browser puts in the cookie anyways... Leaking it.
    However, you should always use the "Content-Security-Policy" Headers, this makes sure nothing can make requests to any webserver you did not manualy allow first.
    Then one of the only issues i can think of would be a XSS making a public post on your webpage (in case this is possible) with your secrets, but you can simply check if a post contains a currently valid secret and in case it does just don´t generate the post or invalidate the token like many apps already do it.

  • @abdhelal
    @abdhelal 8 หลายเดือนก่อน

    Nice video. I think also using CSP (connect-src ) could save you from some of these problems

  • @usemt9726
    @usemt9726 8 หลายเดือนก่อน

    just create a backend that is REALLY safe, the internet is going on a cookieless path, so local storage is not that bad

  • @ipigtaiwan
    @ipigtaiwan 8 หลายเดือนก่อน

    Discord be like:Yeah, let's store user token in localstorage!

  • @AndersonPEM
    @AndersonPEM 8 หลายเดือนก่อน +1

    Now how do you do if the application is decoupled from the backend? :)

  • @CitizensCommunity
    @CitizensCommunity 8 หลายเดือนก่อน +3

    I love this, so many who think Linux is safe also just trust all their binaries. This is such a problem.

  • @aGj2fiebP3ekso7wQpnd1Lhd
    @aGj2fiebP3ekso7wQpnd1Lhd 8 หลายเดือนก่อน

    I've often wondered about the security of local storage when using frames as well because the top page and page can use local storage for communication. Will be encrypting data here going forward.

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน +2

      encrypting localStorage is pointless

    • @aGj2fiebP3ekso7wQpnd1Lhd
      @aGj2fiebP3ekso7wQpnd1Lhd 8 หลายเดือนก่อน

      @@ieatthighs why?

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน

      @@aGj2fiebP3ekso7wQpnd1Lhd if you intent to keep an access token there it won't prevent an attacker from using it. they just won't know what is inside which is pointless since those tokens are usually random/encoded json of non critical info

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน

      @@aGj2fiebP3ekso7wQpnd1Lhd I explained but youtube deleted my comment. Thank them

    • @qbasic16
      @qbasic16 8 หลายเดือนก่อน +1

      ​@@aGj2fiebP3ekso7wQpnd1LhdWhere are you going to store the (symmetric) encryption key?
      It's pointless.

  • @stephenjayh
    @stephenjayh 8 หลายเดือนก่อน

    Thank you kind sir

  • @nixjavi7220
    @nixjavi7220 8 หลายเดือนก่อน

    great video!

  • @priyanshuganatra
    @priyanshuganatra 8 หลายเดือนก่อน +3

    0:19 bro predicted the future 😂

  • @Bat-Georgi
    @Bat-Georgi 8 หลายเดือนก่อน

    Ok, so what am I supposed to use instead? Are cookies and session storage any better?

  • @basarokke4403
    @basarokke4403 8 หลายเดือนก่อน +3

    Good Topic. But where to store auth Tokens instead of localstorage? Or do you want to say don't use auth tokens? I don't understand your opinion clearly?

    • @basarokke4403
      @basarokke4403 8 หลายเดือนก่อน

      I want my laravel api in a domain. And my quasar-vue app will consum it. My quasar app is a spa and a cordova app! How to handle this the right way?

    • @hnccox
      @hnccox 8 หลายเดือนก่อน

      store them in a cookie which is httpOnly

    • @cdruc
      @cdruc  8 หลายเดือนก่อน +2

      If you're using Laravel as a JSON API for a web application, do not use tokens - use the regular cookie based authentication as described here:
      laravel.com/docs/10.x/sanctum#how-it-works-spa-authentication
      If you're using Laravel as a JSON api for a mobile app, use token based authentication as described here: laravel.com/docs/10.x/sanctum#mobile-application-authentication
      If you have both a web app AND a mobile app use.... both.
      Use the cookie based auth routes for the web app login, and use the token based login routes for your mobile app.
      ----
      I'm not familiar with quasar, but from the looks of it, I think you can just use cookies

    • @bartoszkrawczyk4976
      @bartoszkrawczyk4976 8 หลายเดือนก่อน

      Just don't manage your tokens with javascript at all. Set it on the server side in a cookie with httpOnly flag. It will be added to every request automatically, it will be handled by your backend, but won't be accessible via javascript.

    • @basarokke4403
      @basarokke4403 8 หลายเดือนก่อน

      @@bartoszkrawczyk4976 this sounds interesting. Thanks you both! Any resources links where can I see a laravel vue spa example?

  • @untitled8027
    @untitled8027 8 หลายเดือนก่อน +11

    set the secure flag on your session cookies too pls

  • @lightprogrammer
    @lightprogrammer 8 หลายเดือนก่อน

    what about sessionStorage?

  • @johnmarkvictorino2788
    @johnmarkvictorino2788 8 หลายเดือนก่อน +5

    So what the solution for this problem? with Vue as SPA and Laravel API as backend

    • @Gornius
      @Gornius 8 หลายเดือนก่อน +2

      Server should support storing token in secure, readonly cookie. Client should not have access to them. Server sets token in secure httponly cookie in login endpoint and server reads token from that cookie.

    • @minimovzEt
      @minimovzEt 8 หลายเดือนก่อน

      @@Gornius that's a load of bullshit, readonly cookies are not secure in any way

    • @Gornius
      @Gornius 8 หลายเดือนก่อน

      @@minimovzEt Yeah, you're right. I meant httponly.

  • @kipchickensout
    @kipchickensout 8 หลายเดือนก่อน

    there are third party extensions to show network packages. the one i found was ugly and cumbersome but it worked, and it wasn't detected by the website

  • @muhamedkarajic
    @muhamedkarajic 8 หลายเดือนก่อน

    Great video!

  • @Simple_OG
    @Simple_OG 8 หลายเดือนก่อน +1

    Ok, i am newbie if not in local storage then where ?

  • @peteredmonds1712
    @peteredmonds1712 8 หลายเดือนก่อน

    Supabase stores the `access_token` and `refresh_token` JWTs in local storage. Is there some reason why this is okay?

  • @bautistaigarzabal
    @bautistaigarzabal 8 หลายเดือนก่อน +1

    Hi! right now I have to authenticate my app, and I was thinking about saving the jwt token in the localstorage, but seeing this video I know it's not the right thing to do.
    The only way I have to use my backend (symfony) is with fetch, I use Axios.
    How should I do the authentication?

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน +1

      If you don't want to go with session cookies localStorage is fine

    • @bautistaigarzabal
      @bautistaigarzabal 8 หลายเดือนก่อน

      I want to use session cookies, but my frontend and backend are in different docker containers, different ports, and possibly different domains, do you recommend any guide that i can follow to use session cookies?

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน

      @@bautistaigarzabal I had the exact same situation and I just went with localstorage. It's fine as long as you know the risks. Remember, even discord uses this method

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน

      @@bautistaigarzabal looks like youtube keeps deleting my responses

    • @MrCh4nk
      @MrCh4nk 8 หลายเดือนก่อน

      @@bautistaigarzabal thats fine, you still can exchange cookies between each service, even though they are in different container, port, domain, zone, just set the cors on the server to allow subdomain/domain where you serve your frontend app to allow credentials, then each of requests fired via axios should have withCredentials set to true and you are good to go

  • @iRoNYwho
    @iRoNYwho 8 หลายเดือนก่อน +3

    so how to handle tokens if you are not laravel developer? Im using session cookie, and take jwt from it. Is it safe?

    • @cdruc
      @cdruc  8 หลายเดือนก่อน +2

      the cookie must be httpOnly - if it’s not, it’s just as safe as localstorage.
      what are you using for backend?

    • @iRoNYwho
      @iRoNYwho 8 หลายเดือนก่อน +1

      @@cdruc golang echo with, jwt and sessions middleware. thx for httpOnly tip, didnt know

  • @Wariowa345
    @Wariowa345 8 หลายเดือนก่อน

    where am i supposed to do? cookies seems even worst

  • @nefrace
    @nefrace 8 หลายเดือนก่อน

    "99% of JS code is not even yours"
    My website has 0 lines of js code right now and it's all mine

  • @rebok232
    @rebok232 8 หลายเดือนก่อน +9

    Doing it on the server's side can be dangerous too, cause if the server automatically reads the cookie to auth you, then what if someone wants to do csrf on you? And also what if your backend is php and you installed a sketchy library, wouldn't it work cause it's server side or what? Solution: Just install trusted libraries

    • @SirEdges_Adejo
      @SirEdges_Adejo 8 หลายเดือนก่อน +1

      LoL, you just want to comment 😂

  • @jbarriossandrea
    @jbarriossandrea 8 หลายเดือนก่อน

    Where else should I store my tokens then?😅

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน

      localStorage is enough

  • @lucsoft
    @lucsoft 8 หลายเดือนก่อน +1

    Sounds like snake oil, if you have XSS then you have already a compromised system. I find local storage more straight forward and I only need to care about XSS not some crazy CSRF or extra security headers.

  • @arnhazra
    @arnhazra 8 หลายเดือนก่อน

    Very good explaination. But what if a npm package tracks all the requests that I am sending with body header and everything including response. How to be safe from that ?

    • @mpcref
      @mpcref 8 หลายเดือนก่อน

      use deno instead of node.

    • @tukangeksperimen7844
      @tukangeksperimen7844 8 หลายเดือนก่อน +1

      ​@@mpcref why?

    • @mpcref
      @mpcref 8 หลายเดือนก่อน

      @@tukangeksperimen7844to be safe from the concern you're raising.

  • @harryhack91
    @harryhack91 8 หลายเดือนก่อน

    So you're basically implying that we should go back to a monolith architecture and use Http-only cookies.

  • @chrismanning5232
    @chrismanning5232 8 หลายเดือนก่อน +1

    The real message of this video should've been to stop using random ass npm packages lol

  • @lu2000luk
    @lu2000luk 8 หลายเดือนก่อน

    Man, unfortunatley i dont handle auth for my app, my DB does and it stores them in localStorage, and, in some parts of my code extracting tokens from it is actually used. For example to auth the same user across different domains. Thanks for the video btw.

  • @Markus-r6g
    @Markus-r6g 8 หลายเดือนก่อน

    make sure to tell people how to not store auth tokens, how to know if they already are.

  • @hidvpohaidvhozxcvnpzxov7835
    @hidvpohaidvhozxcvnpzxov7835 8 หลายเดือนก่อน

    good video

  • @IIKACHOW95
    @IIKACHOW95 8 หลายเดือนก่อน

    Guys I think he doesn’t want us to save auth tokens in LocalStorage

  • @nomadshiba
    @nomadshiba 8 หลายเดือนก่อน +1

    maybe 5% of js is not mine, i write everything

    • @FabioMafu
      @FabioMafu 8 หลายเดือนก่อน

      I believe most devs write everything

  • @gabboman92
    @gabboman92 8 หลายเดือนก่อน

    that could also happen in apps...

  • @OnyxGouws-u2h
    @OnyxGouws-u2h 8 หลายเดือนก่อน

    Simple, don’t use NPM, there I solved it

  • @theblckbird
    @theblckbird 8 หลายเดือนก่อน

    Awesome!

  • @villandoom
    @villandoom 8 หลายเดือนก่อน

    Discord be like:

  • @mauricebagalwa6923
    @mauricebagalwa6923 8 หลายเดือนก่อน +1

    Noted 😎 !

  • @4fortyfour
    @4fortyfour 8 หลายเดือนก่อน +1

    tell this to discord

  • @aleclippe6213
    @aleclippe6213 8 หลายเดือนก่อน

    How does this apply to the Microsoft tech stack and azure ad

  • @koushikseal
    @koushikseal 8 หลายเดือนก่อน

    CSP

  • @Mempler
    @Mempler 8 หลายเดือนก่อน

    nice, but how the fuck are you store secure tokens in a server-less application.
    I mean literally, you only get an SPA without any code running on the server other than sending a static file.
    every single solution will expose the token in an easily accessible way.

  • @rajikkali2381
    @rajikkali2381 8 หลายเดือนก่อน +13

    No no no. Localstorage is fine. Cookies are no more secure. So tired of hearing this argument on youtube and medium. Even supabase uses this method.

    • @Andrew-jh2bn
      @Andrew-jh2bn 8 หลายเดือนก่อน +2

      I mean, everything's on a spectrum. Local storage is more vulnerable to compromised JavaScript dependencies then a http only cookie. Of course, depending on how sophisticated the malicious dependency, it could make api calls to your backend while you're visiting the page in your browser, but that would have to be more targeted.

    • @abdirahmann
      @abdirahmann 8 หลายเดือนก่อน +1

      yeah me too, am tired of hearing this! 😂😂😂🤡

    • @michaelbitzer7295
      @michaelbitzer7295 8 หลายเดือนก่อน +2

      HttpOnly cookies are more secure.

  • @MedChergui
    @MedChergui 8 หลายเดือนก่อน

    What if i encrypt the token before i store it and decrypt it when i want to use it ?

    • @qbasic16
      @qbasic16 8 หลายเดือนก่อน +1

      And where will you store the key for your (symmetric) encryption?

    • @MedChergui
      @MedChergui 8 หลายเดือนก่อน

      @@qbasic16 if i were using SSR this will be at the server.

    • @qbasic16
      @qbasic16 8 หลายเดือนก่อน +2

      @@MedChergui and what's the point on storing an encrypted token on the server? You still have to authenticate the requests from a (valid) client.

    • @MedChergui
      @MedChergui 8 หลายเดือนก่อน

      @@qbasic16 The encrypted token will be in localStorage (aka Clinet) but the key to decrypt will be in server.
      Decrypt it then check if the encrypted token does match.

    • @MedChergui
      @MedChergui 8 หลายเดือนก่อน

      @@qbasic16 The encrypted token will be stored in the client, but the key will be in server.
      The server decrypt the encrypted token and verify the user

  • @RickardBrent
    @RickardBrent 8 หลายเดือนก่อน +3

    Skip the fluff and get to the point.

  • @milefiori7694
    @milefiori7694 8 หลายเดือนก่อน

    Why don't encode your auth token then? Even if its stolen it's meaningless to the attacker

    • @EpKjelltzer
      @EpKjelltzer 8 หลายเดือนก่อน +3

      Meaningless in what sense? As long as the token is valid proof of authentication, the attacker will be able to use it to impersonate the user they stole it from.

    • @ieatthighs
      @ieatthighs 8 หลายเดือนก่อน +1

      encode? Then the attacker can just decode the token, what are you talking about

    • @pali122
      @pali122 8 หลายเดือนก่อน

      @@EpKjelltzer But adding the user ip, and browser or extra info should help mitigate those things, plus a refresh token stored on the server. I mean that's the usual JWT pattern. An attacker could decode it but the token should not be valid from anywhere

  • @TheNovakon
    @TheNovakon 8 หลายเดือนก่อน +2

    To build code above malicious packages is very bad idea. Dislike.

    • @cdruc
      @cdruc  8 หลายเดือนก่อน +6

      huh?

    • @ZawHlaingWin-ri1js
      @ZawHlaingWin-ri1js 8 หลายเดือนก่อน

      Are u stupid or smth?

    • @svendpai
      @svendpai 8 หลายเดือนก่อน +3

      Try giving the video a second watch, it seems like you misunderstood the message of the video.

    • @DerLuukee
      @DerLuukee 8 หลายเดือนก่อน +1

      Bot 😅😂

  • @xajiraqab
    @xajiraqab 8 หลายเดือนก่อน +1

    document.cookie ? :3

    • @mehedimi
      @mehedimi 8 หลายเดือนก่อน +1

      You can not access HTTP Only Cookie using document.cookie.

    • @xajiraqab
      @xajiraqab 8 หลายเดือนก่อน +1

      @@mehedimi if i cant read tokens using js. how can i make refresh token to refresh access token when it expires

    • @michaelbitzer7295
      @michaelbitzer7295 8 หลายเดือนก่อน +1

      ​@@xajiraqabyou simply send a request to the auth server to issue a new token.

    • @xajiraqab
      @xajiraqab 8 หลายเดือนก่อน

      @@michaelbitzer7295 how if u cant read refresh token

    • @Cloneee
      @Cloneee 8 หลายเดือนก่อน

      ​@@xajiraqabbrowser will do the job