@dshn/agent 0.3.2 → 0.3.3

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 -4
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -4848,6 +4848,13 @@ function e2eBootstrapTag(info) {
4848
4848
  const json = JSON.stringify({ salt: info.salt, device: info.device }).replace(/</g, "\\u003c");
4849
4849
  return `<script>(function (__dshnInfo) {${SHIM_BODY}})(${json})</script>`;
4850
4850
  }
4851
+ function credentialManifestLinks(html) {
4852
+ return html.replace(/<link\b[^>]*>/gi, (tag) => {
4853
+ if (!/\brel\s*=\s*["']?manifest\b/i.test(tag) || /\bcrossorigin\b/i.test(tag))
4854
+ return tag;
4855
+ return tag.replace(/\s*\/?>$/, (end) => ` crossorigin="use-credentials"${end.trim() === "/>" ? " />" : ">"}`);
4856
+ });
4857
+ }
4851
4858
  function injectE2EBootstrap(html, info) {
4852
4859
  const tag = e2eBootstrapTag(info);
4853
4860
  const head = /<head(\s[^>]*)?>/i.exec(html);
@@ -5625,16 +5632,17 @@ var AgentTunnel = class {
5625
5632
  return;
5626
5633
  }
5627
5634
  const wantsDocument = method === "GET" && headers.some(([k, v]) => k.toLowerCase() === "accept" && v.includes("text/html"));
5628
- const injectBootstrap = this.e2eKey !== null && wantsDocument;
5629
- if (injectBootstrap)
5635
+ if (wantsDocument)
5630
5636
  outHeaders["accept-encoding"] = "identity";
5631
5637
  const req = http.request({ host: this.config.localHost, port: this.localPort(), method, path, headers: outHeaders }, (res) => {
5632
5638
  const contentType = String(res.headers["content-type"] ?? "");
5633
- if (injectBootstrap && this.e2eKey !== null && res.statusCode === 200 && /^text\/html\b/i.test(contentType)) {
5639
+ if (wantsDocument && res.statusCode === 200 && /^text\/html\b/i.test(contentType)) {
5634
5640
  const chunks = [];
5635
5641
  res.on("data", (c) => chunks.push(c));
5636
5642
  res.on("end", () => {
5637
- const html = injectE2EBootstrap(Buffer.concat(chunks).toString("utf8"), { salt: this.e2eSalt, device: this.deviceId });
5643
+ let html = credentialManifestLinks(Buffer.concat(chunks).toString("utf8"));
5644
+ if (this.e2eKey !== null)
5645
+ html = injectE2EBootstrap(html, { salt: this.e2eSalt, device: this.deviceId });
5638
5646
  const body = Buffer.from(html, "utf8");
5639
5647
  const resHeaders = filterHeaders(headerListFromRaw(res.rawHeaders), /* @__PURE__ */ new Set([...HOP_BY_HOP, "content-length", "content-encoding"]));
5640
5648
  resHeaders.push(["content-length", String(body.length)]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dshn/agent",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Forward a local dsh web service to the public internet over ds.hn (bundled).",
5
5
  "keywords": [
6
6
  "dsh",