Skip to content

Grant Private Network Access preflights for /files/ data links#395

Open
krokicki wants to merge 1 commit into
mainfrom
private-network-access
Open

Grant Private Network Access preflights for /files/ data links#395
krokicki wants to merge 1 commit into
mainfrom
private-network-access

Conversation

@krokicki

@krokicki krokicki commented Jun 23, 2026

Copy link
Copy Markdown
Member

Problem

Browsers are tightening access from public-origin pages to private-network hosts. Chromium (Chrome/Edge) does this via Private Network Access (PNA): before a request from a public-origin page (e.g. https://neuroglancer-demo.appspot.com) to a private-network address (e.g. an internal host serving Fileglancer's /files/ data links), the browser sends a CORS preflight carrying Access-Control-Request-Private-Network: true. The request only proceeds if the response echoes Access-Control-Allow-Private-Network: true.

Starlette's CORSMiddleware does not emit that header, so Chromium blocks cross-origin viewers (Neuroglancer/N5/Vizarr) from loading data hosted on an internal network.

Change

Add a small pure-ASGI PrivateNetworkAccessMiddleware (modeled on the existing RequestIdMiddleware) that appends Access-Control-Allow-Private-Network: true to responses for preflights carrying the PNA request header. It is registered outside CORSMiddleware so it wraps the preflight response that CORS generates. The header is added only when the PNA request header is present (sent by browsers solely on preflights), so it never leaks onto normal data responses.

Tests

  • test_pna_preflight_grants_private_network — preflight with the PNA request header gets the grant header back.
  • test_pna_header_absent_without_request — the grant header does not appear on ordinary responses.

Note on Firefox

This does not address Firefox, which uses a user-permission model (Local Network Access) rather than a server header. The Firefox remedy is client/policy-side (network.lna.skip-domains, or the enterprise LocalNetworkAccess policy). This PR gets ahead of the equivalent Chromium breakage.

A mirroring change is in x2s3, since the two share this CORS surface.

@StephanPreibisch @JaneliaSciComp/fileglancer

…links

Chromium (Chrome/Edge) sends a CORS preflight before any request from a
public-origin page (e.g. https://neuroglancer-demo.appspot.com) to a
private-network address, and only proceeds if the response echoes
`Access-Control-Allow-Private-Network: true`. Starlette's CORSMiddleware
does not emit this, so Chromium blocks cross-origin viewers
(Neuroglancer/N5/Vizarr) from loading data hosted on an internal host.

Add a pure-ASGI PrivateNetworkAccessMiddleware that echoes the grant header
on preflights carrying `Access-Control-Request-Private-Network: true`,
registered outside CORSMiddleware so it wraps the preflight response.

Note: this does not affect Firefox, which uses a user-permission model
(Local Network Access) rather than this header.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@krokicki krokicki requested a review from neomorphic June 23, 2026 18:44
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.

1 participant