Security rules
NGB032: Service worker caches user-specific responses
Reports service-worker caching of authenticated or per-user API responses: Angular service worker ngsw-config.json dataGroups whose URL patterns cover user, account, session, order or payment endpoints (or the whole API), and custom service workers (sw.js, service-worker.ts, *-sw.js) whose fetch handler calls cache.put() without inspecting the request..
| Property | Value |
|---|---|
| Rule ID | NGB032 |
| Category | Sensitive data & payment security |
| Default severity | medium |
| CWE | CWE-524, CWE-525 |
| Built-in presets | recommended: error, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports service-worker caching of authenticated or per-user API responses: Angular service worker ngsw-config.json dataGroups whose URL patterns cover user, account, session, order or payment endpoints (or the whole API), and custom service workers (sw.js, service-worker.ts, *-sw.js) whose fetch handler calls cache.put() without inspecting the request.
Why it matters
Service-worker caches live in CacheStorage: they persist across logout and browser restarts, are shared by everyone using the browser profile, and are served before the network. A data group with the performance strategy (cache first) can show the previous user's account page to the next person on a shared device, and a cache-everything worker stores tokens and personal data on disk.
Detection behavior and supported patterns
ngsw-config.json:dataGroups[].urlsmatching/api/me,/users,/account,/session,/auth,/token,/orders,/payments,/billing,/cart,/messages… or catch-alls such as/api/**(high confidence withperformance, medium withfreshness)- Custom workers:
self.addEventListener('fetch', …)/self.onfetch = …that callcache.put(request, response)and never look atrequest.method,request.url,request.headers,request.credentials,request.modeorrequest.destination(JavaScript files are parsed syntactically) - The generated
ngsw-worker.jsand build output folders are ignored
Example
"dataGroups": [{ "name": "api", "urls": ["/api/**"], "cacheConfig": { "strategy": "performance", "maxAge": "7d", "maxSize": 100 } }]Safer alternative
"dataGroups": [{ "name": "catalog", "urls": ["/api/catalog/**"], "cacheConfig": { "strategy": "freshness", "maxAge": "1h", "maxSize": 50 } }]Remediation
Only cache public, non-personal API responses in dataGroups, or use the freshness strategy with a short maxAge and clear caches on logout. In custom workers, skip non-GET requests, requests with credentials or an Authorization header, and personal endpoints before calling cache.put().
False-positive considerations
- Data groups for endpoints that look user-specific but return public data (e.g.
/api/orders/statuses) can be reported.
Known limitations
- Workbox configurations (
workbox-config.js,registerRoute(...)strategies) are not analyzed. - Custom workers are matched by file name; workers with other names are not found.
- Whether the application clears caches on logout is not verified.
References
Run it
ngbastion explain NGB032