dsh-relay-phone 0.17.0 → 0.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-relay-phone",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Remote-control your local DeepSeek Harness from a phone through your own zero-knowledge relay: phone-first page, QR pairing, end-to-end encryption, approvals, full desktop UI fallback.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -239,6 +239,12 @@ export function buildBootSource(id, gate) {
239
239
  // because it never named where it was going. The plaintext is now
240
240
  // 0x02 | u32 headerLen | JSON {m,t,c} | body
241
241
  // and the host refuses a request whose outer method/target disagree.
242
+ function bytesToBase64(bytes) {
243
+ var text = ''
244
+ for (var i = 0; i < bytes.length; i++) text += String.fromCharCode(bytes[i])
245
+ return btoa(text)
246
+ }
247
+
242
248
  var BOUND = 0x02
243
249
  function sealBound(method, target, contentType, bytes) {
244
250
  var enc = new TextEncoder()
@@ -373,7 +379,16 @@ export function buildBootSource(id, gate) {
373
379
  return bodyPromise.then(function (body) {
374
380
  var isRead = options.method === 'GET' || options.method === 'HEAD'
375
381
  if (body === null && isRead) {
376
- // GET/HEAD: there is no body, so only the response is sealed.
382
+ // GET/HEAD: there is no body, so only the response is sealed - but the
383
+ // request still has to prove it came from this page. Without the proof
384
+ // header the relay could mint a GET of its own and make the host run it
385
+ // with the host cookie.
386
+ headers.set('x-relay-bind', bytesToBase64(sealBound(
387
+ options.method || 'GET',
388
+ absolute.pathname + absolute.search,
389
+ '',
390
+ new Uint8Array(8).fill(0),
391
+ )))
377
392
  return origFetch(finalUrl, Object.assign({}, options, { headers: headers }))
378
393
  .then(maybeUnwrap)
379
394
  }
package/src/pump.js CHANGED
@@ -753,9 +753,58 @@ export class PumpManager {
753
753
  this.forwardSealed(sid, stream, plain)
754
754
  }
755
755
 
756
+ /**
757
+ * A sealed read has no body to bind, so the client proves it instead: a small
758
+ * sealed `{m,t}` envelope in `x-relay-bind`. Without it the relay could mint a
759
+ * GET of its own and make the host run it with the host cookie. Opening the
760
+ * proof also puts its nonce in the replay cache, so a captured header cannot
761
+ * be reused.
762
+ */
763
+ verifyReadProof(sid, stream) {
764
+ const info = stream.info
765
+ const header = info.headers.get('x-relay-bind')
766
+ if (!header) {
767
+ auditLog(`sealed read without a proof refused (${info.method} ${info.path})`)
768
+ this.respondInline(sid, 400, 'Bad Request', 'dsh-relay-phone: sealed reads need a proof header\n')
769
+ this.closeStream(sid)
770
+ return false
771
+ }
772
+ let sealed
773
+ try {
774
+ sealed = Buffer.from(String(header), 'base64')
775
+ } catch {
776
+ sealed = null
777
+ }
778
+ const proof = sealed && sealed.length >= SEALED_BODY_MIN
779
+ ? this.cryptoBox.open(this.cryptoBox.envelopeKey, sealed)
780
+ : null
781
+ if (!proof) {
782
+ auditLog(`sealed read with an unopenable proof refused (${info.path})`)
783
+ this.respondInline(sid, 400, 'Bad Request')
784
+ this.closeStream(sid)
785
+ return false
786
+ }
787
+ const { bound } = this.unwrapBound(proof)
788
+ if (!bound) {
789
+ auditLog(`sealed read with an unbound proof refused (${info.path})`)
790
+ this.respondInline(sid, 400, 'Bad Request')
791
+ this.closeStream(sid)
792
+ return false
793
+ }
794
+ const mismatch = this.boundMismatch(bound, info)
795
+ if (mismatch) {
796
+ auditLog(`sealed read proof mismatch: ${mismatch}`)
797
+ this.respondInline(sid, 400, 'Bad Request', 'dsh-relay-phone: sealed request was re-routed\n')
798
+ this.closeStream(sid)
799
+ return false
800
+ }
801
+ return true
802
+ }
803
+
756
804
  /** Send an opened (or bodyless) sealed request upstream and seal the response. */
757
805
  forwardSealed(sid, stream, plain, { responseOnly = false } = {}) {
758
806
  const info = stream.info
807
+ if (responseOnly && !this.verifyReadProof(sid, stream)) return
759
808
  const { body, bound } = this.unwrapBound(plain)
760
809
  if (bound) {
761
810
  const mismatch = this.boundMismatch(bound, info)