ingenium 0.0.1 → 0.0.2
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 +1 -1
- package/dist/index.cjs +268 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +105 -9
- package/dist/index.d.ts +105 -9
- package/dist/index.js +268 -44
- package/dist/index.js.map +1 -1
- package/package.json +23 -8
- package/src/app.ts +7 -1
- package/src/body/multipart.ts +9 -1
- package/src/cors/middleware.ts +58 -3
- package/src/cors/types.ts +6 -3
- package/src/csrf/middleware.ts +98 -13
- package/src/csrf/types.ts +22 -1
- package/src/idempotency/middleware.ts +78 -5
- package/src/index.ts +1 -1
- package/src/jwt/middleware.ts +74 -3
- package/src/jwt/types.ts +12 -0
- package/src/jwt/verify.ts +75 -11
- package/src/problem/serialize.ts +18 -2
- package/src/proxy/trust.ts +22 -0
- package/src/session/middleware.ts +36 -3
- package/src/session/types.ts +14 -1
- package/src/static/middleware.ts +43 -8
- package/src/ws/index.ts +2 -0
- package/src/ws/middleware.ts +70 -0
- package/src/ws/types.ts +37 -0
package/src/ws/types.ts
CHANGED
|
@@ -21,12 +21,49 @@ export type WebSocket = WsWebSocket
|
|
|
21
21
|
*/
|
|
22
22
|
export type WebSocketHandler = (socket: WsWebSocket, ctx: IngeniumContext) => void | Promise<void>
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Custom Origin verifier. Receives the request's `Origin` header (or
|
|
26
|
+
* `undefined` when absent, e.g. a non-browser client) plus the raw upgrade
|
|
27
|
+
* request. Return `true` to allow the upgrade, `false` to reject it with a
|
|
28
|
+
* `403` handshake.
|
|
29
|
+
*/
|
|
30
|
+
export type WebSocketOriginVerifier = (
|
|
31
|
+
origin: string | undefined,
|
|
32
|
+
req: IncomingMessage,
|
|
33
|
+
) => boolean
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Origin allowlist policy for a WebSocket upgrade. WS handlers run OUTSIDE the
|
|
37
|
+
* normal middleware pipeline, so the only built-in defense against
|
|
38
|
+
* Cross-Site WebSocket Hijacking (CSWSH) is this option — browsers attach the
|
|
39
|
+
* victim's cookies to cross-origin upgrades, so without an Origin check any
|
|
40
|
+
* external page can open an authenticated socket.
|
|
41
|
+
*
|
|
42
|
+
* - `true` — same-origin only: the `Origin` host must equal the request `Host`.
|
|
43
|
+
* - `string` / `string[]` — exact `Origin` allowlist (compared verbatim).
|
|
44
|
+
* - function — custom predicate (see {@link WebSocketOriginVerifier}).
|
|
45
|
+
*
|
|
46
|
+
* Omitting the option preserves backward compatibility (no enforcement) but
|
|
47
|
+
* emits a one-time dev warning, because the safe default for a browser-facing
|
|
48
|
+
* socket is to restrict origins.
|
|
49
|
+
*/
|
|
50
|
+
export type WebSocketOriginOption =
|
|
51
|
+
| boolean
|
|
52
|
+
| string
|
|
53
|
+
| string[]
|
|
54
|
+
| WebSocketOriginVerifier
|
|
55
|
+
|
|
24
56
|
/** Per-handler options forwarded to `WebSocketServer({ noServer: true, ... })`. */
|
|
25
57
|
export interface WebSocketHandlerOptions {
|
|
26
58
|
/** Max payload size (bytes) for incoming frames. */
|
|
27
59
|
maxPayload?: number
|
|
28
60
|
/** Enable permessage-deflate. Defaults to false (matches `ws` default). */
|
|
29
61
|
perMessageDeflate?: boolean
|
|
62
|
+
/**
|
|
63
|
+
* Origin allowlist for the upgrade handshake — the built-in CSWSH defense.
|
|
64
|
+
* See {@link WebSocketOriginOption} for semantics and why it matters.
|
|
65
|
+
*/
|
|
66
|
+
origin?: WebSocketOriginOption
|
|
30
67
|
}
|
|
31
68
|
|
|
32
69
|
/** Internal: a registered handler entry. */
|