Cross Site Request Forgery - Computerphile

แชร์
ฝัง
  • เผยแพร่เมื่อ 31 พ.ค. 2024
  • If you don't secure your web forms, one mistaken click could be all it takes for your users to delete their own accounts. Tom Scott explains.
    / computerphile
    / computer_phile
    More from Tom Scott: / enyay and / tomscott
    Hacking Websites with SQL Injection: • Hacking Websites with ...
    Cracking Websites with Cross Site Scripting: • Cracking Websites with...
    This video was filmed and edited by Sean Riley.
    Computerphile is a sister project to Brady Haran's Numberphile. See the full list of Brady's video projects at: bit.ly/bradychannels

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

  • @ionlymadethistoleavecoment1723
    @ionlymadethistoleavecoment1723 8 ปีที่แล้ว +1459

    As someone who is a complete novice, and is trying to learn about how to make websites, Tom Scott has made me terribly afraid of screwing something up and having a massive security hole.

  • @ja-vishaara
    @ja-vishaara 9 ปีที่แล้ว +1016

    Tom, I'm never going to your blog, that's for sure now.

  • @Sam_596
    @Sam_596 6 ปีที่แล้ว +152

    "But since then, it's got a bit more complicated"
    -Tom Scott, 2013, describing the internet and the history of the universe in one sentence.

  • @olatrials
    @olatrials 9 ปีที่แล้ว +607

    The funniest thing about your videos is when you talk as if you were the server, interpreter, code or whatever! It would be funny as hell if that was the case, imagine trying to do something malicious, and having the server respond "Well, that's wrong. I'm not having that." in Tom's voice!

  • @o2dyt
    @o2dyt 10 ปีที่แล้ว +365

    "My hand has lower ambitions than my brain does"
    Yeaaah I know the feel...

  • @VictorFrost
    @VictorFrost 10 ปีที่แล้ว +307

    I love how passionate Tom is about this. You can really see it in his face and hear it in his voice.

  • @MozQit0
    @MozQit0 10 ปีที่แล้ว +109

    After just graduating with a Bachelor of Computer Science, I can safely say I would have loved to have this guy as a lecturer; he explains things simply, clearly, interestingly and correctly! I'd like to say a big thanks to the Tom and the Computerphile team for spending their time and effort to make these great videos!

  • @craftxbox
    @craftxbox 7 ปีที่แล้ว +236

    where's the brown paper?

  • @luiscanamarvega
    @luiscanamarvega 9 ปีที่แล้ว +195

    Please, don't ever stop making these.

  • @matts.1352
    @matts.1352 10 ปีที่แล้ว +179

    I remember 6 years ago (I was 12), I'd mess around with chat rooms for fun. Of course, doing so itself was stupid, but it taught me about modifying post-actions and functions, and also about proper security in how users interact with websites.
    Basically, I had a plugin that let me edit post data before it was sent to the site. I'd mess around with the chat a few times, see what values changed in the post data, and then figured out what separate parts and values in the data were for. Eventually, I figured out how to modify the sessionID to be the same as other users, so that I didn't have to be in the chat to play around with it. I also learned how to mess with chat servers screen-name authentication, and to modify my screen-name when I was in the chat. Worst-yet, I learned how to modify user-permissions and mess around with the admin-panel login page so that the chat server thought I was an authentic admin that logged in through the admin-panel and let me use admin operations.
    Of course, at the time I used it for immature things, but I eventually started thinking of ways for how the website could have avoided those problems. That sort of thinking helped inspire me to think in-depth about security in my programming projects.

  • @123456789robbie
    @123456789robbie 10 ปีที่แล้ว +51

    Tom Scott is quickly becoming one of my favourite people on the internet. He's the kind of person i'd have wanted to be best friends with if we'd been kids at the same time and place

  • @TheWP120
    @TheWP120 8 ปีที่แล้ว +141

    These Tom Scott videos are so addictive, I can't stop watching! xD

  • @user-uc4ll6kx1g
    @user-uc4ll6kx1g 8 ปีที่แล้ว +83

    This video inspired me to try to "steal" my CSRF token (as if I was trying to hack my own account). I the process I reinvented cross-origin HTTP requests and clickjacking. Turns out both this attacks are well-known and defended against.

  • @MisterPorkchops
    @MisterPorkchops 10 ปีที่แล้ว +56

    Tom is probably my favorite person on this channel. I just love the way he talks and I love the topics he has.

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

    These are some of my favorite vids on computerphile! Security issues affect everyone and we need more clear explanations. I'd love for Tom to tackle jailbreaking.

  • @AndersEvenrud
    @AndersEvenrud 10 ปีที่แล้ว +19

    Being a web-developer I highly enjoy this series. Tom really knows what he is talking about, and I just love the enthusiasm.

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

      it disturbs me, that you're a web-developer and enjoy this :) you should already know all these issues

    • @AndersEvenrud
      @AndersEvenrud 10 ปีที่แล้ว +7

      suit1337 Yes, I know about these issues. I think most of the developers out there enjoy these videos regardless of what they know about the subject. And there is always a chance of learning something new.

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

      suit1337 You do know that web developers can be new to web development right? We don't live in the age where the only way to learn something is through a proper school. You could easily start your web development very small time on your own and be unaware of the basic security flaws...

    • @suit1337
      @suit1337 10 ปีที่แล้ว

      I'm aware of that - and that is a shocking development in this business. Take another work field for example: someone could not easily start a business as an electrician without proper education - but you can start as a web developer.
      there are lots of fools around here with no clue, even in the basic properties of the business but they make shitloads of money with their crap
      that really fills me, doing proper work, with anger
      ---
      just an example from my country (austria)
      - the website of our ex financial minister was priced at 220.000 Euro
      the website of the agricultural ministry cost about 5,5 Million Euros
      and those websites are not even closely done properly and get defaced over and over again - instead of blaming the stupid overpriced web developers with no proper education they blame the "bad hackers"
      a few weeks ago our interior ministry presented a new 100 % hackerproof "student licence" - it was hacked only 3 days after via a very simple SQL injection
      i hope you understand, that it disturbs me, that every moron with no education can start a new 1 man web agency and start coding with no education in the field at all.

    • @nryle
      @nryle 10 ปีที่แล้ว

      suit1337 I understand this, it's true of anyone who takes pride in their work. It's not really that shocking though. This is true of any business until government steps in to regulate it.
      I think the true problem lies in the fact that Web Development is an all encompassing term even though it has several aspects: Design, Functionality, Reliability, Marketability, and, of course, Security. From what I've seen most people think these are the same, though many have started to separate design.

  • @Phrikeares
    @Phrikeares 8 ปีที่แล้ว +47

    Can't i just load the other form in an invisible Iframe and then parse and search through the html retrieved? Use the token info and create my own form.

  • @isaac10231
    @isaac10231 10 ปีที่แล้ว

    It's good having an episode of computerphile, mainly because the intricate and important details in computer are _so complicated_ even though I (thought) that I knew about computers. This kinda gives me a foundation.
    Also you should probably talk about logic gates, whether it's minecraft or whatnot, they explain how you could have to light switches for one light

  • @kiddor3
    @kiddor3 10 ปีที่แล้ว +11

    Ironically I saw "nonce" today in a code and I thought someone didn't follow code standard for nOnce or n_once. Now I know what they meant.

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

    Got an exam on this tomorrow, this was so helpful for me, thanks! The way you explain things makes them easily accessible

  • @Reddemon815
    @Reddemon815 10 ปีที่แล้ว

    These are awesome. This guy makes Computerphile the channel I look forward to. More of him.

  • @thoughtsofadyingatheist1003
    @thoughtsofadyingatheist1003 9 หลายเดือนก่อน +2

    You'd be surprised how many web devs don't know about this in 2023

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

    Great and informative video as always. Loving the amount of Tom on this channel.

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

    Just wanting to let you guys not know that you are doing a great job I love watching your videos and always get excited when I see that you posted another one.
    I'm 16 years old and enjoy programming but thoose videos add another point of view to it and really get you thinking
    Greetings from Germany

  • @tedspens
    @tedspens 8 ปีที่แล้ว +8

    I always wondered how Wordpress' nonce hash works. Thanks for the enlightenment!

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

    I know little about IT or programming, but your videos are always very informative and easy to understand, so thanks!

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

    This is great! :D I love the way Tom explains advanced terms in really simple ideas

  • @Imrooniel
    @Imrooniel 10 ปีที่แล้ว

    This mini series on security is just wonderfull. Love the content, love the voice, it's just great.

  • @hotrodmind
    @hotrodmind 10 ปีที่แล้ว

    these videos jus seem to come right after i've implemented something for a project in my courses ... Thank you for informing me of these things, heavens knows I'll need them in the field

  • @annayosh
    @annayosh 8 ปีที่แล้ว

    The tale in the beginning about POST and GET requests is a bit of an ideal case too. Many sites actually work just as well if instead of a GET request you make a POST request with the same content, or vice versa.

  • @Daetok
    @Daetok 9 ปีที่แล้ว

    This channel is absolutely amazing!

  • @marko_2317
    @marko_2317 5 ปีที่แล้ว

    Very informative and explained in a simple and understandable manner. That's why Tom is my favorite, though I enjoy watching the others, too!

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

    Holy crap! While I have enjoyed these videos since the start of computerphile, this is the first time I directly learned, or more rightly, realized something. I do have webpages that are badly coded like this. Time to go off and fix!

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

    Tom, You are the best. Keep making those excellent videos.

  • @BorealSelfReliance
    @BorealSelfReliance 10 ปีที่แล้ว

    Great explanation, I did know this sort of attack existed but had never given much thought about how to mitigate it.

  • @ramikafa
    @ramikafa 10 ปีที่แล้ว +13

    This guy is an excellent presenter. Please, more of him.

  • @ambitecturous4741
    @ambitecturous4741 8 ปีที่แล้ว

    Excellent description of XSRF. Thank you. I understand the concept and defenses now.

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

    Very helpful. I liked both the content and the way you described the CSRF. Thanks!!

  • @DevonBernard
    @DevonBernard 10 ปีที่แล้ว

    Another great video guys, looking forward to more cool explanations. Keep up the awesome work!

  • @Sc2mapper117
    @Sc2mapper117 9 ปีที่แล้ว +2

    This was really interesting. I was aware of cross-site-scripting and sql Injection but I had never heard of this. Thanks :)

  • @scienceblossom6197
    @scienceblossom6197 6 ปีที่แล้ว

    Best quality of explaining anything ever possible!! Thanks A TONNN!

  • @DannyBurkeBanjo
    @DannyBurkeBanjo 10 ปีที่แล้ว

    Love your videos! I will doing web computing in September at uni and these videos are excellent! Thanks

  • @rahil471
    @rahil471 10 ปีที่แล้ว

    Awesome video,great help.
    I'm always waiting for your new videos .

  • @davidgeismar6531
    @davidgeismar6531 6 ปีที่แล้ว

    great vid ! So on a website you would store in a database the csrf token everytime a user logs in ?

  • @magnetar02p.23
    @magnetar02p.23 7 ปีที่แล้ว +8

    I know this is not relevant to this video, but can you do a video on elliptic curve RSA cryptography?

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

    I get the concept of the token, but how does the server know if a token is valid once it gets the request? Since the web is stateless, it creates the form with a random token, then sends it on its way. So how does the server know if a token it gets back is valid? Store valid tokens in memory or a database?

  • @Mar_Ten
    @Mar_Ten 6 ปีที่แล้ว

    Actually learned this now by the video. Quite interesting and will eb sure to include this in serious projects in the future.

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

    This guy is amazing! More videos by him please!

  • @yinge101
    @yinge101 10 ปีที่แล้ว

    Couldn't you get around the one-time key thing by creating a hidden/tiny/offscreen (i)frame for the ‘transfer money’ form on the bank website, and then use JavaScript to automatically submit the form?

  • @evildude109
    @evildude109 10 ปีที่แล้ว

    Is this something I can see in context, like in the html of this web page? Where would it be in the code? I don't quite understand it yet.

  • @Smittel
    @Smittel 5 ปีที่แล้ว

    What im wondering is, how would that work? I tried to make myself a custom start page for my browser that would pull the most recent football league tables amd game results for PL, LaLiga and Bundesliga and display it. It wouldnt let me do that, even though i didnt even send anything, i just requested some table in an html.

  • @hecanylmz
    @hecanylmz 4 วันที่ผ่านมา

    I've just watched the video, it was really helpful on my course! Thanks! 🙂

  • @TheAaaargh
    @TheAaaargh 10 ปีที่แล้ว

    Would it be possible for a virus to monitor the network-traffic for specific One-time numbers, say your banks number, and then when it finds one quickly send a premade form, transfering money from your account to the creators as soon as you visit your banks site?

  • @Hobo_X
    @Hobo_X 10 ปีที่แล้ว

    I love this guy please keep making more videos with him

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

    but what if I first send the request for the original page, let say the route /send-money is the route with that form. so, I send the request to that form and scrape the csrf token from it and now send it with my malicious form.
    Would that work?

  • @MaxGuides
    @MaxGuides 10 ปีที่แล้ว +2

    you request the token with your script
    and later in the script you use that token
    easy if the form is standardized-like deleting enemy facebook pages

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

    It's also a good idea to add the action to the seed which generates the nonce, so the nonce to post a comment is different from the one which allows you to delete your account. If you combine that with the username and set a short timeout the users needs to have been on the form which does the action, somehow you need to be able to steal that nonce and get them to go to your infected page. It's basically no longer a security issue in that case. When someone loads a form they usually intend to fill it out and you could even track when they leave the form to immediately invalidate the nonce.

  • @nowhereman3814
    @nowhereman3814 8 ปีที่แล้ว +10

    So...what the hell does nonce mean in Britain?

  • @kuro68000
    @kuro68000 8 ปีที่แล้ว +6

    Why does the camera randomly zoom in some times? it's really distracting.

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

    Here's one consideration on how important it is to validate user input on the server side. Take any disabled html element. Open up firebug console and run some javascript, eg. using jQuery syntax: $('input').removeAttr('disabled'); $('input').removeAttr('readonly');. Then happily make any changes to the input elements and submit the changes.

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

    Nice video ! I already heard about it but I didn't understood everything, so you've made the web a safer place !

  • @NorthcodeNo-no
    @NorthcodeNo-no 10 ปีที่แล้ว

    Well, I use SESSION vars to valdidate, is that fine or should I do this aswell?

  • @eldizo_
    @eldizo_ 10 ปีที่แล้ว

    Will Tom be a regular? His bits are great.

  • @ragir
    @ragir 10 ปีที่แล้ว +7

    Great, now i've got to rewrite the project i'm working on. I didn't know about this and it's so obvious. Good video!

    • @Airblader
      @Airblader 10 ปีที่แล้ว +8

      If you have to rewrite a project to protect against CSRF attacks you are doing other things wrong as well

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

      Rewrite? That sounds a bit like overkill. Just add a nonce token and you're as good as you'll get.

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

    This is indeed a big security hole. I did not know what CSRF did before so I couldn't apply a patch to my site. I can now though. Thanks Tom/Numberphile. Nicely explained :)

  • @imrankhan-uo4jy
    @imrankhan-uo4jy 9 หลายเดือนก่อน

    Excellent explanation in simplest terms!

  • @CrystalblueMage
    @CrystalblueMage 10 ปีที่แล้ว

    Being able to create your own version of a form a send that is a problem in general, as you could also strip out any checks in the original form you don't like.

  • @nanopi
    @nanopi 10 ปีที่แล้ว

    could clickjacking be the 4th in this series? at least that one is easily blocked by X-Frame-Options and some other stuff

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

    Thanks for the video. This is really useful.

  • @kaitlyn__L
    @kaitlyn__L 10 ปีที่แล้ว

    would modern browsers' tab sandboxing prevent that sort of thing?

  • @RedHotBagel
    @RedHotBagel 10 ปีที่แล้ว

    Brilliant Video!
    Awesome and clear explanation!

  • @sacredgeometry
    @sacredgeometry 10 ปีที่แล้ว

    I love these videos, thank you.

  • @LucianoHelenodaRosa
    @LucianoHelenodaRosa 10 ปีที่แล้ว

    I simply love all the Tom's videos, very well explained.
    Keep going with the good content, Mr. Red T-shirt haha - I don't know if it is intentional or not, so I don't want to be a jerk. :p.

  • @MrAskolein
    @MrAskolein 10 ปีที่แล้ว

    Awesome Video, Systems security is to my mind the best subject to do videos on, keep doing that, this is very interesting, very useful ! Keep UP that good work

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

    Oh wow. It's funny seeing people writing about how they implemented a 'nonse'. If only they they knew. This was a great video! Tom is always so enthusiastic, it's great! One request would be making the felt tipped pen sound quieter/non existent. It makes my toes curl!

    • @FernieCanto
      @FernieCanto 10 ปีที่แล้ว

      Word! That is even worse in Numberphile.

  • @lc3
    @lc3 8 ปีที่แล้ว

    Thank you.
    Is there a way to know if a site is using tokens?

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

    Ya know, if accepting request from other website would work, then the form would likely be accessible by javascript running from the other website as well.
    Which means, my javascript could request the form, look for that random string of characters (fairly easily too) and add it to its spoofed request, meaning we would be back to square one.

  • @edinatl2008
    @edinatl2008 9 ปีที่แล้ว +17

    Thanks for helping me learn the valuable lesson of what a 'nonce' is in UK.

  • @hidalginator21
    @hidalginator21 10 ปีที่แล้ว

    Great Video. As a novice web developer these videos help immensely. Keep them coming. A video on how to design a site which can be logged into securely would be very helpful.

  • @Rudde47
    @Rudde47 10 ปีที่แล้ว

    Can't you just load the bank page in the backround of your site with JS and get the token from there and then run a post request from your site?
    Also, how does one store this token?

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

    I've been looking for a video that I can send to my non-techie friends to give them slight idea about XSRF. This video is what I've seen so far that's lay-man friendly.

  • @datdereh2367
    @datdereh2367 10 ปีที่แล้ว

    what if you loaded an invisible in the users browser when they loaded "myAwesomeBlog", extracted the token and used it in a csrf attack?

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

    still relevant even nowadays how beautiful

  • @chriskormaris
    @chriskormaris 6 ปีที่แล้ว

    thanks for this magnificent explanation!

  • @ChrizzyWhite
    @ChrizzyWhite 10 ปีที่แล้ว

    been waiting for this video

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

    Thank you Dawson from Dawson's Creek!

  •  10 ปีที่แล้ว

    What happens if we make a call to the page that generates the form and take the token from there?

  • @FFVison
    @FFVison 10 ปีที่แล้ว

    I have heard about this before, but there's a simple way around it. The problem with it is that the same malicious form on the unrelated blog can still submit a page request on the target site and grab the token before submitting to the page that actually does the damage. All it takes is a little bit of PHP knowledge, some knowledge of HTTP request headers, and a little ingenuity. Still, it's good to know how and why to do this.

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

    The easiest way to get around most of these: Use a solid framework which helps prevent all these attack types. Take Ruby on Rails for example. While not perfect, the latest version is pretty good at avoiding SQL injection, XSS, and CSRF, along with other built in things, like secure cookies, and proper storage of passwords... with a framework doing most of the basic stuff, it's up to the developer not to do anything stupid.

  • @MichielHaisma
    @MichielHaisma 10 ปีที่แล้ว

    It just gets better!

  • @bisschops99
    @bisschops99 10 ปีที่แล้ว

    Love this guy! Great video(s)!

  • @vortyx090
    @vortyx090 8 ปีที่แล้ว

    Ty for those lessons, they are so cool!!!

  • @AmiyaPatanaik
    @AmiyaPatanaik 10 ปีที่แล้ว

    Awesome...never even thought of such security issue...I think chrome's sandboxing of the tabs won't help here coz I have seen the sessions and cookies are shared across tabs....Keep it coming - love the videos

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

    This guy is so good. More of him! :D

  • @Kerbobotat
    @Kerbobotat 10 ปีที่แล้ว

    Really interesting! But how do you know if your bank, etc. is using the token system? Also, can we get a computerphile video explaining bitcoin?

  • @TessaBain
    @TessaBain 10 ปีที่แล้ว

    Wonder if the games I play use it in their deletion form?
    _goes off to make a post in the staff forum to bring it to their attention just in case_

  • @Marphale
    @Marphale 6 ปีที่แล้ว

    I don't understand this and must be missing something. What's to stop the malicious site from sending a GET request for the form and then (via javascript) sending the POST request with the token afterwards? If the answer is that the GET request is secured by the encrypted session ID for the user, then why does that encrypted session ID not secure the POST request also?

  • @samramdebest
    @samramdebest 10 ปีที่แล้ว +18

    but what if the malicious webpage itself loads the bank site in the background, it can get the token that way.

    • @mart3323
      @mart3323 10 ปีที่แล้ว +5

      cross-site scripting is blocked in browsers
      as a simple example, say i have a site with a bunch of livestream embeds, and i set up a script that when i press F2, it scrolls to my favourite one
      As soon as i click inside any of the streams, say the play button.., F2 won't work
      and it'll continue to not work until i click outside again, giving focus back to my own page
      The only way they can load the bank would be to actually load the bank visibly to you, because you're the only one that can interact with it..
      the scripts can't..., not theirs anyway

    • @samramdebest
      @samramdebest 10 ปีที่แล้ว +5

      I think that what you are saying is incorrect, i have done some coding with AJAX(Asynchronous JavaScript and XML) and it didn't need to be visible to be able to load.
      and almost every page on the internet gets data from other sites invisible(i once had a chrome extension that showed which site you visited and where they took data from, an average site connected to more than 20 different websites(like for tracking: google analytic)

    • @OKMX5
      @OKMX5 10 ปีที่แล้ว +6

      I think that the token will be different because it is another loading/creation of the form.

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

      what do you mean other loading/creation of the form, it is not, the site downloads the form and the token, and then sends it back to the bank

    • @samramdebest
      @samramdebest 10 ปีที่แล้ว

      oh do you mean, that even for the request of the forum not only the submission needs to be accompany by the token? That would make more sense and would solve that problem, thanks

  • @barefeg
    @barefeg 10 ปีที่แล้ว

    So even if the malicious site knows how to generate the token (e.g. if it is from wordpress, etc.) , because it doesn't know the username (assuming the token is generated using that), then the the attack won't work, right?

    • @xdjoshuaaz
      @xdjoshuaaz 10 ปีที่แล้ว

      Tokens should be generated randomly (not based on username) and then stored in some sort of session storage (for that user). Creating token value based on username reduces the security provided by this method since the user could use the same username on all websites etc.

  • @aerouk
    @aerouk 10 ปีที่แล้ว

    This guy's videos are brilliant! Web security and hacking is so interesting. :)