Reputation: 111
I want to stop my angular application to be open in an IFRAME. I read some article on google and came to know that in order to achieve this we have to set X-Frame-Options. But I did not find the way to give this header.
Can anyone help me that how can I achieve this in angular-4?
Upvotes: 1
Views: 15952
Reputation: 5226
There is nothing to do with angular app. It is a setting in IIS. To set X-Frame-Options
in IIS server, do the following,
X-Frame-Options
.X-Frame-Options
in the
Name field and type SAMEORIGIN
in the Value field. <customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
More detail about clickjacking attack is here
Hope this solves your problem.
Upvotes: 5
Reputation: 81
The correct way of doing this is by using the X-Frame-Options with the same origin. But for the workaround, you can use this document https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html this tells how you can add the script to your application For using this in angular you can call a function from the constructor of the app.component.ts file
checkAntiClickJacking() {
if (self !== top) {
// Redirect to your url
}
}
Upvotes: 0
Reputation: 41
Here is the solution for Angular:-
http://taimooradilbadshah.blogspot.com/2014/06/the-clickjacking-attack-and-x-frame.html
I made a web.config file on server(IIS) where I put my build(dist) code.
It also works for Angular routing (ignore using hash tag(#)).
web.config
<?xml version="1.0"?>
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
<rewrite>
<rules>
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
<action type="Rewrite" url="/angularProject/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You can check it here your website after putting above code :-
https://www.lookout.net/test/clickjack.html
Thanks
Upvotes: 2