Content Security Policy explained | how to protect against Cross Site Scripting (XSS)

  Рет қаралды 43,755

Jan Goebel

Jan Goebel

Күн бұрын

🔥More exclusive content: productioncode...
Twitter: / _jgoebel
Blog: productioncode...
Website: jangoebel.com
In this video, we cover what Content Security Policy (CSP) is, why you need and how it protects against Cross Site Scripting. We look at Content Security Policy directives, what they do and how you can leverage them for your application. The main goal of Content Security Policy is to protect against Cross Site Scripting attacks. It does so by limiting the origins and urls from which certain assets (e.g. fonts, images, scripts) can be loaded. Content Security Policy can help to mitigate against stored or reflected XSS attack vectors.

Пікірлер: 100
@jgoebel
@jgoebel 3 жыл бұрын
What do you think about this video? Let me know in the comments below.
@rhitmanandhar525
@rhitmanandhar525 3 жыл бұрын
Loved it. Thank you.
@lksjfadlk
@lksjfadlk 2 жыл бұрын
Thanks man.
@isagive
@isagive 2 ай бұрын
i needed a good rule for a modern website. not only why, but some kind of common what.
@wajeehsaleh6121
@wajeehsaleh6121 Ай бұрын
Thanks, man!
@truepakistani9604
@truepakistani9604 2 жыл бұрын
5:48 default-src default of switch statement wow. Explained in just a single statement 👍👍👍
@jgoebel
@jgoebel 2 жыл бұрын
you're most welcome
@Barrosy
@Barrosy Жыл бұрын
Oh my god I was looking all over the web what the meaning behind meta tags and CSP was until I found this video. It's crystal clear to me now. Thank you so much sir.
@ash_tray_6
@ash_tray_6 Жыл бұрын
Thank you! You’re a fantastic teacher.
@jgoebel
@jgoebel Жыл бұрын
I'm glad you liked it
@TrumpsOfDesign
@TrumpsOfDesign Жыл бұрын
Thanks for explanation. I've searched resources, that can explain me in simple way what is CSP and what it for. After this video I have superficial understanding that is enough for my purposes
@noelcovarrubias7490
@noelcovarrubias7490 3 жыл бұрын
Thank you. I first read the article but I was a bit confused because I never heard of XSS before so I came here an after the first 3 mins it was crystal clear to me. :D
@jgoebel
@jgoebel 3 жыл бұрын
thx Noel, I'm glad I could help!
@stomperhk9107
@stomperhk9107 2 жыл бұрын
Dude.... Thank's a ton for that objective video.
@jgoebel
@jgoebel 2 жыл бұрын
Glad it was helpful!
@hekarboi3656
@hekarboi3656 2 жыл бұрын
straight to the point, thanks
@jgoebel
@jgoebel 2 жыл бұрын
you're welcome Hekar
@ecommercetechbuild1354
@ecommercetechbuild1354 2 ай бұрын
Wonderful explanation
@jgoebel
@jgoebel Ай бұрын
Glad it was helpful!
@grahamschuckman3483
@grahamschuckman3483 2 жыл бұрын
Think it would’ve been helpful if you did actually demo a few examples with setting the various directives. Hard to make sense of how each works by just reading the MDN pages that you showed.
@superdop1976
@superdop1976 11 ай бұрын
Thank you for the great explanation.
@jgoebel
@jgoebel 11 ай бұрын
You are welcome!
@emily_tm
@emily_tm 8 ай бұрын
great explanation, many thanks!
@jgoebel
@jgoebel 8 ай бұрын
Glad you enjoyed it!
@israelkayaba6002
@israelkayaba6002 Ай бұрын
Thanks bro !
@dublinnnn
@dublinnnn 8 ай бұрын
Nicely Explained >>
@jgoebel
@jgoebel 8 ай бұрын
Glad it was helpful!
@MHamidAshraf
@MHamidAshraf 7 ай бұрын
very nicely explained. thanks. i liked it.
@jgoebel
@jgoebel 7 ай бұрын
Thanks for liking
@petrtcoi9398
@petrtcoi9398 Жыл бұрын
Great explanation!
@jgoebel
@jgoebel Жыл бұрын
Thanks!
@Rabano94
@Rabano94 Жыл бұрын
thank you for the video! super clear!
@jgoebel
@jgoebel Жыл бұрын
thx
@ahmedelgaidi
@ahmedelgaidi 3 жыл бұрын
The best as always
@jgoebel
@jgoebel 3 жыл бұрын
thx Ahmed 👍
@yasminbrandao3359
@yasminbrandao3359 2 жыл бұрын
Nice explanation! tks for sharing
@jgoebel
@jgoebel 2 жыл бұрын
Glad you liked it!
@justtruth5157
@justtruth5157 Жыл бұрын
Very nice video!!!
@sanketmaske74
@sanketmaske74 3 жыл бұрын
Very well explained.... thanks
@jgoebel
@jgoebel 3 жыл бұрын
thx Sanket 👍
@ازاي-ث7خ
@ازاي-ث7خ Жыл бұрын
Thank you for such great video!
@jgoebel
@jgoebel Жыл бұрын
thx
@ToadyEN
@ToadyEN 2 жыл бұрын
Handy overview, now to building a CSP 😳
@jgoebel
@jgoebel 2 жыл бұрын
nice 👍
@1bigslug
@1bigslug 2 жыл бұрын
Thank you for the video!!
@jgoebel
@jgoebel 2 жыл бұрын
My pleasure!
@najaericsson71
@najaericsson71 5 ай бұрын
Very good!
@jgoebel
@jgoebel 4 ай бұрын
Thanks!
@ukaszkiepas57
@ukaszkiepas57 3 ай бұрын
thank you buddy ! :)
@jgoebel
@jgoebel Ай бұрын
You're most welcome!
@exd0254
@exd0254 2 жыл бұрын
thanks 4 the clear explanation
@jgoebel
@jgoebel 2 жыл бұрын
Glad it was helpful!
@otiagosantoscode
@otiagosantoscode Жыл бұрын
I can't figure out how to implement this in practice!! I'm trying to put a google maps on a statistical html page, but it keeps giving a csp warning or the map doesn't load.
@ricardonacif5426
@ricardonacif5426 9 ай бұрын
Man you look like young Elon Musk lol. Congratz on the content btw!
@ABDULKARIMHOMAIDI
@ABDULKARIMHOMAIDI 6 ай бұрын
Thanks man !!
@jgoebel
@jgoebel 3 ай бұрын
you're welcome
@FlanzetaGaming
@FlanzetaGaming Ай бұрын
What do you think about unsafe-inline in style? i have an app with firebase + react... managed to use nonces but in client side rendering, so styles are broken
@codemadesimple1043
@codemadesimple1043 11 ай бұрын
Well explained 🎉 Are you from Denmark?
@jgoebel
@jgoebel 11 ай бұрын
no, I'm from Germany
@1haker
@1haker Жыл бұрын
Great video
@jgoebel
@jgoebel Жыл бұрын
Glad you enjoyed it
@IHHI22
@IHHI22 2 ай бұрын
on my wordpress website -chrome on my phone says not secure, safari on laptop also says not secure but my SSL certificate is good i checked. also chrome on my laptop doesn't say not secure. I went to inspect >console on website and this error was there but I don't know what it means or where the error is located. The Source Location is blank - "Content Security Policy of your site blocks the use of 'eval' in JavaScript` The Content Security Policy (CSP) prevents the evaluation of arbitrary strings as JavaScript to make it more difficult for an attacker to inject unathorized code on your site. To solve this issue, avoid using eval(), new Function(), setTimeout([string], ...) and setInterval([string], ...) for evaluating strings. If you absolutely must: you can enable string evaluation by adding unsafe-eval as an allowed source in a script-src directive. ⚠ Allowing string evaluation comes at the risk of inline script injection. 1 directive Source location Directive Status script-src blocked
@mindcontroller7136
@mindcontroller7136 2 жыл бұрын
alert("Thank you, very clear explanation")
@jgoebel
@jgoebel Жыл бұрын
haha nice 👍
@nemisis282
@nemisis282 2 ай бұрын
So if im understanding this correctly, this just prevents loading scripts, from sources not allowed by the CSP. But an attacker could still use an inline script tag to run any javascript they could fit everything they need within the comment box (assuming stored and in a comment input)?
@jacksontarlin6841
@jacksontarlin6841 15 күн бұрын
CSPs block all inline scripts by default, though if you have specific inline scripts you want to allow you can identify them with hashes or nonces to whitelist with the CSP.
@none0n
@none0n 2 жыл бұрын
Great video, do you have a video with some in-depth code examples?
@siyamrubaiyeat5852
@siyamrubaiyeat5852 2 жыл бұрын
fixing one missing content security policy header is it impacts the entire website?
@markomilardic
@markomilardic 10 ай бұрын
Great :)
@jgoebel
@jgoebel 10 ай бұрын
Thanks!
@chadbosch1110
@chadbosch1110 3 жыл бұрын
Hey, Is there a secure way in storing/using JWT with CORS to prevent XSS? Hosted Client and Server Separately so can't do httponly. Just wondering if you have any material I could look at.
@jgoebel
@jgoebel 3 жыл бұрын
Hi Chad, if you store a JWT inside of a cookie then your api-gateway needs a strict CORS policy and ideally HttpOnly and Secure cookies to prevent CSRF. However, CORS and cookies do not sufficiently protect you against XSS. Because with XSS some malicious code is running in browser. So in case the JWT is stored in a cookie - even if it is HttpOnly - the attacker can still make authenticated requests. The only "advantage" over using local storage here is that the attacker would need to run the full attack over the browser. This is still bad and the attacker can do pretty much anything he wants to do but at least the attacker does not get access to the actual token. So while the attacker could still do everything via the browser, it would be slightly harder. To protect against XSS, a Content Security Policy is very useful as well as sanitizing user input when it is sent to the server. I think I don't really have a dedicated video that yet.
@ashwinkumar4168
@ashwinkumar4168 2 жыл бұрын
@Barrosy
@Barrosy Жыл бұрын
Not literally like this. You have to replace and with your own directive and value you would like to use. Also make sure to separate these two placeholders with a space. So an example would be
@johnnyforget1494
@johnnyforget1494 3 жыл бұрын
So I've read that putting the CSP in html meta tags isn't super effective and frame ancestors can't be used. What are your thoughts on this?
@jgoebel
@jgoebel 3 жыл бұрын
Hi Johnny, here is a really nice answer for your question: webmasters.stackexchange.com/questions/104857/when-should-i-not-to-use-page-meta-security-headers
@yuvrajagarkar8942
@yuvrajagarkar8942 2 жыл бұрын
but what if some hacker sniffs the traffic and manipulates the request and response headers ? , is that possible if used https ?
@jgoebel
@jgoebel 2 жыл бұрын
Hi Yuvraj, https is TLS over HTTP and all headers that can be encrypted, are encrypted (hostname / IP headers are not encrypted because otherwise routing of the package would be impossible: stackoverflow.com/a/187679/2328833)
@neeerajtk
@neeerajtk Жыл бұрын
Can we set CSP in AWS?
@jgoebel
@jgoebel 11 ай бұрын
CSP is independent of any cloud service
@sauravkarmakar1811
@sauravkarmakar1811 3 жыл бұрын
I used csp script-src to self..and in console it showing many script error...how can i make it accept all my script ?
@jgoebel
@jgoebel 3 жыл бұрын
Hi Saurav, while you could allow any script this would defeat the purpose of having a CSP in the first place. So I figure the only way would be to explicitly add the sources where you want to load scripts from. If you specify self, then this means that you only allow scripts to come from the origin where the webpage was originally loaded from
@sauravkarmakar1811
@sauravkarmakar1811 3 жыл бұрын
@@jgoebel how can i make it accept the scripts that i have written on some script tags inside some pages?
@starindiangamer1322
@starindiangamer1322 7 күн бұрын
alert('Hello World') only hello world
@KareenKreis-q9c
@KareenKreis-q9c 24 күн бұрын
Rebekah Prairie
@Raj0x01
@Raj0x01 2 жыл бұрын
Can anyone explain: "Browsers that don't support CSP still work with servers that implement it" ?
@jgoebel
@jgoebel 2 жыл бұрын
no because the browser enforces the CSP. But pretty much every modern browser supports CSP these days
@Raj0x01
@Raj0x01 2 жыл бұрын
Thanks
@yamansharma9344
@yamansharma9344 3 жыл бұрын
I guess I have seen cross site scripting policies added in web.config files 🤔
@jgoebel
@jgoebel 3 жыл бұрын
could be. Some servers allow you to just pass a config file and then the server will generate the headers for you
@mr.RAND5584
@mr.RAND5584 10 күн бұрын
alert('test')
@nithiyashrees3456
@nithiyashrees3456 24 күн бұрын
@chloesawallace6247
@chloesawallace6247 15 күн бұрын
Hall Anthony Brown Ruth Miller Frank
@panchalnitin
@panchalnitin 2 жыл бұрын
Write down the code mentioned in the video, and then try to edit the comment, KZbin will delete it!
@jgoebel
@jgoebel 2 жыл бұрын
probably because KZbin thinks that you are trying to do a stored cross site scripting (XSS) attack 😁
@freewhitesparrow6205
@freewhitesparrow6205 Жыл бұрын
Is it Elon Mask?
@nithiyashrees3456
@nithiyashrees3456 24 күн бұрын
dd
@nIrUbU01
@nIrUbU01 2 жыл бұрын
doesnt really explain anything, all youre saying is "if you have this header youre protected" - great.
@BearkFearGamer
@BearkFearGamer Жыл бұрын
alert(document.cookie)
@jgoebel
@jgoebel Жыл бұрын
nice try 😁
Content-Security-Policy: An Introduction
30:28
Abhay Bhargav
Рет қаралды 42 М.
Same Origin Policy explained | what is Same Origin policy?
9:12
Running With Bigger And Bigger Lunchlys
00:18
MrBeast
Рет қаралды 84 МЛН
💩Поу и Поулина ☠️МОЧАТ 😖Хмурых Тварей?!
00:34
Ной Анимация
Рет қаралды 1,8 МЛН
Cross-Site Scripting (XSS) Explained
11:27
PwnFunction
Рет қаралды 445 М.
Cracking Websites with Cross Site Scripting - Computerphile
8:34
Computerphile
Рет қаралды 1,5 МЛН
Content Security Policy Explained
5:30
Tejas Kumar
Рет қаралды 5 М.
Missing HTTP Security Headers - Bug Bounty Tips
15:48
LiveOverflow
Рет қаралды 140 М.
OAuth 2.0 - a dead simple explanation
9:16
Jan Goebel
Рет қаралды 20 М.
When to add a CSP (Content Security Policy)
5:21
Kent C. Dodds
Рет қаралды 694
Running With Bigger And Bigger Lunchlys
00:18
MrBeast
Рет қаралды 84 МЛН