repoburg 1.3.283 → 1.3.285

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 (32) hide show
  1. package/agent-pane/backend/dist/index.js +37 -6
  2. package/agent-pane/backend/dist/server.js +36 -5
  3. package/agent-pane/frontend/dist/assets/{index-CV62NC_4.css → index-BlbOKgb_.css} +1 -1
  4. package/agent-pane/frontend/dist/assets/{index-DipHkV9-.js → index-Db6gAdkM.js} +89 -89
  5. package/agent-pane/frontend/dist/index.html +2 -2
  6. package/backend/dist/src/events/events.gateway.js +2 -3
  7. package/backend/dist/src/events/events.gateway.js.map +1 -1
  8. package/backend/dist/src/main.js +6 -7
  9. package/backend/dist/src/main.js.map +1 -1
  10. package/backend/dist/src/mcp-server/mcp-server.bootstrap.js +4 -0
  11. package/backend/dist/src/mcp-server/mcp-server.bootstrap.js.map +1 -1
  12. package/backend/dist/src/origin-guard.d.ts +5 -0
  13. package/backend/dist/src/origin-guard.js +65 -0
  14. package/backend/dist/src/origin-guard.js.map +1 -0
  15. package/backend/dist/tsconfig.build.tsbuildinfo +1 -1
  16. package/daemon/dist/agentPane.js +6 -1
  17. package/daemon/dist/agentPane.spec.js +50 -7
  18. package/daemon/dist/api/registry.js +1 -9
  19. package/daemon/dist/index.js +5 -9
  20. package/daemon/dist/middleware/checkRemoteAuth.js +2 -1
  21. package/daemon/dist/middleware/checkRemoteAuth.spec.js +10 -0
  22. package/daemon/dist/middleware/originGuard.js +112 -0
  23. package/daemon/dist/middleware/originGuard.spec.js +116 -0
  24. package/daemon/dist/serviceManager.js +1 -0
  25. package/daemon/dist/serviceManager.spec.js +7 -0
  26. package/daemon/instance-entry-keys.js +1 -0
  27. package/package.json +1 -1
  28. package/tabtape/extension/dist/build-info.json +3 -3
  29. package/tabtape/extension/dist/manifest.json +1 -1
  30. package/tabtape/ui/dist/build-info.json +3 -3
  31. package/daemon/dist/middleware/corsOrigin.js +0 -53
  32. package/daemon/dist/middleware/corsOrigin.spec.js +0 -46
@@ -23,6 +23,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
23
23
  const path_1 = __importDefault(require("path"));
24
24
  const os_1 = __importDefault(require("os"));
25
25
  const url_1 = require("url");
