Prevent ClickJacking

111 Views Asked by At

Can you please let me know how to prevent clickjacking attack? Thanks in advance. I am using pure javascript for client side and VBscript for serverside. expecting which x-frame-option should I add to website and also how many steps should be taken to avoid clickjacking attack.

1

There are 1 best solutions below

2
Halvor Sakshaug On

You can prevent clickjacking by setting the server response header "X-Frame-Options" with either the value DENY (not allowed to frame) or SAMEORIGIN (only allowed to be framed on the same origin). There is also an ALLOW-FROM option, but it is basically not supported anymore.

But X-Frame-Options is now superseded by frame-ancestors directive of Content Security Policy, which you should use instead as it takes presedence over X-Frame-Options and is more flexible. You can use the options 'none' (no one is allowed to frame), 'self' (only allowed to be framed on the same origin) as well as adding any host name that is allowed to frame.

You could set the header as in this example

Response.AddHeader "Content-Security-Policy", "frame-ancestors 'self' <hostname1> <hostname2>;"