Skip to content

Lack of cache control headers leads to 'Failed to connect to server' when behind authenticating reverse proxy #626

@michaeltandy

Description

@michaeltandy

Hello!

I host novnc behind a reverse proxy, and when a user makes a request without the right authentication cookies, it forwards them to an auth server to get them. But I've run into a minor caching problem with this setup.

Websockify doesn't set a cache-control header when serving static files - so web browsers apply heuristic caching, and cache the HTML for several days. Everything works fine on the first load, and for a few hours thereafter.

But if a user loads novnc after their auth cookies have expired, vnc.html and all other assets are served from their cache (without revalidation) so they don't get forwarded to re-authenticate. The browser's first request is a websocket request to /websockify - to which the reverse proxy responds with a 302 HTTP redirect to a login page.

But the javascript websocket API considers this a generic failure to open a websocket; Failed when connecting: Connection closed (code: 1006) - and the user is shown novnc's ‘Failed to connect to server’ red bar.

There are a few possible fixes for this:

  1. Websockify could start adding cache-control headers to static assets.
  2. Novnc could try to detect and handle this situation in javascript (e.g. make a HTTP request to detect if redirection is going on)
  3. I could switch to a better reverse proxy, one that can add cache control headers for me.
  4. I could set the file modification time on vnc.html to the year 3000 so browser heuristic caching stops deciding to cache it (I'm trying this as a workaround)

Obviously it's debatable where this issue belongs, but novnc said cache header questions belong to websockify back in 2018 so here I am. Thanks for taking the time to read my issue! 🙂

Here is a redacted screenshot showing a wss:// request getting a HTTP 302 redirect response:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions