Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improved X-Frame-Options to avoid iframe issues with web apps #1578

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ RouteConfig BuildRoute(string acronym, bool urlRewritingEnabled)
};

var finalRoute = route.
WithTransformResponseHeader("X-Frame-Options", "SAMEORIGIN", append: false).
WithTransformForwarded().
WithTransformXForwarded().
WithTransform(transform => {
Expand Down
15 changes: 13 additions & 2 deletions Portal/src/Datahub.Portal/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,21 @@ public void ConfigureServices(IServiceCollection services)
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
options.MinimumSameSitePolicy = SameSiteMode.Strict;
options.HttpOnly = Microsoft.AspNetCore.CookiePolicy.HttpOnlyPolicy.Always;
// Handling SameSite cookie according to https://docs.microsoft.com/en-us/aspnet/core/security/samesite?view=aspnetcore-3.1
options.HandleSameSiteCookieCompatibility();
});

services.AddSession(options =>
{
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
options.Cookie.SameSite = SameSiteMode.Strict;
options.Cookie.Name = ".FSDH.Session";
options.IdleTimeout = TimeSpan.FromMinutes(30);
});

//required to access existing headers
services.AddHttpContextAccessor();
services.AddOptions();
Expand Down Expand Up @@ -292,7 +302,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<

app.Use(async (context, next) =>
{
context.Response.Headers.Append("X-Frame-Options", "SAMEORIGIN");
context.Response.Headers.Append("X-Frame-Options", "DENY");
//context.Response.Headers.Append("Content-Security-Policy", "frame-ancestors 'self';");
await next();
});

Expand Down