26
+ const originGuard_1 = require("./middleware/originGuard");
26
27
  /**
27
28
  * Resolve the agent-pane bundle path ABSOLUTELY (pm2 God-daemon-cwd bug class:
28
29
  * never resolve runtime paths against the process cwd).
@@ -79,7 +80,7 @@ async function loadAgentPane(opts = {}) {
79
80
  // otherwise transpile import() into require() (ESM-incompatible).
80
81
  const dynamicImport = new Function('specifier', 'return import(specifier);');
81
82
  const mod = await dynamicImport((0, url_1.pathToFileURL)(distPath).href);
82
- const { fastify, wss } = await mod.createAgentPaneApp(dbPath);
83
+ const { fastify, wss } = await mod.createAgentPaneApp(dbPath, { allowRequest: originGuard_1.isAllowedRequest });
83
84
  await fastify.ready();
84
85
  console.log(`[agentPane] embedded app ready (db: ${dbPath})`);
85
86
  return {
@@ -124,6 +125,10 @@ function createUpgradeRouter(pane, daemonWss, guard) {
124
125
  socket.write('HTTP/1.1 403 Forbidden\r\n\r\n');
125
126
  socket.destroy();
126
127
  };
128
+ if (!(0, originGuard_1.isAllowedRequest)(req.headers.origin, req.headers.host)) {
129
+ reject();
130
+ return;
131
+ }
127
132
  if (pane && url.startsWith('/vscode')) {
128
133
  if (pane.handleVscodeUpgrade) {
129
134
  pane.handleVscodeUpgrade(req, socket, head);
@@ -13,8 +13,9 @@ const path_1 = __importDefault(require("path"));
13
13
  const agentPane_1 = require("./agentPane");
14
14
  // Stub bundle contents: an ESM module satisfying the embed contract.
15
15
  const STUB_DIST = `
16
- export async function createAgentPaneApp(dbPath) {
16
+ export async function createAgentPaneApp(dbPath, opts) {
17
17
  globalThis.__stubDbPath = dbPath;
18
+ globalThis.__stubOpts = opts;
18
19
  return {
19
20
  fastify: {
20
21
  ready: async () => {},
@@ -105,7 +106,40 @@ describe('createPaneDelegate', () => {
105
106
  expect(routing).toHaveBeenCalledWith(req, res);
106
107
  });
107
108
  });
109
+ function upgradeRequest(url, headers = {}) {
110
+ return { url, headers };
111
+ }
108
112
  describe('createUpgradeRouter', () => {
113
+ it.each(['/ws', '/vscode/', '/'])('refuses a %s upgrade from a foreign page before any handler runs', (url) => {
114
+ const pane = { handleWsUpgrade: jest.fn(), handleVscodeUpgrade: jest.fn() };
115
+ const daemonWss = { handleUpgrade: jest.fn(), emit: jest.fn() };
116
+ const guard = jest.fn(async () => true);
117
+ const route = (0, agentPane_1.createUpgradeRouter)(pane, daemonWss, guard);
118
+ const socket = { write: jest.fn(), destroy: jest.fn() };
119
+ route(upgradeRequest(url, { host: 'localhost:9998', origin: 'https://evil.example' }), socket, Buffer.alloc(0));
120
+ expect(socket.write).toHaveBeenCalledWith(expect.stringContaining('403'));
121
+ expect(socket.destroy).toHaveBeenCalled();
122
+ expect(guard).not.toHaveBeenCalled();
123
+ expect(pane.handleWsUpgrade).not.toHaveBeenCalled();
124
+ expect(pane.handleVscodeUpgrade).not.toHaveBeenCalled();
125
+ expect(daemonWss.handleUpgrade).not.toHaveBeenCalled();
126
+ });
127
+ it('refuses an upgrade with a foreign Host (DNS rebinding)', () => {
128
+ const pane = { handleWsUpgrade: jest.fn() };
129
+ const daemonWss = { handleUpgrade: jest.fn(), emit: jest.fn() };
130
+ const route = (0, agentPane_1.createUpgradeRouter)(pane, daemonWss);
131
+ const socket = { write: jest.fn(), destroy: jest.fn() };
132
+ route(upgradeRequest('/ws', { host: 'evil.example:9998' }), socket, Buffer.alloc(0));
133
+ expect(socket.destroy).toHaveBeenCalled();
134
+ expect(pane.handleWsUpgrade).not.toHaveBeenCalled();
135
+ });
136
+ it('upgrades an allowed page', () => {
137
+ const pane = { handleWsUpgrade: jest.fn() };
138
+ const daemonWss = { handleUpgrade: jest.fn(), emit: jest.fn() };
139
+ const route = (0, agentPane_1.createUpgradeRouter)(pane, daemonWss);
140
+ route(upgradeRequest('/ws', { host: 'localhost:9998', origin: 'https://agent.repoburg.com' }), {}, Buffer.alloc(0));
141
+ expect(pane.handleWsUpgrade).toHaveBeenCalled();
142
+ });
109
143
  it('sends /ws upgrades to the embedded pane', () => {
110
144
  const pane = {
111
145
  routing: jest.fn(),
@@ -115,7 +149,7 @@ describe('createUpgradeRouter', () => {
115
149
  };
116
150
  const daemonWss = { handleUpgrade: jest.fn(), emit: jest.fn() };
117
151
  const route = (0, agentPane_1.createUpgradeRouter)(pane, daemonWss);
118
- route({ url: '/ws' }, {}, Buffer.alloc(0));
152
+ route(upgradeRequest('/ws'), {}, Buffer.alloc(0));
119
153
  expect(pane.handleWsUpgrade).toHaveBeenCalled();
120
154
  expect(daemonWss.handleUpgrade).not.toHaveBeenCalled();
121
155
  });
@@ -126,10 +160,11 @@ describe('createUpgradeRouter', () => {
126
160
  emit: jest.fn(),
127
161
  };
128
162
  const route = (0, agentPane_1.createUpgradeRouter)(pane, daemonWss);
129
- route({ url: '/' }, {}, Buffer.alloc(0));
163
+ const req = upgradeRequest('/');
164
+ route(req, {}, Buffer.alloc(0));
130
165
  expect(pane.handleWsUpgrade).not.toHaveBeenCalled();
131
166
  expect(daemonWss.handleUpgrade).toHaveBeenCalled();
132
- expect(daemonWss.emit).toHaveBeenCalledWith('connection', { daemon: true }, { url: '/' });
167
+ expect(daemonWss.emit).toHaveBeenCalledWith('connection', { daemon: true }, req);
133
168
  });
134
169
  it('falls back to the daemon wss for /ws when the pane is absent', () => {
135
170
  const daemonWss = {
@@ -137,7 +172,7 @@ describe('createUpgradeRouter', () => {
137
172
  emit: jest.fn(),
138
173
  };
139
174
  const route = (0, agentPane_1.createUpgradeRouter)(null, daemonWss);
140
- route({ url: '/ws' }, {}, Buffer.alloc(0));
175
+ route(upgradeRequest('/ws'), {}, Buffer.alloc(0));
141
176
  expect(daemonWss.handleUpgrade).toHaveBeenCalled();
142
177
  });
143
178
  it('sends /vscode upgrades to the embedded pane proxy', () => {
@@ -147,7 +182,7 @@ describe('createUpgradeRouter', () => {
147
182
  };
148
183
  const daemonWss = { handleUpgrade: jest.fn(), emit: jest.fn() };
149
184
  const route = (0, agentPane_1.createUpgradeRouter)(pane, daemonWss);
150
- route({ url: '/vscode/stable-hash/' }, {}, Buffer.alloc(0));
185
+ route(upgradeRequest('/vscode/stable-hash/'), {}, Buffer.alloc(0));
151
186
  expect(pane.handleVscodeUpgrade).toHaveBeenCalled();
152
187
  expect(pane.handleWsUpgrade).not.toHaveBeenCalled();
153
188
  expect(daemonWss.handleUpgrade).not.toHaveBeenCalled();
@@ -157,7 +192,7 @@ describe('createUpgradeRouter', () => {
157
192
  const daemonWss = { handleUpgrade: jest.fn(), emit: jest.fn() };
158
193
  const route = (0, agentPane_1.createUpgradeRouter)(pane, daemonWss);
159
194
  const socket = { write: jest.fn(), destroy: jest.fn() };
160
- route({ url: '/vscode/' }, socket, Buffer.alloc(0));
195
+ route(upgradeRequest('/vscode/'), socket, Buffer.alloc(0));
161
196
  expect(socket.write).toHaveBeenCalledWith(expect.stringContaining('403'));
162
197
  expect(socket.destroy).toHaveBeenCalled();
163
198
  expect(daemonWss.handleUpgrade).not.toHaveBeenCalled();
@@ -190,6 +225,14 @@ describe('loadAgentPane', () => {
190
225
  // A bundle without interrupted-turn resume exposes no starter.
191
226
  expect(pane.startAutoResume).toBeUndefined();
192
227
  });
228
+ it("hands the bundle the daemon's origin policy, tunnels included", async () => {
229
+ const dir = tmpDir('policy');
230
+ const distPath = writeStubDist(path_1.default.join(dir, 'dist'));
231
+ await (0, agentPane_1.loadAgentPane)({ distPath, dbPath: path_1.default.join(dir, 'home', 'data.db'), legacyDbPath: null });
232
+ const { allowRequest } = globalThis.__stubOpts;
233
+ expect(allowRequest('https://workstation.repoburg.com', 'workstation.repoburg.com')).toBe(true);
234
+ expect(allowRequest('https://evil.example', 'localhost:9998')).toBe(false);
235
+ });
193
236
  it('exposes the bundle\'s auto-resume starter for the daemon to call once it listens', async () => {
194
237
  const dir = tmpDir('auto-resume');
195
238
  const distPath = writeStubDist(path_1.default.join(dir, 'dist'), `${STUB_DIST}\nexport function startAutoResume() { globalThis.__stubAutoResume = (globalThis.__stubAutoResume ?? 0) + 1; }\n`);
@@ -1,17 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  const express_1 = require("express");
7
4
  const stateManager_1 = require("../stateManager");
8
- const cors_1 = __importDefault(require("cors"));
9
5
  const router = (0, express_1.Router)();
10
- // Enable CORS for all origins for the GET endpoint.
11
- const corsOptions = {
12
- origin: '*',
13
- };
14
- router.get('/get-active-port', (0, cors_1.default)(corsOptions), (req, res) => {
6
+ router.get('/get-active-port', (req, res) => {
15
7
  const port = stateManager_1.stateManager.getActiveBackendPort();
16
8
  res.json({ port });
17
9
  });
@@ -9,7 +9,7 @@ const http_1 = __importDefault(require("http"));
9
9
  const ws_1 = require("ws");
10
10
  const cors_1 = __importDefault(require("cors"));
11
11
  const serviceManager_1 = require("./serviceManager");
12
- const corsOrigin_1 = require("./middleware/corsOrigin");
12
+ const originGuard_1 = require("./middleware/originGuard");
13
13
  const services_1 = __importDefault(require("./api/services"));
14
14
  const auth_1 = __importDefault(require("./api/auth"));
15
15
  const registry_1 = __importDefault(require("./api/registry"));
@@ -71,14 +71,10 @@ async function main() {
71
71
  }
72
72
  res.status(503).type('text/plain').send('tabtape is not available on this daemon\n');
73
73
  });
74
- // Spec: allowlist only — local tooling (vite, daemon-desktop) and
75
- // *.repoburg.com tunnel hostnames. The previous origin:'*' with
76
- // credentials:true was an open API surface.
77
- app.use((0, cors_1.default)({
78
- origin: corsOrigin_1.corsOrigin,
79
- methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
80
- credentials: true,
81
- }));
74
+ // Everything below is closed to foreign pages: a refused request runs no
75
+ // route. See middleware/originGuard.ts for who is allowed and why.
76
+ app.use(originGuard_1.originGuard);
77
+ app.use((0, cors_1.default)(originGuard_1.corsOptions));
82
78
  // CF Access guard for the embedded pane: when the machine has a tunnel and
83
79
  // Access is configured, /api/* traffic must carry a valid Access JWT.
84
80
  app.use('/api', checkRemoteAuth_1.checkRemoteAuth);
@@ -4,6 +4,7 @@ exports.checkRemoteAuth = checkRemoteAuth;
4
4
  exports.checkRemoteWsAuth = checkRemoteWsAuth;
5
5
  const tunnel_state_1 = require("../remote/tunnel-state");
6
6
  const access_jwt_1 = require("../remote/access-jwt");
7
+ const originGuard_1 = require("./originGuard");
7
8
  /**
8
9
  * Guard for daemon endpoints that must not be reachable by anonymous tunnel
9
10
  * traffic once CF Access is configured.
@@ -19,7 +20,7 @@ const access_jwt_1 = require("../remote/access-jwt");
19
20
  function isLocalHostHeader(host) {
20
21
  if (!host)
21
22
  return true; // no Host header = non-HTTP client tooling
22
- return host.startsWith('localhost') || host.startsWith('127.0.0.1') || host.startsWith('0.0.0.0');
23
+ return (0, originGuard_1.isLoopbackHost)(host);
23
24
  }
24
25
  async function checkRemoteAuth(req, res, next) {
25
26
  const state = (0, tunnel_state_1.loadTunnelState)();
@@ -46,6 +46,16 @@ describe('checkRemoteAuth (HTTP)', () => {
46
46
  }
47
47
  expect(mockedVerify).not.toHaveBeenCalled();
48
48
  });
49
+ it('does not take a lookalike Host for a local one', async () => {
50
+ mockedLoad.mockReturnValue(PINNED_STATE);
51
+ for (const host of ['localhost.evil.com', '127.0.0.1.evil.com:9998', '0.0.0.0.evil.com']) {
52
+ const res = makeRes();
53
+ const next = jest.fn();
54
+ await (0, checkRemoteAuth_1.checkRemoteAuth)(makeReq({ host }), res, next);
55
+ expect(res.status).toHaveBeenCalledWith(401);
56
+ expect(next).not.toHaveBeenCalled();
57
+ }
58
+ });
49
59
  it('requires an Access assertion for tunnel-host requests when configured', async () => {
50
60
  mockedLoad.mockReturnValue(PINNED_STATE);
51
61
  const res = makeRes();
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.corsOptions = void 0;
4
+ exports.isLoopbackHost = isLoopbackHost;
5
+ exports.isAllowedRequest = isAllowedRequest;
6
+ exports.originGuard = originGuard;
7
+ exports.setExtraOriginsForTest = setExtraOriginsForTest;
8
+ /**
9
+ * Which browser pages may talk to this daemon.
10
+ *
11
+ * The loopback binding does not keep web pages out: a browser sends any page's
12
+ * requests to localhost, and the pane API behind this port runs code on the
13
+ * machine. CORS alone cannot stop that (it only hides the response, the request
14
+ * still runs) and WebSockets have no same-origin policy at all. So this check
15
+ * runs before every route and upgrade and refuses the request outright.
16
+ *
17
+ * Allowed Origin:
18
+ * - none: same-origin GETs, curl, CLIs, Node clients
19
+ * - http(s) on a loopback hostname, any port: vite, local tools, the Mac app
20
+ * - https://agent.repoburg.com and https://app.repoburg.com: the public
21
+ * frontends that call the visitor's own daemon
22
+ * - https://<mahlas>.repoburg.com on ITS OWN tunnel hostname only: anyone can
23
+ * own a mahlas, so such a page must not reach somebody else's daemon
24
+ * - chrome-extension://: Ask Repoburg is sideloaded, its id is not fixed
25
+ * - REPOBURG_ALLOWED_ORIGINS (comma-separated)
26
+ *
27
+ * `null` is refused: any site can send it from a sandboxed iframe, and mini
28
+ * apps and agent HTML (opaque origins too) reach the API through the host.
29
+ *
30
+ * Allowed Host: loopback names, *.repoburg.com and the hosts of
31
+ * REPOBURG_ALLOWED_ORIGINS. A site that rebinds its own domain to 127.0.0.1
32
+ * is same-origin and sends no Origin on GET, but Host still names that domain.
33
+ */
34
+ const LOOPBACK_HOSTNAMES = new Set(['localhost', '127.0.0.1', '0.0.0.0', '[::1]']);
35
+ const PUBLIC_FRONTENDS = new Set(['https://agent.repoburg.com', 'https://app.repoburg.com']);
36
+ const TUNNEL_SUFFIX = '.repoburg.com';
37
+ const extraOrigins = (process.env.REPOBURG_ALLOWED_ORIGINS ?? '')
38
+ .split(',')
39
+ .map((value) => value.trim())
40
+ .filter(Boolean);
41
+ function parseUrl(value) {
42
+ try {
43
+ return new URL(value);
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ /** The hostname of a Host header: lowercase, without the port. */
50
+ function hostnameOf(host) {
51
+ return parseUrl(`http://${host}`)?.hostname ?? null;
52
+ }
53
+ /** Exact match: `localhost.evil.com` is not loopback. */
54
+ function isLoopbackHost(host) {
55
+ return LOOPBACK_HOSTNAMES.has(hostnameOf(host) ?? '');
56
+ }
57
+ function isAllowedHost(host) {
58
+ const hostname = hostnameOf(host);
59
+ if (hostname === null)
60
+ return false;
61
+ return (LOOPBACK_HOSTNAMES.has(hostname) ||
62
+ hostname.endsWith(TUNNEL_SUFFIX) ||
63
+ extraOrigins.some((origin) => parseUrl(origin)?.hostname === hostname));
64
+ }
65
+ function isAllowedOrigin(origin, host) {
66
+ if (PUBLIC_FRONTENDS.has(origin) || extraOrigins.includes(origin))
67
+ return true;
68
+ const url = parseUrl(origin);
69
+ if (!url)
70
+ return false;
71
+ if (url.protocol === 'chrome-extension:')
72
+ return true;
73
+ if (url.protocol !== 'http:' && url.protocol !== 'https:')
74
+ return false;
75
+ if (LOOPBACK_HOSTNAMES.has(url.hostname))
76
+ return true;
77
+ return (url.protocol === 'https:' &&
78
+ url.hostname.endsWith(TUNNEL_SUFFIX) &&
79
+ host !== undefined &&
80
+ url.hostname === hostnameOf(host));
81
+ }
82
+ /** May a request with these headers use the daemon? No Host means HTTP/1.0
83
+ * tooling: a browser always sends one. */
84
+ function isAllowedRequest(origin, host) {
85
+ if (host !== undefined && !isAllowedHost(host))
86
+ return false;
87
+ return origin === undefined || isAllowedOrigin(origin, host);
88
+ }
89
+ /** Express middleware: refuse the request before any route runs. */
90
+ function originGuard(req, res, next) {
91
+ if (isAllowedRequest(req.headers.origin, req.headers.host)) {
92
+ next();
93
+ return;
94
+ }
95
+ res.status(403).json({
96
+ error: 'This origin may not use the Repoburg daemon. Add a trusted one to REPOBURG_ALLOWED_ORIGINS.',
97
+ });
98
+ }
99
+ /** CORS headers follow the same decision, for each request. */
100
+ const corsOptions = (req, callback) => {
101
+ callback(null, {
102
+ origin: isAllowedRequest(req.headers.origin, req.headers.host),
103
+ methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
104
+ credentials: true,
105
+ });
106
+ };
107
+ exports.corsOptions = corsOptions;
108
+ /** Exposed for tests. */
109
+ function setExtraOriginsForTest(origins) {
110
+ extraOrigins.length = 0;
111
+ extraOrigins.push(...origins);
112
+ }
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const originGuard_1 = require("./originGuard");
4
+ const LOCAL_HOST = 'localhost:9998';
5
+ describe('isAllowedRequest', () => {
6
+ afterEach(() => (0, originGuard_1.setExtraOriginsForTest)([]));
7
+ it('allows requests without an Origin header (same-origin GET, curl, CLIs)', () => {
8
+ expect((0, originGuard_1.isAllowedRequest)(undefined, LOCAL_HOST)).toBe(true);
9
+ expect((0, originGuard_1.isAllowedRequest)(undefined, undefined)).toBe(true);
10
+ });
11
+ it('allows loopback pages on any port', () => {
12
+ expect((0, originGuard_1.isAllowedRequest)('http://localhost:3000', LOCAL_HOST)).toBe(true);
13
+ expect((0, originGuard_1.isAllowedRequest)('http://localhost:9998', LOCAL_HOST)).toBe(true);
14
+ expect((0, originGuard_1.isAllowedRequest)('http://127.0.0.1:5173', '127.0.0.1:9998')).toBe(true);
15
+ expect((0, originGuard_1.isAllowedRequest)('http://0.0.0.0:3000', LOCAL_HOST)).toBe(true);
16
+ expect((0, originGuard_1.isAllowedRequest)('http://[::1]:3000', LOCAL_HOST)).toBe(true);
17
+ expect((0, originGuard_1.isAllowedRequest)('https://localhost:3000', LOCAL_HOST)).toBe(true);
18
+ });
19
+ it('allows the public frontends to reach the local daemon', () => {
20
+ expect((0, originGuard_1.isAllowedRequest)('https://agent.repoburg.com', LOCAL_HOST)).toBe(true);
21
+ expect((0, originGuard_1.isAllowedRequest)('https://app.repoburg.com', LOCAL_HOST)).toBe(true);
22
+ expect((0, originGuard_1.isAllowedRequest)('https://agent.repoburg.com', 'workstation.repoburg.com')).toBe(true);
23
+ });
24
+ it('allows a tunnel page on its own hostname', () => {
25
+ expect((0, originGuard_1.isAllowedRequest)('https://workstation.repoburg.com', 'workstation.repoburg.com')).toBe(true);
26
+ expect((0, originGuard_1.isAllowedRequest)('https://a-b.repoburg.com', 'A-B.repoburg.com')).toBe(true);
27
+ });
28
+ it("refuses a tunnel page on anybody else's daemon", () => {
29
+ expect((0, originGuard_1.isAllowedRequest)('https://evil.repoburg.com', LOCAL_HOST)).toBe(false);
30
+ expect((0, originGuard_1.isAllowedRequest)('https://evil.repoburg.com', 'workstation.repoburg.com')).toBe(false);
31
+ });
32
+ it('allows the Chrome extension', () => {
33
+ expect((0, originGuard_1.isAllowedRequest)('chrome-extension://abcdefghijklmnop', LOCAL_HOST)).toBe(true);
34
+ });
35
+ it('refuses unknown origins', () => {
36
+ expect((0, originGuard_1.isAllowedRequest)('https://evil.example.com', LOCAL_HOST)).toBe(false);
37
+ expect((0, originGuard_1.isAllowedRequest)('http://evil.com', LOCAL_HOST)).toBe(false);
38
+ });
39
+ it('refuses null, the origin of sandboxed iframes and file pages', () => {
40
+ expect((0, originGuard_1.isAllowedRequest)('null', LOCAL_HOST)).toBe(false);
41
+ expect((0, originGuard_1.isAllowedRequest)('file://', LOCAL_HOST)).toBe(false);
42
+ });
43
+ it('refuses repoburg.com hostnames over http (tunnels are https)', () => {
44
+ expect((0, originGuard_1.isAllowedRequest)('http://workstation.repoburg.com', 'workstation.repoburg.com')).toBe(false);
45
+ expect((0, originGuard_1.isAllowedRequest)('http://agent.repoburg.com', LOCAL_HOST)).toBe(false);
46
+ });
47
+ it('refuses lookalike origins', () => {
48
+ expect((0, originGuard_1.isAllowedRequest)('https://workstation.repoburg.com.evil.com', LOCAL_HOST)).toBe(false);
49
+ expect((0, originGuard_1.isAllowedRequest)('https://evilrepoburg.com', LOCAL_HOST)).toBe(false);
50
+ expect((0, originGuard_1.isAllowedRequest)('http://localhost.evil.com', LOCAL_HOST)).toBe(false);
51
+ expect((0, originGuard_1.isAllowedRequest)('http://127.0.0.1.nip.io', LOCAL_HOST)).toBe(false);
52
+ });
53
+ it('refuses malformed origins', () => {
54
+ expect((0, originGuard_1.isAllowedRequest)('not a url', LOCAL_HOST)).toBe(false);
55
+ });
56
+ it('refuses foreign Host headers even without Origin (DNS rebinding)', () => {
57
+ expect((0, originGuard_1.isAllowedRequest)(undefined, 'evil.example:9998')).toBe(false);
58
+ expect((0, originGuard_1.isAllowedRequest)(undefined, 'localhost.evil.com:9998')).toBe(false);
59
+ expect((0, originGuard_1.isAllowedRequest)(undefined, 'workstation.repoburg.com.evil.com')).toBe(false);
60
+ expect((0, originGuard_1.isAllowedRequest)('http://localhost:3000', 'evil.example:9998')).toBe(false);
61
+ });
62
+ it('allows extra origins and their hosts from the env list', () => {
63
+ (0, originGuard_1.setExtraOriginsForTest)(['https://staging.example.com']);
64
+ expect((0, originGuard_1.isAllowedRequest)('https://staging.example.com', LOCAL_HOST)).toBe(true);
65
+ expect((0, originGuard_1.isAllowedRequest)('https://staging.example.com', 'staging.example.com')).toBe(true);
66
+ expect((0, originGuard_1.isAllowedRequest)(undefined, 'staging.example.com')).toBe(true);
67
+ expect((0, originGuard_1.isAllowedRequest)('https://other.example.com', LOCAL_HOST)).toBe(false);
68
+ expect((0, originGuard_1.isAllowedRequest)(undefined, 'other.example.com')).toBe(false);
69
+ });
70
+ });
71
+ describe('isLoopbackHost', () => {
72
+ it('matches the hostname exactly, with or without a port', () => {
73
+ expect((0, originGuard_1.isLoopbackHost)('localhost')).toBe(true);
74
+ expect((0, originGuard_1.isLoopbackHost)('LOCALHOST:9998')).toBe(true);
75
+ expect((0, originGuard_1.isLoopbackHost)('127.0.0.1:9998')).toBe(true);
76
+ expect((0, originGuard_1.isLoopbackHost)('[::1]:9998')).toBe(true);
77
+ expect((0, originGuard_1.isLoopbackHost)('localhost.evil.com')).toBe(false);
78
+ expect((0, originGuard_1.isLoopbackHost)('127.0.0.1.evil.com:9998')).toBe(false);
79
+ expect((0, originGuard_1.isLoopbackHost)('0.0.0.0.evil.com')).toBe(false);
80
+ });
81
+ });
82
+ describe('originGuard', () => {
83
+ function run(headers) {
84
+ const next = jest.fn();
85
+ const json = jest.fn();
86
+ const status = jest.fn(() => ({ json }));
87
+ (0, originGuard_1.originGuard)({ headers }, { status }, next);
88
+ return { next, status, json };
89
+ }
90
+ it('lets allowed requests through', () => {
91
+ const { next, status } = run({ host: LOCAL_HOST, origin: 'https://agent.repoburg.com' });
92
+ expect(next).toHaveBeenCalledTimes(1);
93
+ expect(status).not.toHaveBeenCalled();
94
+ });
95
+ it('answers 403 and never reaches a route for a foreign page', () => {
96
+ const { next, status, json } = run({ host: LOCAL_HOST, origin: 'https://evil.example' });
97
+ expect(next).not.toHaveBeenCalled();
98
+ expect(status).toHaveBeenCalledWith(403);
99
+ expect(json).toHaveBeenCalledWith({ error: expect.stringContaining('REPOBURG_ALLOWED_ORIGINS') });
100
+ });
101
+ });
102
+ describe('corsOptions', () => {
103
+ function optionsFor(origin) {
104
+ let options;
105
+ (0, originGuard_1.corsOptions)({ headers: { host: LOCAL_HOST, origin } }, (err, result) => {
106
+ if (err)
107
+ throw err;
108
+ options = result;
109
+ });
110
+ return options;
111
+ }
112
+ it('reflects only allowed origins, so a foreign page never gets CORS headers', () => {
113
+ expect(optionsFor('http://localhost:3000')).toMatchObject({ origin: true, credentials: true });
114
+ expect(optionsFor('https://evil.example')).toMatchObject({ origin: false });
115
+ });
116
+ });
@@ -81,6 +81,7 @@ function instanceEnv(projectPath, name, port) {
81
81
  PORT: String(port),
82
82
  REPOBURG_PROJECT_PATH: projectPath,
83
83
  REPOBURG_INSTANCE_NAME: name,
84
+ REPOBURG_ALLOWED_ORIGINS: process.env.REPOBURG_ALLOWED_ORIGINS,
84
85
  };
85
86
  // Drop keys unset in the caller env — pm2 env is {[key: string]: string}.
86
87
  return Object.fromEntries(Object.entries(base).filter(([, v]) => v !== undefined));
@@ -48,6 +48,13 @@ describe('instanceEnv', () => {
48
48
  expect((0, instanceEntry_1.instanceEntryAllows)(key)).toBe(true);
49
49
  }
50
50
  });
51
+ it("hands the daemon's allowed origins to the instance", () => {
52
+ process.env.REPOBURG_ALLOWED_ORIGINS = 'https://staging.example.com';
53
+ const env = (0, serviceManager_1.instanceEnv)('/w', 'w', 3400);
54
+ delete process.env.REPOBURG_ALLOWED_ORIGINS;
55
+ expect(env.REPOBURG_ALLOWED_ORIGINS).toBe('https://staging.example.com');
56
+ expect((0, instanceEntry_1.instanceEntryAllows)('REPOBURG_ALLOWED_ORIGINS')).toBe(true);
57
+ });
51
58
  });
