Title: Unable to Clear Cached Data in Angular-Generated Service Worker · Issue #58733 · angular/angular · GitHub
Open Graph Title: Unable to Clear Cached Data in Angular-Generated Service Worker · Issue #58733 · angular/angular
X Title: Unable to Clear Cached Data in Angular-Generated Service Worker · Issue #58733 · angular/angular
Description: Which @angular/* package(s) are the source of the bug? service-worker Is this a regression? No Description I am using the Angular Service Worker, and it works well overall. However, I encountered a potential data leak issue when caching ...
Open Graph Description: Which @angular/* package(s) are the source of the bug? service-worker Is this a regression? No Description I am using the Angular Service Worker, and it works well overall. However, I encountered a...
X Description: Which @angular/* package(s) are the source of the bug? service-worker Is this a regression? No Description I am using the Angular Service Worker, and it works well overall. However, I encountered a...
Opengraph URL: https://github.com/angular/angular/issues/58733
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unable to Clear Cached Data in Angular-Generated Service Worker","articleBody":"### Which @angular/* package(s) are the source of the bug?\n\nservice-worker\n\n### Is this a regression?\n\nNo\n\n### Description\n\nI am using the Angular Service Worker, and it works well overall. However, I encountered a potential data leak issue when caching API responses. Here’s the scenario:\n\nIf I cache an API response (e.g., abc.com/api/posts) for User A, then log out and log in as User B, and switch to offline mode before fetching the API for User B, I can still see the cached data belonging to User A. This is a significant security concern, as it exposes sensitive data across user sessions.\n\nTo address this issue, I decided to implement a custom service worker to extend the functionality of Angular’s generated service worker. My custom implementation looks like this:\n\n```javascript\nimportScripts('./ngsw-worker.js');\n\nself.addEventListener('message', async (event) => {\n const cacheNames = await self.caches.keys();\n for (const name of cacheNames) {\n await self.caches.delete(name);\n }\n});\n``` \n\nWith this approach, I expect that sending a message (e.g., after logging out) will clear all cached data from the browser's cache storage:\n\n```javascript\nnavigator.serviceWorker.controller.postMessage({\n type: 'CLEAR_CACHE',\n});\n``` \n\nWhile this solution successfully clears the visible data in the browser’s cache storage (verified via DevTools), an issue persists: if I refresh the page and switch to offline mode, the previously cached data is still accessible. This suggests that Angular’s ngsw-worker.js maintains an internal cache that I cannot access or clear using my current implementation.\n\n### Please provide a link to a minimal reproduction of the bug\n\n_No response_\n\n### Please provide the exception or error you saw\n\n```true\n\n```\n\n### Please provide the environment you discovered this bug in (run `ng version`)\n\n```true\nAngular CLI: 17.2.3\nNode: 20.10.0\nPackage Manager: npm 10.2.3\nOS: Mac os\n\nAngular: 17.2.3\n... animations, common, compiler, compiler-cli, core, forms\n... platform-browser, platform-browser-dynamic, router\n\nPackage Version\n---------------------------------------------------------\n@angular-devkit/architect 0.1702.3\n@angular-devkit/build-angular 17.2.3\n@angular-devkit/core 17.2.3\n@angular-devkit/schematics 17.2.3\n@angular/cli 17.2.3\n@schematics/angular 17.2.3\nrxjs 7.5.6\ntypescript 5.3.3\nzone.js 0.14.4\n```\n\n### Anything else?\n\n_No response_","author":{"url":"https://github.com/mehranmb78","@type":"Person","name":"mehranmb78"},"datePublished":"2024-11-19T12:59:06Z","url":"https://github.com/angular/angular/issues/58733"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:191d8b69-0f78-a586-a48b-648ab9f913ad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E4AA:91CF4:FC91E7:14F28C6:6B010783 |
| html-safe-nonce | 93499c84a7d268ee9d32fd373cf2494d2e7b85edf915300aa1d6491adf9f20a1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNEFBOjkxQ0Y0OkZDOTFFNzoxNEYyOEM2OjZCMDEwNzgzIiwidmlzaXRvcl9pZCI6IjI0NzU4MTc3Mzc2MTI0OTQ3MjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 99d7359694939531d16950c892d882f416f4286af6f01295c14ef91cc9ae15fa |
| hovercard-subject-tag | issue:2672084471 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/58733/issue_layout |
| twitter:image | https://opengraph.githubassets.com/87f5cdf86eb58711921e1d28d465765672f04bcc5c457bcb6d1e6263af840b69/angular/angular/issues/58733 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/87f5cdf86eb58711921e1d28d465765672f04bcc5c457bcb6d1e6263af840b69/angular/angular/issues/58733 |
| og:image:alt | Which @angular/* package(s) are the source of the bug? service-worker Is this a regression? No Description I am using the Angular Service Worker, and it works well overall. However, I encountered a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mehranmb78 |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width