GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor(server): align pty connect preflight order · anomalyco/opencode@7b39a33

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • opencode/src/server/routes/instance/httpapi/handlers
      • pty.ts
    • server/src/handlers
      • pty.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/server/routes/instance/httpapi/handlers/pty.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/server/routes/instance/httpapi/handlers/pty.ts
+6-7Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ export const ptyConnectHandlers = HttpApiBuilder.group(PtyConnectApi, "pty-conne
184184
params: { ptyID: PtyID }
185185
request: HttpServerRequest.HttpServerRequest
186186
}) {
187+
if (!validOrigin(ctx.request, cors)) return HttpServerResponse.empty({ status: 403 })
188+
189+
const ticket = new URL(ctx.request.url, "http://localhost").searchParams.get(PTY_CONNECT_TICKET_QUERY)
190+
if (ticket && !(yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID, ...(yield* ticketScope) })))
191+
return HttpServerResponse.empty({ status: 403 })
192+
187193
const exists = yield* pty(Pty.Service.use((service) => service.get(ctx.params.ptyID))).pipe(
188194
Effect.map((info) => info.status === "running"),
189195
Effect.catchTag("Pty.NotFoundError", () => Effect.succeed(false)),
@@ -192,13 +198,6 @@ export const ptyConnectHandlers = HttpApiBuilder.group(PtyConnectApi, "pty-conne
192198

193199
const query = Schema.decodeUnknownOption(CursorQuery)(yield* HttpServerRequest.ParsedSearchParams)
194200
if (Option.isNone(query)) return HttpServerResponse.empty({ status: 400 })
195-
const ticket = new URL(ctx.request.url, "http://localhost").searchParams.get(PTY_CONNECT_TICKET_QUERY)
196-
if (ticket) {
197-
const valid = validOrigin(ctx.request, cors)
198-
? yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID, ...(yield* ticketScope) })
199-
: false
200-
if (!valid) return HttpServerResponse.empty({ status: 403 })
201-
}
202201
const parsedCursor = query.value.cursor === undefined ? undefined : Number(query.value.cursor)
203202
const cursor =
204203
parsedCursor !== undefined && Number.isSafeInteger(parsedCursor) && parsedCursor >= -1
Collapse file

‎packages/server/src/handlers/pty.ts‎

Copy file name to clipboardExpand all lines: packages/server/src/handlers/pty.ts
+8-8Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,21 @@ export const PtyHandler = HttpApiBuilder.group(Api, "server.pty", (handlers) =>
140140
.handleRaw(
141141
"pty.connect",
142142
Effect.fn("PtyHandler.connect")(function* (ctx) {
143+
if (!isAllowedRequestOrigin(ctx.request.headers.origin, ctx.request.headers.host, cors))
144+
return HttpServerResponse.empty({ status: 403 })
145+
146+
const url = new URL(ctx.request.url, "http://localhost")
147+
const ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY)
148+
if (ticket && !(yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID, ...(yield* ticketScope) })))
149+
return HttpServerResponse.empty({ status: 403 })
150+
143151
const pty = yield* Pty.Service
144152
const exists = yield* pty.get(ctx.params.ptyID).pipe(
145153
Effect.as(true),
146154
Effect.catchTag("Pty.NotFoundError", () => Effect.succeed(false)),
147155
)
148156
if (!exists) return HttpServerResponse.empty({ status: 404 })
149157

150-
const url = new URL(ctx.request.url, "http://localhost")
151-
const ticket = url.searchParams.get(PTY_CONNECT_TICKET_QUERY)
152-
if (ticket) {
153-
const valid = isAllowedRequestOrigin(ctx.request.headers.origin, ctx.request.headers.host, cors)
154-
? yield* tickets.consume({ ticket, ptyID: ctx.params.ptyID, ...(yield* ticketScope) })
155-
: false
156-
if (!valid) return HttpServerResponse.empty({ status: 403 })
157-
}
158158
const parsedCursor = url.searchParams.get("cursor")
159159
const cursorNumber = parsedCursor === null ? undefined : Number(parsedCursor)
160160
const cursor =

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.