52
59
  describe('backendStartOptions', () => {
53
60
  it("runs the backend with the daemon's own node, not the first node in PATH", () => {
@@ -18,5 +18,6 @@ module.exports = {
18
18
  'PORT',
19
19
  'REPOBURG_PROJECT_PATH',
20
20
  'REPOBURG_INSTANCE_NAME',
21
+ 'REPOBURG_ALLOWED_ORIGINS',
21
22
  ],
22
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repoburg",
3
- "version": "1.3.283",
3
+ "version": "1.3.285",
4
4
  "description": "A local AI-powered software developer assistant that runs on your own machine.",
5
5
  "author": "Celal Ertug",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "tree": "d64a42e34da47bfa9c700a72af183de7b539d91e",
3
- "commit": "7102f1892b5e12fc2c4957bd72cff2876f833070",
3
+ "commit": "b528357756c84c3a1b745be1642a58aac38a81cc",
4
4
  "dirty": false,
5
- "repoburgVersion": "1.3.283",
6
- "builtAt": "2026-10-31T05:39:51.596Z"
5
+ "repoburgVersion": "1.3.285",
6
+ "builtAt": "2026-10-31T07:59:56.899Z"
7
7
  }
@@ -58,5 +58,5 @@
58
58
  ]
59
59
  }
60
60
  ],
