GeezerVison is showing github.com — fix(opencode): strip transfer-encoding in UI proxy and allow public m… · cavanaug/opencode@1251a87
File treeExpand file treeCollapse file tree Open diff view settings routes/instance/httpapi/middleware
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/src/components/terminal.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -482,7 +482,7 @@ export const Terminal = (props: TerminalProps) => { | 482 | 482 | const connectToken = async () => { | 483 | 483 | const result = await client.pty | 484 | 484 | .connectToken( | 485 | | - { ptyID: id }, | | 485 | + { ptyID: id, directory }, | 486 | 486 | { | 487 | 487 | throwOnError: false, | 488 | 488 | headers: { "x-opencode-ticket": "1" }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/middleware.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,6 +13,7 @@ import { compress } from "hono/compress" | 13 | 13 | import * as ServerBackend from "./backend" | 14 | 14 | import { isAllowedCorsOrigin, type CorsOptions } from "./cors" | 15 | 15 | import { isPtyConnectPath, PTY_CONNECT_TICKET_QUERY } from "./shared/pty-ticket" | | 16 | +import { isPublicUIPath } from "./shared/public-ui" | 16 | 17 |
| 17 | 18 | const log = Log.create({ service: "server" }) | 18 | 19 |
| @@ -45,6 +46,7 @@ export const AuthMiddleware: MiddlewareHandler = (c, next) => { | 45 | 46 | if (c.req.method === "OPTIONS") return next() | 46 | 47 | const password = Flag.OPENCODE_SERVER_PASSWORD | 47 | 48 | if (!password) return next() | | 49 | + if (isPublicUIPath(c.req.method, c.req.path)) return next() | 48 | 50 | if (isPtyConnectPath(c.req.path) && c.req.query(PTY_CONNECT_TICKET_QUERY)) return next() | 49 | 51 | const username = Flag.OPENCODE_SERVER_USERNAME ?? "opencode" | 50 | 52 |
| |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/routes/instance/httpapi/middleware/authorization.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,6 +3,7 @@ import { Effect, Encoding, Layer, Redacted } from "effect" | 3 | 3 | import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http" | 4 | 4 | import { HttpApiError, HttpApiMiddleware } from "effect/unstable/httpapi" | 5 | 5 | import { hasPtyConnectTicketURL } from "@/server/shared/pty-ticket" | | 6 | +import { isPublicUIPath } from "@/server/shared/public-ui" | 6 | 7 |
| 7 | 8 | const AUTH_TOKEN_QUERY = "auth_token" | 8 | 9 | const UNAUTHORIZED = 401 | @@ -92,6 +93,7 @@ export const authorizationRouterMiddleware = HttpRouter.middleware()( | 92 | 93 | Effect.gen(function* () { | 93 | 94 | const request = yield* HttpServerRequest.HttpServerRequest | 94 | 95 | const url = new URL(request.url, "http://localhost") | | 96 | + if (isPublicUIPath(request.method, url.pathname)) return yield* effect | 95 | 97 | if (hasPtyConnectTicketURL(url)) return yield* effect | 96 | 98 | return yield* credentialFromURL(url, request).pipe( | 97 | 99 | Effect.flatMap((credential) => validateRawCredential(effect, credential, config)), | |
Collapse file Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +// Static UI assets the browser fetches without app-managed credentials, e.g. | | 2 | +// the manifest link in <head>. These bypass auth so the page can install/render | | 3 | +// the manifest icons even when a server password is configured. | | 4 | +export const PUBLIC_UI_PATHS = new Set<string>([ | | 5 | + "/site.webmanifest", | | 6 | + "/web-app-manifest-192x192.png", | | 7 | + "/web-app-manifest-512x512.png", | | 8 | +]) | | 9 | + | | 10 | +export function isPublicUIPath(method: string, pathname: string) { | | 11 | + return method === "GET" && PUBLIC_UI_PATHS.has(pathname) | | 12 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/server/shared/ui.ts +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,6 +33,7 @@ function proxyResponseHeaders(headers: Record<string, string>) { | 33 | 33 | // transfer metadata makes browsers decode already-decoded assets again. | 34 | 34 | result.delete("content-encoding") | 35 | 35 | result.delete("content-length") | | 36 | + result.delete("transfer-encoding") | 36 | 37 | return result | 37 | 38 | } | 38 | 39 |
| |
|