Skip to content

fix: let browser handle navigation requests to support auth proxies#2069

Open
pakerfeldt wants to merge 1 commit intoFlowFuse:mainfrom
pakerfeldt:fix-sw-auth-proxy
Open

fix: let browser handle navigation requests to support auth proxies#2069
pakerfeldt wants to merge 1 commit intoFlowFuse:mainfrom
pakerfeldt:fix-sw-auth-proxy

Conversation

@pakerfeldt
Copy link

Description

When the dashboard is deployed behind an authentication proxy (Cloudflare Access, OAuth2 Proxy, Authelia, etc.), the service worker intercepts all navigation requests and serves a cached index.html. This prevents the browser from following the proxy's HTTP redirect to the login page when the auth session expires, resulting in "There was an error loading the Dashboard."

Remove the NavigationRoute registration so the service worker never handles navigation requests. The browser performs normal network navigation and can follow auth redirects naturally.
To prevent precacheAndRoute from implicitly serving index.html for navigation requests (via its directoryIndex and cleanURLs defaults), both options are explicitly disabled.
Static asset requests (JS, CSS, fonts, images) are unaffected, they are not navigation requests and continue to be served from the precache via exact URL match.

Testing

Tested behind Cloudflare Access (Zero Trust) with Google IdP:

  • Auth session expiry → browser redirects to login page → re-authentication returns to dashboard
  • Static assets still served from precache

Related Issue(s)

Fixes #2068

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
    Unsure how we would write tests for the service worker.
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on FlowFuse/helm to update ConfigMap Template
    • Issue/PR raised on FlowFuse/CloudProject to update values for Staging/Production
  • Link to Changelog Entry PR, or note why one is not needed.

Labels

  • Includes a DB migration? -> add the area:migration label

When the dashboard sits behind an authentication proxy (Cloudflare
Access, OAuth2 Proxy, Authelia, etc.), the service worker must not
intercept navigation requests. Otherwise it serves a cached index.html,
preventing the browser from following HTTP redirects to the login page
when the auth session expires.

Remove the NavigationRoute + createHandlerBoundToURL registration and
disable precacheAndRoute's directoryIndex and cleanURLs options so it
cannot implicitly serve index.html for navigation requests.

Static assets (JS, CSS, fonts, images) are still served from the
precache via exact URL match, so page loads remain fast.
@pakerfeldt
Copy link
Author

With issue #2068 and this PR, I hope we can have a conversation on how to resolve the problem. This PR is a suggested solution that has been proving to work for me, but maybe people with more experience of service workers would come up with a better approach.

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.

Service worker prevents auth redirect when dashboard is behind an authentication proxy

1 participant