@dshn/agent 0.3.1 → 0.3.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/lib/index.js +12 -2
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -4624,7 +4624,15 @@ var SHIM_BODY = String.raw`
4624
4624
  let resolveReady
4625
4625
  const ready = new Promise((r) => { resolveReady = r })
4626
4626
  const hexToBytes = (hx) => { const a = new Uint8Array(hx.length / 2); for (let i = 0; i < a.length; i++) a[i] = parseInt(hx.substr(i * 2, 2), 16); return a }
4627
- const isApi = (url) => { try { const u = new URL(url, location.href); return u.origin === location.origin && u.pathname.startsWith('/api') } catch { return false } }
4627
+ // Same host as the page, over http(s) OR ws(s). A wss: URL has the origin
4628
+ // "wss://host", which never equals the page's "https://host", so comparing
4629
+ // origins would leave every event socket undecrypted.
4630
+ const isApi = (url) => {
4631
+ try {
4632
+ const u = new URL(url, location.href)
4633
+ return u.host === location.host && /^(https?|wss?):$/.test(u.protocol) && u.pathname.startsWith('/api')
4634
+ } catch { return false }
4635
+ }
4628
4636
 
4629
4637
  async function deriveKey(password, saltHex) {
4630
4638
  const base = await crypto.subtle.importKey('raw', enc.encode(password), 'PBKDF2', false, ['deriveKey'])
@@ -4704,7 +4712,9 @@ var SHIM_BODY = String.raw`
4704
4712
  : data instanceof Blob ? new Uint8Array(await data.arrayBuffer())
4705
4713
  : new Uint8Array(await new Blob([data]).arrayBuffer())
4706
4714
  const opened = await openBytes(key, raw)
4707
- data = opened[0] === 0 ? new TextDecoder().decode(opened.subarray(1)) : opened.subarray(1).buffer
4715
+ // slice, not subarray: subarray(1).buffer is the WHOLE decrypted
4716
+ // buffer, type byte included, and would hand the app one extra byte.
4717
+ data = opened[0] === 0 ? new TextDecoder().decode(opened.subarray(1)) : opened.slice(1).buffer
4708
4718
  } catch { return } // drop messages we can't decrypt
4709
4719
  }
4710
4720
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dshn/agent",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Forward a local dsh web service to the public internet over ds.hn (bundled).",
5
5
  "keywords": [
6
6
  "dsh",