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

Support Private Network Access #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

mluex
Copy link

@mluex mluex commented Jul 19, 2023

Chrome is deprecating access to private network endpoints from non-secure websites as part of the Private Network Access specification. The aim is to protect users from cross-site request forgery (CSRF) attacks targeting routers and other devices on private networks. These attacks have affected hundreds of thousands of users, allowing attackers to redirect them to malicious servers.

Source: https://developer.chrome.com/blog/private-network-access-update/

For more and up to date details on how it works, implementation timeline on the part of Google Chrome, please check out the link provided.

To summarize briefly:
When the browser notices that a website A wants to request a resource from website B and website B is a website in private IP space, the browser sends a additional headers in the Preflight request (along with CORS headers, if any).

HTTP/1.1 OPTIONS /delete-item
Origin: https://www.example.com
Access-Control-Request-Method: PUT
Access-Control-Request-Credentials: true
Access-Control-Request-Private-Network: true

The header Access-Control-Request-Private-Network: true is the one we are concerned with here.

If the server behind website B wants to allow this request, then it has to respond with status code 200 / 204 and the response header Access-Control-Allow-Private-Network: true.

HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://www.example.com
Access-Control-Allow-Methods: PUT
Access-Control-Allow-Credentials: true
Access-Control-Allow-Private-Network: true

This PR implements the standard in this great bundle to allow or deny (default) Private Network Access with the appropriate header.

Users may set allow_private_network: true in nelmio_cors.yaml to instruct the bundle to set Access-Control-Allow-Private-Network: true for Preflight requests containing Access-Control-Request-Private-Network: true.

if ('OPTIONS' === $request->getMethod() && $request->headers->has('Access-Control-Request-Method')) {
if ('OPTIONS' === $request->getMethod() &&
($request->headers->has('Access-Control-Request-Method') ||
$request->headers->has('Access-Control-Request-Private-Network'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it allowed to have the Access-Control-Request-Private-Network header without Access-Control-Request-Method?

Comment on lines +224 to +225
if ($request->headers->has('Access-Control-Request-Private-Network')
&& strtolower($request->headers->get('Access-Control-Request-Private-Network')) === 'true'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ($request->headers->has('Access-Control-Request-Private-Network')
&& strtolower($request->headers->get('Access-Control-Request-Private-Network')) === 'true'
if (strtolower($request->headers->get('Access-Control-Request-Private-Network')) === 'true'

and, I'm not sure non lowercase true is allowed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants