teapot-coding-agent 0.35.27 → 0.35.29
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 +20 -0
- package/dist/server/api.js +91 -2
- package/package.json +1 -1
- package/public/assets/{index-CcmKosBW.js → index-BuOwDdBP.js} +5 -5
- package/public/assets/{index-CcmKosBW.js.map → index-BuOwDdBP.js.map} +1 -1
- package/public/assets/index-QlwrdJke.css +1 -0
- package/public/assets/{shiki-CD4t9YNF.js → shiki-BkT0ArEY.js} +2 -2
- package/public/assets/{shiki-CD4t9YNF.js.map → shiki-BkT0ArEY.js.map} +1 -1
- package/public/index.html +2 -2
- package/public/assets/index-DMS0fUWe.css +0 -1
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) => {
|
package/dist/server/api.js
CHANGED
|
@@ -130,10 +130,99 @@ 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
|
+
/**
|
|
164
|
+
* `Sec-Fetch-Site` FIRST — the browser computes it and NOTHING in the request path can rewrite
|
|
165
|
+
* it, unlike `Host`.
|
|
166
|
+
*
|
|
167
|
+
* MEASURED failure this fixes: the operator runs a reverse proxy
|
|
168
|
+
* (`http-proxy`, `changeOrigin: true`) from :7788 to :7789, so the browser's `Origin` says
|
|
169
|
+
* `:7788` while the `Host` reaching teapot says `:7789` — and comparing those two refused every
|
|
170
|
+
* prompt sent through the proxy ("リバースプロキシした先からプロンプトを送信できない").
|
|
171
|
+
*
|
|
172
|
+
* `Sec-Fetch-Site` is `same-origin` on the operator's own page and `cross-site` on an attacker's,
|
|
173
|
+
* regardless of how many proxies sit in between, because it describes the INITIATOR, not the
|
|
174
|
+
* URL. Modern browsers always send it on a state-changing request.
|
|
175
|
+
*/
|
|
176
|
+
const site = c.req.header("sec-fetch-site");
|
|
177
|
+
if (site === "cross-site")
|
|
178
|
+
return false;
|
|
179
|
+
if (site === "same-origin" || site === "none")
|
|
180
|
+
return true;
|
|
181
|
+
/**
|
|
182
|
+
* Older browsers do not send `Sec-Fetch-Site`, so fall back to comparing hosts — using
|
|
183
|
+
* `X-Forwarded-Host` when a proxy supplied one.
|
|
184
|
+
*
|
|
185
|
+
* That is not a bypass: `X-Forwarded-Host` is not a CORS-safelisted header, so a cross-origin
|
|
186
|
+
* page cannot set it without a preflight, and this server approves no preflight. A LOCAL process
|
|
187
|
+
* could forge it — and a local process can already read the config, so it is not the threat this
|
|
188
|
+
* guards.
|
|
189
|
+
*/
|
|
190
|
+
const host = c.req.header("x-forwarded-host") ?? c.req.header("host") ?? "";
|
|
191
|
+
try {
|
|
192
|
+
const u = new URL(origin);
|
|
193
|
+
if (u.host === host)
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
/* "null" (a sandboxed iframe or a redirect) is never acceptable */
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
return false;
|
|
201
|
+
};
|
|
133
202
|
app.use("/api/*", async (c, next) => {
|
|
203
|
+
/**
|
|
204
|
+
* A cross-origin WRITE is refused BEFORE the token check.
|
|
205
|
+
*
|
|
206
|
+
* Order matters: a token-less server (`!want` below) would otherwise hand every cross-origin
|
|
207
|
+
* request straight through, which is exactly the state a first-run install is in.
|
|
208
|
+
*/
|
|
209
|
+
const method = c.req.method.toUpperCase();
|
|
210
|
+
if (method !== "GET" && method !== "HEAD" && !sameOrigin(c)) {
|
|
211
|
+
return c.json({ error: "cross-origin request refused — set an API token in settings, or call the API from a local client" }, 403);
|
|
212
|
+
}
|
|
134
213
|
const want = apiToken();
|
|
135
|
-
|
|
136
|
-
|
|
214
|
+
/**
|
|
215
|
+
* With no token configured the API is still open to LOCAL clients, but it now says so loudly.
|
|
216
|
+
*
|
|
217
|
+
* Opening it is a real decision: the first-run wizard sets the password through
|
|
218
|
+
* `/api/setup`, so the server cannot demand a token before one exists. Leaving that silent is
|
|
219
|
+
* how the OpenCode advisory happened — their server was unauthenticated by default and nobody
|
|
220
|
+
* noticed. The header makes the state visible to every client, and the startup banner warns.
|
|
221
|
+
*/
|
|
222
|
+
if (!want) {
|
|
223
|
+
c.header("x-teapot-auth", "none");
|
|
224
|
+
return next();
|
|
225
|
+
}
|
|
137
226
|
const h = c.req.header("authorization");
|
|
138
227
|
const provided = h?.startsWith("Bearer ") ? h.slice(7) : undefined;
|
|
139
228
|
if (provided && provided === want)
|