@johnhenry/browsermesh-core 0.2.1 → 0.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/handshake.mjs +22 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnhenry/browsermesh-core",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Identity, crypto, peer management, and trust primitives for BrowserMesh",
5
5
  "type": "module",
6
6
  "main": "./src/index.mjs",
package/src/handshake.mjs CHANGED
@@ -316,9 +316,19 @@ export class SignalingClient {
316
316
  if (!this.#ws) {
317
317
  throw new Error('SignalingClient not connected')
318
318
  }
319
+ // The real deployed signaling server (browsermesh-servers/signaling)
320
+ // forwards offer/answer/ice-candidate/signal messages by their
321
+ // "target" field, not "to" -- confirmed directly against that
322
+ // server's own source (`const {target, ...payload} = msg`). A `to`
323
+ // field is simply ignored server-side, so every forwarded message
324
+ // was rejected with "forwarded messages require a target field"
325
+ // before this fix. `from` is sent for backward-compatible local
326
+ // debugging/logging only -- the server doesn't read or forward it
327
+ // as-is; see #fire()'s own comment for why the receiving side no
328
+ // longer trusts it.
319
329
  const msg = JSON.stringify({
320
330
  from: this.#localPodId,
321
- to: remotePodId,
331
+ target: remotePodId,
322
332
  type,
323
333
  ...payload,
324
334
  })
@@ -372,8 +382,18 @@ export class SignalingClient {
372
382
  #fire(event, data) {
373
383
  const set = this.#listeners.get(event)
374
384
  if (!set) return
385
+ // The real signaling server stamps forwarded peer-to-peer messages
386
+ // with its own "source" field, based on which authenticated
387
+ // WebSocket connection the message actually arrived on -- that's
388
+ // the trustworthy value. `from` is whatever the ORIGINAL sender
389
+ // self-declared in their own outgoing payload and the server never
390
+ // validates it before forwarding, so preferring it here would mean
391
+ // trusting an arbitrary, spoofable claim over the server's own
392
+ // attribution. Falls back to `from` only for non-forwarded,
393
+ // direct server messages (e.g. `registered`) that have no `source`.
394
+ const fromPodId = data.source ?? data.from
375
395
  for (const cb of set) {
376
- try { cb(data, data.from) } catch (e) { silentCatch('clawser-mesh-handshake', 'swallow-listener-errors', e) }
396
+ try { cb(data, fromPodId) } catch (e) { silentCatch('clawser-mesh-handshake', 'swallow-listener-errors', e) }
377
397
  }
378
398
  }
379
399
  }