How to Make Your React App Safer

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 86

  • @o_glethorpe
    @o_glethorpe 2 роки тому +8

    You mentioned that it's not good to store jwt in localstorage since is public, can be accessed by browsers extensions etc..., well, cookie can be accessed as well, httponly can be intercepted by extensions, so where would you store a jwt? The title says: How to Make Your React App Safer, but you only pointed out a problem...

    • @PedroTechnologies
      @PedroTechnologies  2 роки тому +4

      I mean, there will always be vulnerability. For example, not only can httpOnly cookies be accessible by the chrome extension api, but if a browser doesn't support httpOnly cookies, then it will treat it like a normal cookie. My point with this wasn't to give a 100% solution, because there isn't one. I just pointed out what you should do to minimize the risk. The risk from using cookies is way less then the risk of using session/local storage.

  • @nonequivalence1864
    @nonequivalence1864 2 роки тому +85

    I've been a pro software engineer with over 6yrs of experience, here's my $0.02 on this - there really isn't a safe way to store tokens. Local storage, cookies, etc are all vulnerable. All websites, even major ones, use one of these and get hacked regularly but the media never talks about it due to not making their stock prices more volatile than it already is. The security of your application 99.9% depends on how well your backend is. Frontend code will ALWAYS be vulnerable no matter which framework, library or language you use which means your desired method of storing auth tokens "safely" is also vulnerable.

    • @adnanhussain1460
      @adnanhussain1460 Рік тому

      agree

    • @AG-ur1lj
      @AG-ur1lj Рік тому +2

      If only React were only front end code

    • @yousefwaleed-e9w
      @yousefwaleed-e9w Рік тому

      @nonequivalence1864
      Could you please explain how do i make my back end more secure or provide me any blog or channel that you think it might help me
      I use node.js btw
      And Thank you ❤

    • @GoKotlinJava
      @GoKotlinJava Рік тому

      @@AG-ur1lj lmao

    • @edmonvevo5691
      @edmonvevo5691 10 місяців тому +1

      pro software engineer ? it’s something new haha

  • @carliey
    @carliey Рік тому +3

    Where should be store the jwt then pedro?

  • @ozoemenabright7925
    @ozoemenabright7925 2 роки тому +5

    Not a new dev but you caught me there at saving cookies to local storage for easy accessibility. Thanks for the knowledge

    • @ThanHtutZaw3
      @ThanHtutZaw3 2 роки тому

      I also saved in localstorage too . but these info from firebase . May be it is safe.

    • @hyzyr
      @hyzyr Рік тому

      Sorry, but nosense, cookies are same vulnerable to XSS attacks as localStorage, it doesn't matter where you store them, that's why we create tokens so they are encrypted, the only thing you can do is add a little more information in the token. such as the user's browser, device, and checking it on the backend

  • @tomasburian6550
    @tomasburian6550 2 роки тому +3

    Dude, you are among my top favorite dev video creators! Keep up the great job!

  • @jay8118
    @jay8118 2 роки тому +8

    Love from India... 🙌

  • @rhiannonmonks6894
    @rhiannonmonks6894 2 роки тому +4

    Great discussion on JWT and your point about a huge hit via NPM packages is....accurate and scary!

  • @eugeneesterhuizen4263
    @eugeneesterhuizen4263 2 роки тому +5

    Congrats on the 100k man! So happy that you keep going up, your channel has been a huge help and the content keeps getting better. Great job.

  • @SxAde
    @SxAde Рік тому +1

    Hi! In the example you gave where the user manually types a URL, is it safe to just set the input type to "url"?
    I found out that forms do validate url input types when calling the onChange and onSubmit events, but I wonder if that's enough and if it also works when the input is not within a form.

    • @victorohachor203
      @victorohachor203 Рік тому +1

      Agreed... Except that you can manually change the input type to text in the developer tools before submitting. So, it is still not safe relying on it completely.

  • @harimuthum3407
    @harimuthum3407 2 роки тому +2

    Please make a video on Authentication and Authorisation for React. Authentication and Authorisation for Node Express were very useful.

  • @thegrizzlywolf5927
    @thegrizzlywolf5927 Рік тому

    the only person ever when i heard him said please do like to this video i go fast to do the like thank u so much pedro

  • @davidrawlings7067
    @davidrawlings7067 2 місяці тому

    Fantastic video! Thank you

  • @codewithguillaume
    @codewithguillaume 2 роки тому +2

    About Next 13, how would you deal with authentication? :)

    • @PedroTechnologies
      @PedroTechnologies  2 роки тому +2

      Tbh ive been sick so I haven't been totally up to date with the new release yet! I will try it out and for sure make a vid on my opinions!

    • @codewithguillaume
      @codewithguillaume 2 роки тому +1

      @@PedroTechnologies oh god I hope you are doing better ! Thanks for your work my friend

  • @afickredox4121
    @afickredox4121 2 роки тому

    yesssir, thanks to make us up to date with ur videos and make me more aware what i'm doing with my web application , love it

  • @uttekarlsson3265
    @uttekarlsson3265 2 роки тому +3

    Nice, could you do a tutorial on how to implement Pagination in React Table? Where you fetch next page by API and not load everything at once.

    • @uttekarlsson3265
      @uttekarlsson3265 2 роки тому

      He have made one before but not with react table. You can find it here: ua-cam.com/video/HANSMtDy508/v-deo.html. However I also prefer react table.

    • @adnanhussain1460
      @adnanhussain1460 Рік тому

      @@uttekarlsson3265 implement the same logic with react table

  • @umangbhatnagar1415
    @umangbhatnagar1415 2 роки тому

    lots of love and respect from INDIA

  • @adnanhussain1460
    @adnanhussain1460 Рік тому

    rock on Pedro, you're doing a great work and CONGRATS

  • @PanlasangMotour
    @PanlasangMotour 2 роки тому +1

    Brother would like to ask can i apply it also on my angular app 🤔

  • @abongilebono7999
    @abongilebono7999 2 роки тому

    i agree local storage is not the best place to store your tokens. So as a beginner I'm asking which are the best places to store them ? It's important for me plz answer

  • @randomforest_dev
    @randomforest_dev 2 роки тому +3

    Thanks for your video! Is there any solution for securely storing jwt token ? If we store it in httpOnly cookie, we need server side proxy for our react app (which means our react app will become a Nodejs app) or if our REST Api handle cookies, it will become stateful which is against REST.

    • @Stormface16
      @Stormface16 2 роки тому +1

      Had the same thing on my table today as well, i really hoped there was a solution given here

    • @Weagle1337
      @Weagle1337 Рік тому

      Nowadays all methods has a vulnerability problem, it's easy to say that save JWT in LocalStorage is dangerous, but nothing is a silver bullet, you just must take a lot of care of your backend, rotating the JWT signature secret regulary and having a system that allows the user to invalidate/ban a stolen JWT based on the identity saved on it

  • @MrSYLVESTER444
    @MrSYLVESTER444 2 місяці тому

    How do one create a backdoor in his react code just in case client failed to payup

  • @jsantos1220
    @jsantos1220 2 роки тому

    So whats the way to handle tokens? cookies? you didn't say it, or the answer is cookies with corrects cors?

  • @piero.guerrero
    @piero.guerrero 2 роки тому +1

    So at the end, where to store the security tokens in the frontend?

    • @adnanhussain1460
      @adnanhussain1460 Рік тому +1

      there isn't any foolproof way to store, its kind of anything is vulnerable on frontend and your app security 99% depends on your backend, so make a double check on backend upon token coming from frontend in a req when you are doing some critical action

  • @user-gnwolmgkqpcn15829
    @user-gnwolmgkqpcn15829 Рік тому

    your advice is so good to think about even though mine is based on vue framework. thank you for your work and video.

  • @realmanproject7529
    @realmanproject7529 2 роки тому +1

    Thanks, bro, xss is pretty interesting

  • @jorgedavalos5663
    @jorgedavalos5663 2 роки тому

    would you ever do a todo tutorial or something like that trying solid.js?

  • @piuspolocha
    @piuspolocha 2 роки тому +2

    Pedro this is nice video but we will really appreciate it if you build of full stack application consisting of Admin and user dashboard using JavaScript and nodejs for backend
    Thanks you are the best so far

  • @althafahd9872
    @althafahd9872 2 роки тому +1

    hi sir, in you github repo is their are any real world professional projects publically. plz can u refer one of them for review for me

  • @jeevandza3464
    @jeevandza3464 2 роки тому

    How extensions can excess my browser local storage, isn't that protected inside my browser ?.

  • @shinobi_coder88
    @shinobi_coder88 2 роки тому

    Pedro, if we're using like Firebase Auth, Auth0, or NextAuth isn't the JWT pre-handled already?

  • @nikhilgupta6655
    @nikhilgupta6655 Рік тому

    If you could animate things up and show us that instead of your face in full screen mode, I think that would be helpful. You can keep your face video at the bottom/ top in small screen overlapped like in streaming videos. Just a suggestion. Cheers

  • @Wakkyguy
    @Wakkyguy 2 роки тому +1

    If we have to retain the user session between revisits to our application, where should we store the jwt? Cookies?

    • @napoleonbonaparte1260
      @napoleonbonaparte1260 2 роки тому

      Redis cache

    • @Wakkyguy
      @Wakkyguy 2 роки тому

      @@napoleonbonaparte1260 then we have to maintain user session on the server side.

    • @eliasgarcia1146
      @eliasgarcia1146 2 роки тому +2

      I was left with the same doubt since it does not mention where to store it

    • @Azoraqua
      @Azoraqua 2 роки тому +2

      What I learned is that it's best to store JWT tokens in cookies, and use them for any API request as it goes on; Make sure to keep the tokens valid for a limited time-span, determined by the nature of the app.
      After that, revoke access (either directly, indirectly or even both).

  • @ehfajkhan
    @ehfajkhan 6 місяців тому

    Good one, would be better if you have explanation with some digrams.

  • @mahmoodnazari1004
    @mahmoodnazari1004 2 роки тому +1

    Hi Pedro, thanks for your useful tutorials. I learned a lot of things until now. If you make another video about "How to load content based on language changed from mongo DB with react js?", it will also become another useful video. Thanks

  • @orarbel167
    @orarbel167 2 роки тому +2

    I didn't understand why jwt in localstorage is unsafe 🙈 If the jwt is encrypted what can a attacker do with it? The attacker also doesn't have the BE details (its in .env file) so the attacker can't use the jwt to update the data in the DB

    • @abdirahmann
      @abdirahmann 2 роки тому +13

      you have misundertood 4 things so i'll help you understand them.
      jwts are not encrypted, they are signed!, both encryption and signing use public private key pairs though, there is a difference between encryption and signing.
      for example:
      ENCRYPTION -
      1. if i wanted to tell you a secret but there were alot of people that will listen to us, i will ENCRYPT the secret, we will agree beforehand on how to decrypt encrypted data, then i will encrypt the secret and give you the encrypted secret, since we both agreed on how to decrypt data before, you'll be able to decrypt the secret and read it, since all the other people dont know how to decrypt the secret, it will seem to them as a bunch of useless data.
      SIGNING -
      2. on the other hand, if i wanted to announce something to the people and the people wanted to be 100% sure it was me and not an impersonator, i will announce my public key to the people and everyone will have a record of my public key, then i will SIGN the message that i want to announce with my private key, the people then receive my announcement and they will verify the signature in the message that i signed using my public key that i shared with them.
      3 .If the jwt is encrypted what can a attacker do with it? -
      first of all, its not encrypted, its signed as you read above, infact you can go to jwt.io, paste in a jwt that you have and they'll tell you the information contained in the jwt. if an attacker gets hold of a jwt, they can impersonate the person that received that jwt from the backend, the backend only checks to see if the jwt is valid by checking if the signature on the jwt is valid and now that this attacker has a jwt they stole, the backend would allow them to do anything the owner could do and thats BAAAAAD.
      4. The attacker also doesn't have the BE details (its in .env file) so the attacker can't use the jwt to update the data in the DB
      whatever logic you wrote in the app update the data in the db, your users dont update the DB directly, your backend does, and what else does your backend allow?? 🤔, it allows request from the user on the internet 😄, processes the requests and UPDATES the DB to store the information received from the user. you .env file defines what environment your app runs on and what DBs to connect to.
      The attacker initially doesnt know how your backend is setup BUT they can enumerate your backend by analyzing the response the app returns when they do certain things and hence why the pedro says its better to return a generic statement to the user instead of returning the message of the error which is usually contained in the message field (err.message)
      i hope this cleared up some confusion and taught you something new, have fun and take care
      byeeeeeeeeeee

    • @dixztube
      @dixztube 2 роки тому +1

      @@abdirahmann great response. I learned a few things in there as far as jwt being signed

    • @sinc1802
      @sinc1802 2 роки тому +1

      @@abdirahmann This comment deserves a pin

  • @tech3425
    @tech3425 2 роки тому

    *Alternative title*
    Battle Scars: PEDRO

  • @wagnerlessa5518
    @wagnerlessa5518 2 роки тому

    Joga duro man, parabens denovo.

  • @hatosenshi
    @hatosenshi 2 роки тому

    Hello pedro ! First of all, It's been like 1 year I wanted to leanr MERN but couldn't because I felt like the youtuber wasn't able to explain it well to a beginner. But after watching your 1 hour course, I want to thank you because I understand better now.
    But I have a little problem If you ( or someone else ) can help... I tried to connect my cluster to mongodb compass but I got this error "Server selection timed out after 30000 ms". Does someone knows what's the reason for this ?
    Thanks !

  • @favouritejome
    @favouritejome 2 роки тому

    Please could you make a video about Authentication, how to properly save jwt tokens without localstorage, how to refresh the token? I know this is a lot, but I've been having issues with this

  • @Pedro-gu7jj
    @Pedro-gu7jj 2 роки тому

    mora no brasil mano ?

  • @marianaangel5338
    @marianaangel5338 2 роки тому

    I liked the lesson so much! Good job! Still waiting for Nextjs with redux toolkit.....

  • @synt-x6458
    @synt-x6458 2 роки тому

    Awesome. Would be great if you drop a video about S.E.O for react apps

  • @imkir4n
    @imkir4n 2 роки тому

    Nice vid pedro

  • @juanurani5839
    @juanurani5839 2 роки тому

    Yo said what not to do with jwt but you didn't say what to do with jwb...

  • @arunkb6452
    @arunkb6452 2 роки тому

    Love from kerala❤

  • @wizz1e80
    @wizz1e80 9 місяців тому

    YOU DIDN'T GIVE ANY RECOMMENDATIONS ABOUT WHERE ELSE TO STORE TOKENS
    IF I'M NOT USING LOCAL STORAGE OR COOKIES
    WHAT DO I USE??????

  • @arzooqadri8805
    @arzooqadri8805 2 роки тому

    It's out of context but, can u make a Vedio on Api integration in React js. I'll appreciate it thnx!

  • @Babbili
    @Babbili 2 роки тому +2

    create react app has never been safe with all these redos valunerablities

  • @VishalSharma-rn7mt
    @VishalSharma-rn7mt Рік тому

    Awesome

  • @ACHTech20
    @ACHTech20 2 роки тому

    That's encoding not encryption

  • @wagnerlessa5518
    @wagnerlessa5518 2 роки тому

    Rumo ao 1M

  • @EAbdoAhmedSayed
    @EAbdoAhmedSayed 2 роки тому

    Egyptian announced 11/ 11 a revolution against the decorators alsis
    Could you speak about
    Our Egyptian revolution

  • @kashmirtechtv2948
    @kashmirtechtv2948 Місяць тому

    bro❤❤

  • @oncoding4520
    @oncoding4520 Рік тому

    like and comment done :)

  • @wagnerlessa5518
    @wagnerlessa5518 2 роки тому

    Mr Beast quem?

  • @palyanytsia
    @palyanytsia 9 місяців тому

    This video just a waste of time. No examples or solutions provided

  • @huzaifac137
    @huzaifac137 2 роки тому

    It sucks to know you cannot use JWT safely in your client app that's why I'll stick to localStorage and JWT expiring after one hour until I'll learn httpOnly ( which is also not full safe)

  • @rayhanislam7518
    @rayhanislam7518 2 роки тому +1

    It's not effective for everyone. do code It'll helpful for everyone