agent-theatre 0.1.2 → 0.1.4

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/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // src/server.ts
2
2
  import { createServer } from "http";
3
- import { existsSync, mkdirSync, readFileSync as readFileSync2, rmSync, writeFileSync } from "fs";
3
+ import { existsSync, mkdirSync, readFileSync as readFileSync2, rmSync, writeFileSync, realpathSync } from "fs";
4
4
  import { homedir as homedir2 } from "os";
5
- import { join as join2, basename as basename2 } from "path";
5
+ import { join as join2, basename as basename2, resolve, sep } from "path";
6
6
  import { Hono } from "hono";
7
7
  import { getRequestListener } from "@hono/node-server";
8
8
  import { WebSocketServer } from "ws";
@@ -1197,6 +1197,8 @@ var Theatre = class {
1197
1197
  } catch {
1198
1198
  return c.body(null, 204);
1199
1199
  }
1200
+ const cwd = typeof payload?.cwd === "string" ? payload.cwd : "";
1201
+ if (cwd && !isWithin(cwd, this.opts.cwd)) return c.body(null, 204);
1200
1202
  const { events } = hookPayloadToEvents(payload, { home: homedir2() });
1201
1203
  if (events.length) this.ingest(events);
1202
1204
  return c.body(null, 204);
@@ -1297,6 +1299,17 @@ var Theatre = class {
1297
1299
  return basename2(this.opts.cwd);
1298
1300
  }
1299
1301
  };
1302
+ function isWithin(dir, root) {
1303
+ const norm3 = (p) => {
1304
+ try {
1305
+ return realpathSync(p);
1306
+ } catch {
1307
+ return resolve(p);
1308
+ }
1309
+ };
1310
+ const d = norm3(dir), r = norm3(root);
1311
+ return d === r || d.startsWith(r.endsWith(sep) ? r : r + sep);
1312
+ }
1300
1313
 
1301
1314
  // src/scan.ts
1302
1315
  import { readdirSync as readdirSync2, readFileSync as readFileSync3, statSync as statSync2 } from "fs";