question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for Private Network Access (CORS header Access-Control-Allow-Private-Network)

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to reach my ASP.NET core api running on https://localhost:5001/ from a SPA which is hosted on another domain (although same computer for me) and I get a CORS error.

Describe the solution you’d like

I would like to propose that we extend the CorsPolicy with the boolean property AllowPrivateNetworkAccess and CorsPolicyBuilder with the method WithPrivateNetworkAccess which the CorsService uses to set the Access-Control-Allow-Private-Network: true on preflight requests if the browser sends the Access-Control-Request-Private-Network: true header in the request.

Additional context

Link to WICG Draft: https://wicg.github.io/private-network-access/ Link to Chrome developer article about the feature and roll out: https://developer.chrome.com/blog/private-network-access-preflight/

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Andreas-Hjortlandcommented, Mar 25, 2022

For people who are having issues with the private network access cors header, you can add the following code snippet just before app.UseCors() in your ASP.NET application to work around the issue until we get proper support through the CorsPolicyBuilder interface:

// Enable PNA preflight requests
app.Use(async (ctx, next) =>
{
    if (ctx.Request.Method.Equals("options", StringComparison.InvariantCultureIgnoreCase) && ctx.Request.Headers.ContainsKey("Access-Control-Request-Private-Network"))
    {
        ctx.Response.Headers.Add("Access-Control-Allow-Private-Network", "true");
    }

    await next();
});
app.UseCors();
1reaction
msftbot[bot]commented, Oct 26, 2022

Thanks for contacting us.

We’re moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s). If we later determine, that the issue has no community involvement, or it’s very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Private Network Access: introducing preflights
First, implement support for standard CORS preflight requests on affected routes. Then add support for the two new response headers. When your ...
Read more >
IIS CORS Module support for Access-Control-Allow-Private ...
Chromium 98 introduces [1] a new CORS request. Is there a way to request support for additional CORS headers from the Official Microsoft...
Read more >
Spring CORS Filter for Access-Control-Allow-Private ...
I am using Spring Boot 2.7 therefore Spring 5.3 is included. It uses a custom CorsProcessor class to add the relevant header to...
Read more >
CORS extension “Private Network Access”
This works by issuing a HTTP OPTIONS request, adding information about the upcoming request with the headers Access-Control-Request-Method and ...
Read more >
How to add the "Access-Control-Allow-Private-Network
The solution is to send a custom header from Wowza server Access-Control-Allow-Private-Network: true whenever the HTTP provider url is accessed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found