@oxyhq/core 13.0.0 → 14.0.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 +36 -2
- package/dist/cjs/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +4 -3
- package/dist/cjs/mixins/OxyServices.user.js +50 -44
- package/dist/cjs/server/index.js +9 -1
- package/dist/cjs/server/securityHeaders.js +234 -0
- package/dist/cjs/utils/apiUtils.js +40 -10
- package/dist/esm/.tsbuildinfo +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/mixins/OxyServices.user.js +51 -45
- package/dist/esm/server/index.js +3 -0
- package/dist/esm/server/securityHeaders.js +224 -0
- package/dist/esm/utils/apiUtils.js +39 -10
- package/dist/types/.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/mixins/OxyServices.user.d.ts +27 -6
- package/dist/types/server/index.d.ts +2 -0
- package/dist/types/server/securityHeaders.d.ts +154 -0
- package/dist/types/utils/apiUtils.d.ts +48 -6
- package/package.json +8 -3
- package/src/index.ts +3 -0
- package/src/mixins/OxyServices.user.ts +60 -49
- package/src/mixins/__tests__/followGraphPagination.test.ts +250 -0
- package/src/server/__tests__/securityHeaders.test.ts +244 -0
- package/src/server/index.ts +16 -0
- package/src/server/securityHeaders.ts +304 -0
- package/src/utils/apiUtils.ts +64 -15
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
|
|
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
|