@oxyhq/core 13.0.0 → 13.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,14 +21,14 @@ bun add @oxyhq/core
21
21
  - **Device management**
22
22
  - **Linked clients** for app backends that need the active Oxy bearer token
23
23
  - **User identity contracts and handle normalization** so apps render display names and build local/federated profile handles consistently
24
- - **Server middleware** for Express request identity and per-user rate limiting
24
+ - **Server middleware** for Express request identity, per-user rate limiting, and shared security headers / CSP baseline
25
25
 
26
26
  ## Exports
27
27
 
28
28
  The package exposes two public entry points:
29
29
 
30
30
  - `@oxyhq/core` — main entry (API client, session, crypto, models, shared utilities, i18n, platform, device)
31
- - `@oxyhq/core/server` — Express-only helpers (`createOxyRateLimit`, `createOxyAuthMiddleware`, `requireOxyAuth`, `getOxyUserId`, `getRequiredOxyUserId`, `createOxyCors`, `safeFetch`, `verifySecret`, and request types)
31
+ - `@oxyhq/core/server` — Express-only helpers (`createOxyRateLimit`, `createOxyAuthMiddleware`, `requireOxyAuth`, `getOxyUserId`, `getRequiredOxyUserId`, `createOxyCors`, `createOxySecurityHeaders`, `buildOxyCspDirectives`, `safeFetch`, `verifySecret`, and request types)
32
32
 
33
33
  All client/runtime symbols (including `SessionClient`, `KeyManager`, `SignatureService`, `RecoveryPhraseService`, and the shared color / theme / error / network / debug helpers) are re-exported from the package root. Server-only Express helpers live under `@oxyhq/core/server` so React Native and browser bundles never import Express.
34
34
 
@@ -159,6 +159,40 @@ For routers that are not mounted after `createOxyRateLimit`, use
159
159
  `createOxyAuthMiddleware(oxy)` to resolve the bearer session and require a user
160
160
  in one middleware.
161
161
 
162
+ ## Security Headers And CSP
163
+
164
+ `createOxySecurityHeaders` is Helmet plus the Oxy-wide Content-Security-Policy
165
+ baseline: the Cloudflare Web Analytics beacon (which Cloudflare injects into
166
+ proxied HTML, and which needs `static.cloudflareinsights.com` in `script-src`
167
+ AND `cloudflareinsights.com` in `connect-src`), the Oxy API and CDN origins the
168
+ SDK talks to, and the standard hardening floor. Apps never name those hosts
169
+ themselves.
170
+
171
+ Mount it on backends that SERVE HTML. A JSON-only API gains nothing from a
172
+ source-list CSP — it governs no browsing context — so harden those with the
173
+ non-CSP headers (`hsts`, `noSniff`, `frameguard`, CORP) instead.
174
+
175
+ ```ts
176
+ import { createOxySecurityHeaders } from '@oxyhq/core/server';
177
+
178
+ app.use(createOxySecurityHeaders({
179
+ csp: {
180
+ connectSrc: ['https://api.example.com', 'wss://api.example.com'],
181
+ frameSrc: ['https://player.vimeo.com'],
182
+ },
183
+ helmet: { crossOriginResourcePolicy: { policy: 'cross-origin' } },
184
+ }));
185
+ ```
186
+
187
+ `csp` entries are ADDED to the baseline and deduped — a directive can never be
188
+ replaced, so `'self'` (and the beacon hosts) cannot be dropped; extending a
189
+ directive the baseline does not define seeds it with `'self'` first. The
190
+ `helmet` passthrough covers every non-CSP header (`hsts`, `frameguard`,
191
+ `referrerPolicy`, CORP/COOP, …) and rejects `contentSecurityPolicy` at compile
192
+ time so the baseline cannot be bypassed. Surfaces that set the header
193
+ themselves (a Next.js `headers()`, an edge worker) can call
194
+ `buildOxyCspDirectives(extensions)` for the resolved directive map.
195
+
162
196
  ## User Identity Normalization
163
197
 
164
198
  `@oxyhq/core` normalizes user payloads returned by auth and user APIs so `id` is