I am trying to restrict angular app from being loaded in iframe
but not able to do that.
I have angular
app running independently from API
. API is implemented using .net core 2.1
and UI client using angular 7
.
I tried below different options in api middleware
but none is working in my case:
#1
app.Use(async (context, next) => { context.Response.Headers.Add("Content-Security-Policy", "frame-ancestors 'none'; " + "script-src 'self'; " + "style-src 'self'; " + "img-src 'self'"); await next(); });
#2
app.Use(async (context, next) => { context.Response.Headers.Add("X-Frame-Options", "DENY"); await next(); });
I am getting above added values in response header
but still able to load application in iframe
in other application.
Is there anything I am missing here at angular/API
side?
Added more information
We used IIS to host angular app. Also tried below setting in web.config in angular app:
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="DENY" />
</customHeaders>
</httpProtocol>
Why not serving the headers in the server side of your UI ? What are you using to serve your angular app ? is it nginx ? apache httpd ? Both of them provide the ability to return headers on every requests
Edit : As you are using IIS indeed it seems to be
But I don't know more about it
Sources: https://www.keycdn.com/blog/x-frame-options