@dokebi/websocket 0.4.3 → 0.4.4
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/AI.md +1 -1
- package/dist/gateway.js +8 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/AI.md
CHANGED
|
@@ -182,7 +182,7 @@ stop: block new work → wait for received handlers and broadcasts being sent
|
|
|
182
182
|
|
|
183
183
|
## 9. Cautions
|
|
184
184
|
|
|
185
|
-
- Never use `origins: '*'` on a cookie-authenticated route (Cross-Site WebSocket Hijacking). When a proxy rewrites Host, set web `trustProxy` accordingly or list the public origin in `origins`.
|
|
185
|
+
- Never use `origins: '*'` on a cookie-authenticated route (Cross-Site WebSocket Hijacking). Without `origins` the same Host passes with either scheme, except one case: an upgrade that came over **https** (the socket, or `X-Forwarded-Proto` from a proxy in web `trustProxy`) with an **`http://`** Origin of that host is 403 — an http page can be rewritten on the path and must not open the wss socket with the user's cookies. List `http://…` in `origins` if a page really has to. An upgrade that looks like http (a TLS proxy the app does not trust) is not held to this: name the proxy in `trustProxy`. When a proxy rewrites Host, set web `trustProxy` accordingly or list the public origin in `origins`.
|
|
186
186
|
- Examples that trust a header value as the identity (example 23) are for tests only.
|
|
187
187
|
- `hub.events` is consumed only by this plugin. No other code reads it.
|
|
188
188
|
- Broadcasts are at most once. They can be missed across reconnects, leader changes and slow consumers, and resending after `OUTCOME_UNKNOWN` can deliver twice.
|
package/dist/gateway.js
CHANGED
|
@@ -148,7 +148,7 @@ function parseOrigins(value) {
|
|
|
148
148
|
* Browsers always send Origin on WebSocket upgrades, so a foreign page cannot reuse the user's
|
|
149
149
|
* cookies (CSWSH) unless its origin is allowed. Clients without Origin are not browsers.
|
|
150
150
|
*/
|
|
151
|
-
function originAllowed(origin, host, allowed) {
|
|
151
|
+
function originAllowed(origin, host, allowed, secure = false) {
|
|
152
152
|
if (origin === undefined || allowed === '*')
|
|
153
153
|
return true;
|
|
154
154
|
if (typeof origin !== 'string')
|
|
@@ -166,6 +166,12 @@ function originAllowed(origin, host, allowed) {
|
|
|
166
166
|
return true;
|
|
167
167
|
if (typeof host !== 'string' || !host)
|
|
168
168
|
return false;
|
|
169
|
+
// The same host over plain http is another origin for a request that came over https: an
|
|
170
|
+
// http page (which anyone on the path can rewrite) must not open the wss socket with the
|
|
171
|
+
// user's cookies. The other way round is not refused: behind a TLS proxy the app does not
|
|
172
|
+
// trust, the request looks like http while the page really is https.
|
|
173
|
+
if (secure && url.protocol === 'http:')
|
|
174
|
+
return false;
|
|
169
175
|
try {
|
|
170
176
|
return new URL(`${url.protocol}//${host}`).host === url.host;
|
|
171
177
|
}
|
|
@@ -397,7 +403,7 @@ export class Gateway {
|
|
|
397
403
|
// D-0140: dokebi-web records and checks `config.id` (describe, duplicates, route hooks).
|
|
398
404
|
...(config ? { config: { ...config } } : {}),
|
|
399
405
|
preValidation: async (request, reply) => {
|
|
400
|
-
if (!originAllowed(request.headers.origin, this.web.requestHost(request), origins)) {
|
|
406
|
+
if (!originAllowed(request.headers.origin, this.web.requestHost(request), origins, request.protocol === 'https')) {
|
|
401
407
|
if (logger.isEnabled('debug'))
|
|
402
408
|
logger.log('debug', 'WebSocket origin refused', {
|
|
403
409
|
path: route.path,
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ class WebsocketRuntime {
|
|
|
59
59
|
/** Factory input: `{ app, options? }`. Options default to `app.config['dokebi-websocket']`. */
|
|
60
60
|
export const createPlugin = definePlugin({
|
|
61
61
|
name: 'dokebi-websocket',
|
|
62
|
-
version: '0.4.
|
|
62
|
+
version: '0.4.4',
|
|
63
63
|
core: '^0.4.2',
|
|
64
64
|
options,
|
|
65
65
|
contributes: [realtime],
|