Cross-Site Scripting Explained with Examples and How to Prevent XSS with Content Security Policy

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ค. 2024
  • In this video, I discuss XSS Cross-Site scripting attacks and how to prevent them.
    0:00 Intro
    2:40 XSS Stored Attacks
    The injected script is stored permanently on the target servers. The victim then retrieves this malicious script from the server when the browser sends a request for data.
    4:50 Reflected XSS Attacks
    When a user is tricked into clicking a malicious link, submitting a specially crafted form, or browsing to a malicious site, the injected code travels to the vulnerable website. The Web server reflects the injected script back to the user's browser, such as in an error message, search result, or any other response that includes data sent to the server as part of the request. The browser executes the code because it assumes the response is from a "trusted" server which the user has already interacted with.
    8:00 Source Code Explained
    9:50 Prevent XSS Attacks with CSP
    16:00 Prevent all scripts with CSP
    Source Code
    github.com/hnasr/javascript_p...
    🏭 Backend Engineering Videos
    • Backend Engineering (B...
    💾 Database Engineering Videos
    • Database Engineering
    🛰 Network Engineering Videos
    • Network Engineering
    🏰 Load Balancing and Proxies Videos
    • Proxies
    🐘 Postgres Videos
    • PostgresSQL
    🚢Docker
    • Docker
    🧮 Programming Pattern Videos
    • Programming Patterns
    🛡 Web Security Videos
    • Web Security
    🦠 HTTP Videos
    • HTTP
    🐍 Python Videos
    • Python by Example
    🔆 Javascript Videos
    • Javascript by Example
    👾Discord Server / discord
    Become a Member
    / @hnasr
    Support me on PayPal
    bit.ly/33ENps4
    Become a Patreon
    / hnasr
    Stay Awesome,
    Hussein
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @galfrasian
    @galfrasian 4 ปีที่แล้ว +20

    Love your spirit man. You keep regularly updating your videos. Great job.

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

      Saumya yadav ❤️

  • @asderex
    @asderex 4 ปีที่แล้ว +12

    Great video Hussein. I’ve heard of XSS but never had them explained so clearly. Would love to see more security related videos if the inspiration hits you! This has become my favourite back end channel - thanks for your effort making these.

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

      Thanks for the encouragement ❤️ well sure keep them coming whenever Inspiration hits.
      I put all my security related videos on this playlist. Check it out
      th-cam.com/play/PLQnljOFTspQU3YDMRSMvzflh_qXoz9zfv.html

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

      @@hnasr Wao I just saw the playlist this is overwhelming!

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

    Great video Hussein!

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

    Oooooo Mama......... :D Your Accent/tone/speech/words/humor is just perfect. Thank you that i found you.

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

      Oh thank you!

    • @user-mb9vk8vq8w
      @user-mb9vk8vq8w 7 หลายเดือนก่อน

      0:34 😂😅

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

    Thanks man! You've been shooting out amazing content lately like multiple times a week! Keep up the good work

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

      Constantine thanks whenever I feel inspired I put some content out before the inspiration dies. 😊 I love making videos

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

      @@hnasr I appreciate the answer! I have to change my mindset about making content and use your philosophy. I make a lot of content but I just keep trying to perfect it so I never release anything publicly.

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

      You should release your work! You have no idea who your work will help 🙏

  • @jakealert1722
    @jakealert1722 4 ปีที่แล้ว +6

    Another Hussein Nasser video woohoooo!
    Would be really awesome if you could make a video purely about CSP. How to set it up and what the best practices are :)

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

    Wow!!
    Very informative. I lean new things again in less time.... It will help me a lot to prevent outside to come in to my server scripts.

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

    Mahn! Incredibly fun to watch! Love your content bro

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

    this is so easily digestable! thank you

  • @potaraju92
    @potaraju92 3 หลายเดือนก่อน

    Love your style of teaching, man, you are awesome.

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

    Thank you Naseer ! This is very helpful

  • @Lena-of7wd
    @Lena-of7wd 2 ปีที่แล้ว +2

    Great explanation, thanks!

  • @paschalokafor9043
    @paschalokafor9043 6 หลายเดือนก่อน

    I just subscribed. You are awesome bro. Thank you loads.

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

    Thank you very much and keep doing your job :)

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

    FYI - its a "reflected" since your code is "reflecting" the search item on the return results page @2:24, thus executing the script.

  • @tomytoon123
    @tomytoon123 7 หลายเดือนก่อน

    I enjoy how this guy explain :)

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

    We appreciate your efforts

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

    Awesome made it all clearer 🙏

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

    You are the best explainer

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

    This is cool man.I was on facebook console doing all things and kept getting this CSP thing, glad you cleared it up.Need to see how to implement it in nginx when delivering static website

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

      Siddiqui Sarik should be as simple as adding that header assuming your nginx is layer 7 reverse proxying

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

    Hello Hussein after going through video , I realised that it was you . I have watched most of your content on the design

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

    thanks for the nice explaining it was very enjoyable.

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

    This was incredibly helpful thank you! How does this work with the HTML tag "meta http-equiv="Content-Security-Policy" content="default-src 'self'"? Does this tag mean I don't have to include all the lines of JS shown in your video?

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

      I hope he answers looks like you may be missing code

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

    It's very informative!

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

    Great Explanation

  • @rahul.r
    @rahul.r 4 ปีที่แล้ว

    Glad to see you actively adding more videos. Trying to watch as many as possible. Can we expect a video on tools like Prometheus and Grafana by any chance?

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

      Rahul it is on my list of things to research.

    • @rahul.r
      @rahul.r 4 ปีที่แล้ว

      Hussein Nasser great to hear that!

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

    Please make more videos on web security and headers! ❤️

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

    This is $$ Gold $$. Thank you so much. You earned a subscriber!

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

      Awesome, thank you! :D

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

    Very helpful ser!! 🙏🌹❤

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

    I love your videos always you are the best on youtube
    Thank you so much for your effort and time

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

    Thank you for this great video, as always. Learning a lot from them. (I am trying to build a resource server for my spring boot- anugular application. Please do you know any resource that will help or any free tool I can use. Thanks for your feedback.)

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

    Awesome Demo thank's

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

    It was helpful, thank you

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

      Glad to hear that!

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

    ও মামা।
    Amazing explanation!

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

    Thank you for a beautiful explanation sir. Actually interested in learning js btw found u on Udemy.

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

      NO Oxygen thank you for your comments I hope you enjoy the content and welcome to the channel

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

    Such powerful stuff...

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

    Of course you could have mentioned the real problem and solution in the js code, distinguishing text from HTML encoded text. (Easier with typescript 😜) But good demo of the csp header.

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

    if it is a dynamic website, is it okay to put the main homepage link in?

  • @dmitry.gashko
    @dmitry.gashko 3 ปีที่แล้ว +1

    4:55 In general stored xss is more dangerous than reflected one. First - there are no user action required to run a stored xss (when a reflected xss needs a link) and second - any stored xss can also be used as a reflected xss. I mean, I can make some xss on a page no one goes to, so stored xss is not so dangerous there, but I still can make a link to that page, like with reflected xss.
    But, what I was thinking about, is that stored xss is more dangerous on public pages but on private pages reflected xss is more dangerous .
    This is because stored xss on private pages in most cases is like self xss - you make that xss, and you can "hack" yourself, but with reflected xss on private pages you can send a link to, for example, profile settings, and it would be quite regular reflected xss.
    p.s. of course there's always an ability that admins can go to private pages, so, any stored/reflected xss is bad and no matter where it appeared.

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

      I need a coder like you trying to login into a scam site. I got my login but I want full access!

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

    شكرا جدا عالشرح الواضح

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

      ❤️❤️ العفو

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

    is XSS relevant to only public domain sites(twitter,facebook) or even licensed webapps(jira, enterprise git..etc) can undergo XSS?

    • @dmitry.gashko
      @dmitry.gashko 3 ปีที่แล้ว +1

      XSS is relevant to WEB in general. So, no matter jira is, github, gitlab, youtube or amazon.

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

    Hi Hussain.Your content is awesome. Csp attributes get fails even though it has been configured correct url.can u help me out?

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

    "Oooo Mama" 😂
    - Hussain 2020

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

    Anybody know how to check if a given website has xss header enabled using pyhton.

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

    hi hussein
    I need you help/info related to one issue
    We have in java code like below
    String hname = request.getRemoteName(); // this line is showing issue in Fortify scan
    can you help me how to validate the hname?
    I used with ESAPI input validator but it could not remediate it. Please help

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

    awesome

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

    What websites let you just store things on them like that?

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

    Does xss protection header prevents DOM xss

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

    At 09:13 , you said we shoudnt write script inside inline script tag. But it wasn't clear why. Can u elaborate on it please.

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

      Natesh M Bhat Because most cross side scripting attacks uses inline script injunction too. So the best approach is to block inline script and use CSP to only load it from a url. As i explained in the end

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

    I don't know if u use instagram but there was this one account who posted an insta story, It said "Some text" and below was the profile picture of the person who was viewing that story. So if i opened the story then it would be my pic. But Instagram doesnt provide any API like TH-cam does even if it did , There isn't any place to embed it. I wonder how he did it cuz it was pretty cool

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

      what account is that?

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

      I have also seen that one of my friend gave that link to view that status and there is a image placeholder where profile pic of the status viewer will be shown

  • @FordExplorer-rm6ew
    @FordExplorer-rm6ew 4 ปีที่แล้ว

    Been just kind of defeated.
    Haven't even been on a computer in a long time.
    I do like your vids though.
    Still picking up theories and concepts here and there

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

      sry828 89 it takes time I feel the same sometimes too because of the amount of information out there. I find it helpful to know that this is a marathon not sprint and I just take things easy and only jump on things that interests me. That doesn’t always happen though like today I just spent the whole day relaxing, playing video games and grilling. No engineering 😅

    • @FordExplorer-rm6ew
      @FordExplorer-rm6ew 4 ปีที่แล้ว +1

      @@hnasr thankgs for the encouragement.
      Noted and definitely appreciated
      Thx fren :) 👍

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

    great

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

    Can u make a vid on modsecurity with Nginx

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

    How to implement in struts

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

    ❤️

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

    the edvotise was so greate "click here to Boost your CPU"🤣🤣🤣

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

    So you mean that if we do use CSP XSS can't be injected, right ?

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

      they can be injected, they just won’t be triggered if inline script is disabled

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

      @@hnasr I am not getting it. So the final answer is: It can't be hcaked, right ?

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

    When your mom found out that you did something wrong and she stares at you like she about to end yo career: 3:26

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

    joss

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

    XSS babes!

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

    This + html ping to post form :)

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

    Thank you for saying SHE and including us ✨ 🙌🏽 ✨ women hack & code too (:

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

      Oh God STFU up with that dumb brainwashed crap.

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

      Learn to be a damn adult already.

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

    alert("Mad")

  • @DevinJohw
    @DevinJohw 2 หลายเดือนก่อน

    alert("Hello");

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

    alert(test attack);

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

      Forgot the quotes for the string

  • @Adarsh-Shrivastava
    @Adarsh-Shrivastava 6 หลายเดือนก่อน

    alert("XSS")

    • @Adarsh-Shrivastava
      @Adarsh-Shrivastava 6 หลายเดือนก่อน

      This proves youtube comments os safe from XSS