home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
3.98k stars 2.72k forks source link

service-worker caching policy too aggressive #14836

Open kantlivelong opened 1 year ago

kantlivelong commented 1 year ago

Checklist

Describe the issue you are experiencing

When running Home Assistant behind a reverse proxy along with other web apps service-worker.js will cache content from other apps which causes them to break. Currently service-worker is configured to cache anything that comes back with a 200 (or 0) status code.

An example of this is:

  1. Two apps/services behind a reverse proxy: -- (A) Home Assistant being served at https://domain.tld/ -- (B) Z-Wave JS UI being served at https://domain.tls/_/zwavejs2mqtt
  2. Ensure cache is cleared and service worker not registered.
  3. Browse to B, this should work
  4. Browse to A, also works.
  5. Now go back to B. You'll notice that data served by web socket no longer works. This is because service-worker is caching session details that are provided via a GET request.

Describe the behavior you expected

service-worker should only cache things that actually relate to HA.

Would it be worthwhile to cache content based on a header? https://developer.chrome.com/docs/workbox/modules/workbox-cacheable-response/#caching-based-on-headers https://github.com/home-assistant/frontend/blob/dev/src/entrypoints/service_worker.ts#L64

Steps to reproduce the issue

High level reproduction steps are outlined in the problem. Can provide specific configs/setup information if needed.

What version of Home Assistant Core has the issue?

core-2022.12.7

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

FireFox 108

Which operating system are you using to run this browser?

Linux Mint 21

State of relevant entities

No response

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

No response

Additional information

No response

mitchcapper commented 1 year ago

Fantastic find, confirmed to happen in chrome too and break plenty of other items running on the same hostname.

mitchcapper commented 1 year ago

For a temporary work around you can add an exception for a prefix to the cacher. This is very fragile as it depends on their obfuscated code but wfm for now: sed -i 's#re(new RegExp("/(api|auth)/.*"),new le)#re(new RegExp("/(api|auth)/.*"),new le),re(new RegExp("/SOME_PREFIX_HERE.*"),new le)#' /usr/local/lib/python3.10/site-packages/hass_frontend/service_worker.js

then as long as /SOME_PREFIX_HERE is used to start a proxy path it won't cache it. If the code changes just search that file for api|auth and copy that regex code and add another for what you want.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

kantlivelong commented 1 year ago

This is still an issue.

github-actions[bot] commented 1 year ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

kantlivelong commented 1 year ago

This is still an issue.

github-actions[bot] commented 11 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

kantlivelong commented 11 months ago

This is still an issue.

github-actions[bot] commented 8 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

kantlivelong commented 8 months ago

This is still an issue.

github-actions[bot] commented 5 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

kantlivelong commented 5 months ago

This is still an issue.

github-actions[bot] commented 2 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

kantlivelong commented 2 months ago

This is still an issue.