dsh-mobile 0.6.13 → 0.6.14

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/lib/index.d.mts CHANGED
@@ -1949,7 +1949,7 @@ interface OriginConfigurationStatus {
1949
1949
  }
1950
1950
  /** Require a public HTTPS origin; custom external ports are supported. */
1951
1951
  export declare function validateOriginPublicOrigin(value: unknown): string;
1952
- /** Bind only one explicit loopback or RFC1918 IPv4 interface, never all interfaces. */
1952
+ /** Bind one explicit loopback, RFC1918 IPv4 or IPv6 ULA interface; zone IDs are unsupported. */
1953
1953
  export declare function validateOriginListenHost(value: unknown): string;
1954
1954
  export declare function validateOriginListenPort(value: unknown): number;
1955
1955
  /** Authorize direct proxy socket peers, not untrusted forwarded client headers. */
package/lib/index.mjs CHANGED
@@ -11754,12 +11754,16 @@ const MIN_ORIGIN_LISTEN_PORT = 1024;
11754
11754
  const RESERVED_LAN_GATEWAY_PORT$1 = 3443;
11755
11755
  /** DSH's own WebServer port; the plugin cannot function while it is taken. */
11756
11756
  const RESERVED_DSH_WEB_PORT = 3080;
11757
- const PRIVATE_NETWORKS = [
11758
- "10.0.0.0/8",
11759
- "172.16.0.0/12",
11760
- "192.168.0.0/16"
11761
- ].map(parseCidr);
11762
- const TRUSTED_NETWORKS = [...PRIVATE_NETWORKS, parseCidr("127.0.0.0/8")];
11757
+ const TRUSTED_NETWORKS = [
11758
+ ...[
11759
+ "10.0.0.0/8",
11760
+ "172.16.0.0/12",
11761
+ "192.168.0.0/16",
11762
+ "fc00::/7"
11763
+ ].map(parseCidr),
11764
+ parseCidr("127.0.0.0/8"),
11765
+ parseCidr("::1/128")
11766
+ ];
11763
11767
  /** Require a public HTTPS origin; custom external ports are supported. */
11764
11768
  function validateOriginPublicOrigin(value) {
11765
11769
  if (typeof value !== "string" || value.length > 512 || /[\s\u0000-\u001f\u007f\\@?#]/u.test(value)) throw new Error("origin_public_origin_invalid");
@@ -11781,10 +11785,15 @@ function validateOriginPublicOrigin(value) {
11781
11785
  if (url.protocol !== "https:" || url.pathname !== "/" || url.username !== "" || url.password !== "" || url.search !== "" || url.hash !== "" || url.port !== "" && Number(url.port) < 1 || (isIP(host) === 4 ? !isGloballyRoutableIpv4(host) : isIP(host) !== 0 || !validHostname)) throw new Error("origin_public_origin_invalid");
11782
11786
  return url.origin;
11783
11787
  }
11784
- /** Bind only one explicit loopback or RFC1918 IPv4 interface, never all interfaces. */
11788
+ /** Bind one explicit loopback, RFC1918 IPv4 or IPv6 ULA interface; zone IDs are unsupported. */
11785
11789
  function validateOriginListenHost(value) {
11786
- if (typeof value !== "string" || isIP(value) !== 4 || !isLoopbackAddress(value) && !addressAllowed(value, PRIVATE_NETWORKS)) throw new Error("origin_listen_host_invalid");
11787
- return value;
11790
+ const addressFamily = isIP(value);
11791
+ if (typeof value !== "string" || value.includes("%") || addressFamily === 0 || !addressAllowed(value, TRUSTED_NETWORKS.filter((range) => range.bits === (addressFamily === 6 ? 128 : 32)))) throw new Error("origin_listen_host_invalid");
11792
+ return addressFamily === 6 ? new URL("http://[" + value + "]").hostname.slice(1, -1) : value;
11793
+ }
11794
+ /** Format a validated backend listener, including the brackets required by IPv6 URLs. */
11795
+ function formatOriginBackendOrigin(listenHost, listenPort) {
11796
+ return "http://" + (isIP(listenHost) === 6 ? "[" + listenHost + "]" : listenHost) + ":" + String(listenPort);
11788
11797
  }
11789
11798
  function validateOriginListenPort(value) {
11790
11799
  if (!Number.isSafeInteger(value) || Number(value) < MIN_ORIGIN_LISTEN_PORT || Number(value) > 65535) throw new Error("origin_listen_port_invalid");
@@ -11793,14 +11802,15 @@ function validateOriginListenPort(value) {
11793
11802
  }
11794
11803
  /** Authorize direct proxy socket peers, not untrusted forwarded client headers. */
11795
11804
  function validateOriginAllowedCidrs(value, listenHost) {
11796
- const input = value === void 0 && isLoopbackAddress(listenHost) ? ["127.0.0.0/8"] : value;
11805
+ const addressFamily = isIP(listenHost);
11806
+ const input = value === void 0 && isLoopbackAddress(listenHost) ? [addressFamily === 6 ? "::1/128" : "127.0.0.0/8"] : value;
11797
11807
  if (!Array.isArray(input) || input.length === 0 || input.length > 16) throw new Error("origin_allowed_cidrs_invalid");
11798
11808
  const cidrs = [];
11799
11809
  for (const entry of input) {
11800
- if (typeof entry !== "string" || entry.length > 64 || isIP(entry.split("/")[0] ?? "") !== 4) throw new Error("origin_allowed_cidrs_invalid");
11810
+ if (typeof entry !== "string" || entry.length > 64 || entry.includes("%") || isIP(entry.split("/")[0] ?? "") !== addressFamily) throw new Error("origin_allowed_cidrs_invalid");
11801
11811
  try {
11802
11812
  const cidr = parseCidr(entry);
11803
- if (cidr.bits !== 32 || !TRUSTED_NETWORKS.some((range) => cidr.prefix >= range.prefix && addressAllowed(entry.split("/")[0], [range]))) throw new Error("untrusted CIDR");
11813
+ if (cidr.bits !== (addressFamily === 6 ? 128 : 32) || !TRUSTED_NETWORKS.some((range) => cidr.bits === range.bits && cidr.prefix >= range.prefix && addressAllowed(entry.split("/")[0], [range]))) throw new Error("untrusted CIDR");
11804
11814
  cidrs.push(cidr.source);
11805
11815
  } catch {
11806
11816
  throw new Error("origin_allowed_cidrs_invalid");
@@ -11878,7 +11888,7 @@ var OriginConfigStore = class {
11878
11888
  listenHost: settings.listenHost,
11879
11889
  listenPort: settings.listenPort,
11880
11890
  allowedCidrs: settings.allowedCidrs,
11881
- backendOrigin: "http://" + settings.listenHost + ":" + String(settings.listenPort)
11891
+ backendOrigin: formatOriginBackendOrigin(settings.listenHost, settings.listenPort)
11882
11892
  },
11883
11893
  storagePath: this.stateRoot,
11884
11894
  ...this.errorCode === void 0 ? {} : { errorCode: this.errorCode }
@@ -12038,7 +12048,7 @@ var OriginController = class {
12038
12048
  enabled: true,
12039
12049
  state: "ready",
12040
12050
  origin: settings.publicOrigin,
12041
- backendOrigin: "http://" + settings.listenHost + ":" + String(gateway.address().port)
12051
+ backendOrigin: formatOriginBackendOrigin(settings.listenHost, gateway.address().port)
12042
12052
  });
12043
12053
  }
12044
12054
  async stop() {