Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Security difference between X-Frame-Options and Content-Security-Policy headers?

These HTTP headers seem to do the same thing, albeit with the latter having a bit more flexibility.

Is there any additional security that the Content-Security-Policy offers?

like image 292
Cisplatin Avatar asked May 22 '26 19:05

Cisplatin


1 Answers

X-FRAME-OPTIONS allow you to protect your site from being framed in other sites.

For example X-FRAME-OPTIONS: SAMEORIGIN allows your site to be embedded in an iframe on the same domain only. It's needed to prevent clickjacking attacks.

But Content-Security-Policy has completely different purpose. Specification of CSP says that:

Content Security Policy is a declarative policy that lets the authors (or server administrators) of a web application inform the client about the sources from which the application expects to load resources.

So its main purpose is to protect your site from XSS attacks on your users, by not allowing browsers to loader resources (scripts, etc.) from unknown domains.

like image 104
Vitaly Kulikov Avatar answered May 25 '26 09:05

Vitaly Kulikov