61
- "version_name": "0.6.0 (repoburg 1.3.283, 7102f18)"
61
+ "version_name": "0.6.0 (repoburg 1.3.285, b528357)"
62
62
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "tree": "d64a42e34da47bfa9c700a72af183de7b539d91e",
3
- "commit": "7102f1892b5e12fc2c4957bd72cff2876f833070",
3
+ "commit": "b528357756c84c3a1b745be1642a58aac38a81cc",
4
4
  "dirty": false,
5
- "repoburgVersion": "1.3.283",
6
- "builtAt": "2026-10-31T05:39:51.596Z"
5
+ "repoburgVersion": "1.3.285",
6
+ "builtAt": "2026-10-31T07:59:56.899Z"
7
7
  }
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.corsOrigin = corsOrigin;
4
- exports.setExtraOriginsForTest = setExtraOriginsForTest;
5
- /**
6
- * CORS origin allowlist for the daemon.
7
- *
8
- * Spec: the daemon serves the embedded agent-pane to local tooling
9
- * (vite dev servers, daemon-desktop) and, once a tunnel is provisioned, to
10
- * `*.repoburg.com` machine hostnames. Everything else is rejected — the
11
- * previous `origin: '*'` with `credentials: true` is an open API surface.
12
- *
13
- * Allowed:
14
- * - no Origin header (same-origin / non-browser clients such as curl)
15
- * - http://localhost:<any> and http://127.0.0.1:<any>
16
- * - https://<anything>.repoburg.com (tunnel machine hostnames)
17
- * - extra origins from REPOBURG_ALLOWED_ORIGINS (comma-separated)
18
- */
19
- const REPORG_HOSTNAME_SUFFIX = '.repoburg.com';
20
- const extraOrigins = (process.env.REPOBURG_ALLOWED_ORIGINS ?? '')
21
- .split(',')
22
- .map((value) => value.trim())
23
- .filter(Boolean);
24
- function isLocalOrigin(origin) {
25
- return (origin.protocol === 'http:' &&
26
- (origin.hostname === 'localhost' || origin.hostname === '127.0.0.1'));
27
- }
28
- function isTunnelOrigin(origin) {
29
- return origin.protocol === 'https:' && origin.hostname.endsWith(REPORG_HOSTNAME_SUFFIX);
30
- }
31
- /** CORS origin callback. `false` = do not emit CORS headers for this origin. */
32
- function corsOrigin(origin, callback) {
33
- // Same-origin requests and non-browser clients send no Origin header.
34
- if (origin === undefined) {
35
- callback(null, true);
36
- return;
37
- }
38
- let parsed;
39
- try {
40
- parsed = new URL(origin);
41
- }
42
- catch {
43
- callback(null, false);
44
- return;
45
- }
46
- const allowed = isLocalOrigin(parsed) || isTunnelOrigin(parsed) || extraOrigins.includes(origin);
47
- callback(null, allowed);
48
- }
49
- /** Exposed for tests. */
50
- function setExtraOriginsForTest(origins) {
51
- extraOrigins.length = 0;
52
- extraOrigins.push(...origins);
53
- }
@@ -1,46 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const corsOrigin_1 = require("./corsOrigin");
4
- function evaluate(origin) {
5
- let result = false;
6
- (0, corsOrigin_1.corsOrigin)(origin, (err, allow) => {
7
- if (err)
8
- throw err;
9
- result = !!allow;
10
- });
11
- return result;
12
- }
13
- describe('corsOrigin', () => {
14
- afterEach(() => (0, corsOrigin_1.setExtraOriginsForTest)([]));
15
- it('allows requests without an Origin header (same-origin / curl)', () => {
16
- expect(evaluate(undefined)).toBe(true);
17
- });
18
- it('allows localhost and 127.0.0.1 on any port', () => {
19
- expect(evaluate('http://localhost:3000')).toBe(true);
20
- expect(evaluate('http://localhost:9998')).toBe(true);
21
- expect(evaluate('http://127.0.0.1:5173')).toBe(true);
22
- });
23
- it('allows tunnel machine hostnames under repoburg.com (https only)', () => {
24
- expect(evaluate('https://workstation.repoburg.com')).toBe(true);
25
- expect(evaluate('https://a-b.repoburg.com')).toBe(true);
26
- });
27
- it('rejects unknown origins', () => {
28
- expect(evaluate('https://evil.example.com')).toBe(false);
29
- expect(evaluate('http://evil.com')).toBe(false);
30
- });
31
- it('rejects repoburg.com hostnames over http (tunnels are https)', () => {
32
- expect(evaluate('http://workstation.repoburg.com')).toBe(false);
33
- });
34
- it('rejects lookalike suffixes', () => {
35
- expect(evaluate('https://workstation.repoburg.com.evil.com')).toBe(false);
36
- expect(evaluate('https://evilrepoburg.com')).toBe(false);
37
- });
38
- it('rejects malformed origins', () => {
39
- expect(evaluate('not a url')).toBe(false);
40
- });
41
- it('allows extra origins configured via env list', () => {
42
- (0, corsOrigin_1.setExtraOriginsForTest)(['https://staging.example.com']);
43
- expect(evaluate('https://staging.example.com')).toBe(true);
44
- expect(evaluate('https://other.example.com')).toBe(false);
45
- });
46
- });