teapot-coding-agent 0.35.26 → 0.35.28

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
@@ -192,6 +192,26 @@ async function main() {
192
192
  }
193
193
  const app = buildApp(master);
194
194
  const server = serveApp(app, config.port, config.host);
195
+ /**
196
+ * Say out loud when the API has no auth, and when it is reachable beyond loopback.
197
+ *
198
+ * The OpenCode advisory (CVE-2026-22812) was not just "a server was open" — it was open and
199
+ * nobody knew. `apiToken()` is empty on a fresh install because the setup wizard sets the
200
+ * password THROUGH the API, so a token cannot be demanded before one exists; the honest response
201
+ * is to make the state visible on every start rather than to pretend it is protected.
202
+ *
203
+ * See docs/security-advisories.md.
204
+ */
205
+ const noAuth = !(process.env.TEAPOT_API_TOKEN || master.config.password);
206
+ const beyondLoopback = !!config.host && config.host !== "127.0.0.1" && config.host !== "localhost";
207
+ if (noAuth) {
208
+ console.error("[teapot] no API token set — /api is open to LOCAL clients. Cross-origin writes are refused, " +
209
+ "but set TEAPOT_API_TOKEN or config.password before exposing this port.");
210
+ if (beyondLoopback) {
211
+ console.error(`[teapot] WARNING: bound to ${config.host} with NO auth — anyone who can reach this port can ` +
212
+ "drive the agents. Set TEAPOT_API_TOKEN or config.password now.");
213
+ }
214
+ }
195
215
  // agent crash isolation: an agent error never escapes its own loop; here we
196
216
  // also make sure the process survives unexpected rejections.
197
217
  process.on("uncaughtException", (err) => {
@@ -130,10 +130,72 @@ export function buildApp(master) {
130
130
  * also accept the query form.
131
131
  */
132
132
  const tokenInQueryOk = (path) => path === "/api/ws" || /^\/api\/agents\/[^/]+\/term$/.test(path);
133
+ /**
134
+ * Requests that a PAGE ON ANOTHER ORIGIN must not be able to make.
135
+ *
136
+ * This is the defence that does not depend on the operator configuring a token, and it closes
137
+ * the browser half of the OpenCode advisory (CVE-2026-22812 / GHSA-vxw4-wv6m-9hhh): their server
138
+ * was unauthenticated AND sent permissive CORS, so any website could drive it. teapot sends no
139
+ * CORS headers — a cross-origin READ is already blocked by the browser — but a cross-origin
140
+ * WRITE is still DELIVERED, and these routes have side effects a website must not trigger:
141
+ *
142
+ * POST /api/agents/:id/prompt → the agent runs the model with tool access
143
+ * POST /api/agents/:id/restart → restart onto a different build
144
+ * PUT /api/config → rewrite the config, including API keys
145
+ * POST /api/update/restart → restart the process
146
+ * POST /api/setup → set the password on a first-run server
147
+ *
148
+ * The check is deliberately structural rather than a header-name list: a browser always sends
149
+ * `Origin` on a cross-origin request (and on every `fetch` it sends `Sec-Fetch-Site`), while a
150
+ * local process — which the OS already isolates from other users — sends neither. So "an Origin
151
+ * that is not this server" is rejected, and a request with no Origin at all (curl, the CLI, the
152
+ * desktop shell) is unaffected.
153
+ *
154
+ * MEASURED threat model, and its limit: this stops a web page. It does NOT stop a local process
155
+ * on the same machine, and it is not meant to — that is what the token and the loopback bind are
156
+ * for. See `docs/security-advisories.md`.
157
+ */
158
+ const sameOrigin = (c) => {
159
+ const origin = c.req.header("origin");
160
+ // no Origin at all: a non-browser client. A browser ALWAYS sets it cross-origin.
161
+ if (origin === undefined)
162
+ return true;
163
+ const host = c.req.header("host") ?? "";
164
+ try {
165
+ const u = new URL(origin);
166
+ if (u.host === host)
167
+ return true;
168
+ }
169
+ catch {
170
+ /* "null" (a sandboxed iframe or a redirect) is never acceptable */
171
+ return false;
172
+ }
173
+ return false;
174
+ };
133
175
  app.use("/api/*", async (c, next) => {
176
+ /**
177
+ * A cross-origin WRITE is refused BEFORE the token check.
178
+ *
179
+ * Order matters: a token-less server (`!want` below) would otherwise hand every cross-origin
180
+ * request straight through, which is exactly the state a first-run install is in.
181
+ */
182
+ const method = c.req.method.toUpperCase();
183
+ if (method !== "GET" && method !== "HEAD" && !sameOrigin(c)) {
184
+ return c.json({ error: "cross-origin request refused — set an API token in settings, or call the API from a local client" }, 403);
185
+ }
134
186
  const want = apiToken();
135
- if (!want)
136
- return next(); // nothing configured yet — the API stays open
187
+ /**
188
+ * With no token configured the API is still open to LOCAL clients, but it now says so loudly.
189
+ *
190
+ * Opening it is a real decision: the first-run wizard sets the password through
191
+ * `/api/setup`, so the server cannot demand a token before one exists. Leaving that silent is
192
+ * how the OpenCode advisory happened — their server was unauthenticated by default and nobody
193
+ * noticed. The header makes the state visible to every client, and the startup banner warns.
194
+ */
195
+ if (!want) {
196
+ c.header("x-teapot-auth", "none");
197
+ return next();
198
+ }
137
199
  const h = c.req.header("authorization");
138
200
  const provided = h?.startsWith("Bearer ") ? h.slice(7) : undefined;
139
201
  if (provided && provided === want)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.35.26",
3
+ "version": "0.35.28",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",