Cross-site request forgery | How csrf Token Works

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ต.ค. 2024
  • In this video you will learn how csrf token works and to be protected agains csrf attacks.
    Visit amigoscode.com for the entire course
    ⭐️ FEW MORE THINGS BEFORE I FORGET ⭐️
    ▶️ Don't forget to subscribe | bit.ly/2HpF5V8
    ▶️ Join Closed Facebook Group for discussion and early access videos and courses | bit.ly/2FbuIkx
    ▶️ Follow me on Instagram | bit.ly/2TSkA9w

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

  • @StyleTrick
    @StyleTrick 3 ปีที่แล้ว +5

    How does this prevent the hacker from performing CSRF? The hacker can just read the XSRF-TOKEN Cookie from the client side code and add it as a header? Would love to get some clarity.

    • @shyamsundargoyal9251
      @shyamsundargoyal9251 2 ปีที่แล้ว

      I think if you are saving this token in cookie then it should be like session ids. A unique token for every logged in user

    • @chessking3248
      @chessking3248 2 ปีที่แล้ว

      I have the same question

  • @ruslannovikov8374
    @ruslannovikov8374 ปีที่แล้ว +1

    I am very thankful for this explanation. Your channel allows me to get really helpful coding knowledges and also to improve my English!!!

  • @dzen1234
    @dzen1234 2 ปีที่แล้ว +3

    I not completely understood. If CSRF token is saved in cookies the user browser will send cookies at intruder's link opening. Looks like sending CSRF token in some hidden form field is much better.

    • @shyamsundargoyal9251
      @shyamsundargoyal9251 2 ปีที่แล้ว

      You can make that cookie's samesite flag as strict. So it won't be sent on cross site requests

    • @chessking3248
      @chessking3248 2 ปีที่แล้ว

      @@shyamsundargoyal9251 The final request in a CSRF attack is not cross-site .

    • @mach1ne722
      @mach1ne722 18 ชั่วโมงที่ผ่านมา

      You are correct. You need to have the CSRF token returned by the server, ideally somewhere in response body. If it's returned within the cookie, cross-site requests will include the Cookie (legitimate token) and the forged request might be accepted, depending on the backend logic.
      However, the CSRF token could be returned within the cookie, client-side JavaScript could there-after extract it via document.cookie directive and manually add it as a X-CSRF-TOKEN header. When the server expects the the token from the header and not the cookie, situation changes, because cross-site requests won't have this header automatically attached (unlike cookie) and the attacker doesn't know the victim user's token value, so the abuse won't be possible.

  • @user-cx5ry5tt6s
    @user-cx5ry5tt6s 4 ปีที่แล้ว +2

    MY BROTHER!! Thank you so much ! I’m bad in English, but I excellent understand you. Respect! DjazakAllah hayran

  • @aldovargas8514
    @aldovargas8514 2 ปีที่แล้ว

    Is it expected that the XSRF token changes on every call? I have implemented but any call will retrieve a different token

  • @geekthegeek730
    @geekthegeek730 3 ปีที่แล้ว +2

    It was very helpful to me. Thanks man for explaining this concept in detailed

  • @dev.jacek.grzegorczyk
    @dev.jacek.grzegorczyk 4 ปีที่แล้ว +2

    Hi, is it possible to run off the csrf "Are you sure you want to logout" screen in spring boot security for a non logged in users? By default it shows even if a user did not log in.

  • @shashikumar9068
    @shashikumar9068 4 ปีที่แล้ว +1

    Hello...Is it possible to enable CSRF and HttpOnly/Secure(for JseesionId) in the same time?

  • @gofarputra9284
    @gofarputra9284 2 ปีที่แล้ว

    Is the csrf token is changing every requests or remain the same?

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

    extremely well explained and enlightening, thank you very much!!!

  • @marcosernestoalarconhermoz2470
    @marcosernestoalarconhermoz2470 3 ปีที่แล้ว

    If it wasn't too much trouble, is the example repository available?

  • @rezokobaidze8501
    @rezokobaidze8501 2 ปีที่แล้ว

    when i get csrf token from backend it is not set in cookie automaticaly

  • @borisdimitrijevic-v6d
    @borisdimitrijevic-v6d ปีที่แล้ว

    Amigo can u please help em solve dissapering csrf in react application using spring boot

  • @uvillanueva95
    @uvillanueva95 4 ปีที่แล้ว

    I understand how CSRF attack works,but, why the cookie protects the server? The attacker cannot copy that CSRF token inside the cookie? If you have the client token and the user token, you have all, no?

    • @cse8617
      @cse8617 4 หลายเดือนก่อน

      Browser is smart enough to only allow a website to access its own cookie, now website can access the cookie of other website

  • @sthakor10
    @sthakor10 3 ปีที่แล้ว +3

    Very well explained. Thanks

  • @robgreen9112
    @robgreen9112 4 ปีที่แล้ว

    which course is this a part of? youtube is not linking the previous episode

    • @EgorlandiaxTsar
      @EgorlandiaxTsar 2 ปีที่แล้ว

      Hello! Here is the link (SpringBootSecurity) th-cam.com/video/her_7pa0vrg/w-d-xo.html

  • @Aman-Thakor
    @Aman-Thakor 4 ปีที่แล้ว +1

    Sir, If I'm using angular as frontend and rest API in spring boot with security at the backend and I'm not using cookies anywhere in the entire application, I'm using localStorage. Does it make sense to use CSRF and if yes then how when I'm not using cookies? Eagerly waiting for your reply!

    • @kishoreramana1
      @kishoreramana1 2 ปีที่แล้ว

      best way is sending the token in the hidden field.
      [...]

    • @shyamsundargoyal9251
      @shyamsundargoyal9251 2 ปีที่แล้ว

      @@kishoreramana1 I think for this to work you need to send a changing token every time because if a hacker is targeting a particular site he can use the value of this csrf token if it is same always.

    • @kishoreramana1
      @kishoreramana1 2 ปีที่แล้ว

      @@shyamsundargoyal9251 we would need to generate a new csrf token whenever user logs in or refreshes the session, then it would be unique for that session.

    • @mach1ne722
      @mach1ne722 18 ชั่วโมงที่ผ่านมา

      If you are using localstorage and utilizing this session ID within the header, such as Authorization: Bearer and not Cookie, then your app is secure.
      Reasoning: Cross-site malicious requests will have only victim user's session Cookies attached within the request, other headers won't be attached automatically, meaning that requests won't pass as authenticated, preventing the attack.

  • @geeksforstudy7661
    @geeksforstudy7661 ปีที่แล้ว

    csrf token every time change per post request how to handle in angular

  • @kaarropll95756
    @kaarropll95756 3 ปีที่แล้ว

    my spring do not creat the scrf token, i have no cookies :(( help

  • @ceki9900
    @ceki9900 2 ปีที่แล้ว

    I'm not getting any cookie when sending get request?

  • @brian_mckenzie8317
    @brian_mckenzie8317 4 ปีที่แล้ว

    I have a question ... I already have the knowledge on IDOR, CSRF vulnerabilities but I need to practice .. like chess ... I am happy there are softwares I can practice on relating to chess ... because I can test out ..reaarange..apply...try out anything I have learnt ... so saying that ..
    are there any websites or softwares I can buy that has like 100's of IDOR vulnerabilities that I can use Burp on and practice all night?? Thanks.

    • @amigoscode
      @amigoscode  4 ปีที่แล้ว +1

      not sure I am afraid

    • @gindudheer5539
      @gindudheer5539 4 ปีที่แล้ว

      Yes, OWASP has a few vulnerable by design websites for you to practice on. Check it out

  • @arghyamitra3281
    @arghyamitra3281 ปีที่แล้ว

    If we are using jwt do we need csrf enabling?

  • @avatargirase
    @avatargirase 4 ปีที่แล้ว +2

    How this prevent someone from impersonating by using the same csrf token?

    • @StyleTrick
      @StyleTrick 3 ปีที่แล้ว

      Yes, the hacker could write code to simple get the XSRF-TOKEN from the cookies on the client side?

    • @shyamsundargoyal9251
      @shyamsundargoyal9251 2 ปีที่แล้ว +1

      @@StyleTrick the cookie that you are sending should have samesite flag as strict. So it cannot be sent with cross site requests. Also to avoid xss, cookie should be httpsecure so that client side js cannot access it.

    • @ilyaslyusarchuk3664
      @ilyaslyusarchuk3664 2 ปีที่แล้ว

      @@shyamsundargoyal9251 so how does it work from postman (copying the CSRF token) and not from a malicious website?

    • @mach1ne722
      @mach1ne722 17 ชั่วโมงที่ผ่านมา

      The attacker would need to extract the token from victim browser. This could be achieved with for example a XSS attack (Cross-Site-Scripting). XSS almost always defeats CSRF protection as it is more severe client-side vulnerability. In that case, you need to take care of the XSS problem first, or any other form of sensitive data leakage from your site. Once the token is safe, CSRF protections will then hold. Otherwise, hackers cannot get the victim user's valid XSRF-TOKEN and request forgery protection works.

  • @basavaraj2065
    @basavaraj2065 3 ปีที่แล้ว

    Where is the full code/github link for this ?

  • @redaelouahabi731
    @redaelouahabi731 2 ปีที่แล้ว

    Thank you very much, I was sicking for that really

  • @justindavis7654
    @justindavis7654 4 ปีที่แล้ว

    what version of postman are you using my ui looks different from yours

    • @amigoscode
      @amigoscode  4 ปีที่แล้ว

      Justin Davis I was using a deprecated version. But the new one is quite similar

    • @justindavis7654
      @justindavis7654 4 ปีที่แล้ว

      @@amigoscode do you do any front end ui stuff with angular?

    • @amigoscode
      @amigoscode  4 ปีที่แล้ว

      Justin Davis no angular so just react 🙂

  • @justindavis7654
    @justindavis7654 4 ปีที่แล้ว

    hey im not getting all those cookies that your getting all im getting is a jsessionid how do i get what your getting

    • @amigoscode
      @amigoscode  4 ปีที่แล้ว

      Full course is now out. Check my channel for the latest video

    • @truth-seeker-2300
      @truth-seeker-2300 4 ปีที่แล้ว

      Hi Justin, if you have figured out how to get that csrf token while sending a GET request, sharing the workout is highly appreciated :)

  • @АлександрСидоров-ъ1ж7ь
    @АлександрСидоров-ъ1ж7ь 6 หลายเดือนก่อน

    Great video ! Thanks a lot

  • @hadifox
    @hadifox 4 ปีที่แล้ว +1

    hallo amigoscode , if i want to start learn java programming can you share tutorial link for beginner ^_^ , Thank you ...

    • @amigoscode
      @amigoscode  4 ปีที่แล้ว

      planning to record a course

  • @AjayRathor3926
    @AjayRathor3926 9 หลายเดือนก่อน

    Well explained.

  • @rahulsinha3267
    @rahulsinha3267 3 ปีที่แล้ว

    Superb! Well explained!

  • @howiewhite4773
    @howiewhite4773 3 ปีที่แล้ว +1

    Wheres the git?

  • @lifestealerarmlet6795
    @lifestealerarmlet6795 10 หลายเดือนก่อน

    Can you provide source code for this video

  • @عابثالأخير-ز9ي
    @عابثالأخير-ز9ي 4 ปีที่แล้ว

    sir can you give one cousre about BDA postgresql

  • @ginadi9733
    @ginadi9733 4 ปีที่แล้ว

    Thank you.

  • @chocciemliki7910
    @chocciemliki7910 4 ปีที่แล้ว +1

    I HATE FUCKING GAMESTOP KEEP SAYING IM TRYING TO DO THIS

  • @ugurersoy4304
    @ugurersoy4304 4 หลายเดือนก่อน

    great

  • @عابثالأخير-ز9ي
    @عابثالأخير-ز9ي 4 ปีที่แล้ว +1

    amazing your channel

    • @amigoscode
      @amigoscode  4 ปีที่แล้ว +1

      Thanks. Subscribe for more

  • @chocciemliki7910
    @chocciemliki7910 4 ปีที่แล้ว

    I JUST WANT A FUCKING CONTROLLER AND I DONT HAVE MY CREDIT CARD ON ME SO IM DOING IT ONLINE