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

[BUG] . NET9.0 Blazor Web App cannot allow cross domain websites to display nested iframe tags #59532

Closed
jackrao168 opened this issue Nov 27, 2024 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@jackrao168
Copy link

Describe the bug

. NET9.0 Blazor Web App cannot allow cross domain websites to display nested iframe tags.

Exceptions (if any)

  • Adding code to. NET 8.0 is effective, but NET9.0 is invalid:
    builder.Services.AddAntiforgery(options =>
    {
    options.SuppressXFrameOptionsHeader = true;
    });

Further technical details

  • Browser page prompt: Localhost has refused the connection.

  • Browser console error message: Refused to frame 'https://localhost:33500/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

  • Browser response header: content-security-policy: frame-ancestors 'self'

  • Trying to add the following code did not solve the problem,The reason is that regardless of the operation, there is always a policy in the browser response header:content-security-policy: frame-ancestors 'self':
    app.Use(async (context, next) =>
    {
    // https://localhost:5000 As the parent page domain name
    context.Response.Headers.Append("Content-Security-Policy", "frame-ancestors https://localhost:5000");
    // or
    // context.Response.Headers.Append("Content-Security-Policy", "frame-ancestors *");
    // or
    // context.Response.Headers.Remove("Content-Security-Policy");

    await next();
    });

@marcpopMSFT marcpopMSFT transferred this issue from dotnet/sdk Dec 17, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Dec 17, 2024
@martincostello martincostello added area-blazor Includes: Blazor, Razor Components and removed untriaged area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Dec 18, 2024
@javiercn
Copy link
Member

@jackrao168 thanks for contacting us.

Blazor enables compression of the websocket connection by default in 9.0 and limits framing of the app. You can configure this in the call to AddInteractiveServerRenderMode which will allow you to either disable compression or configure a different CSP policy.

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Dec 20, 2024
Copy link
Contributor

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@jackrao168
Copy link
Author

@jackrao168 thanks for contacting us.

Blazor enables compression of the websocket connection by default in 9.0 and limits framing of the app. You can configure this in the call to AddInteractiveServerRenderMode which will allow you to either disable compression or configure a different CSP policy.

Thank you very much, The problem has been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants