Skip to content

fix(server): port upstream PTY connect route authorization (anomalyco/opencode#58258) - #1615

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1793205780-pty-connect-route-auth
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1793205780-pty-connect-route-auth

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #1614

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

With server auth enabled, a ticketed PTY WebSocket connect skips Basic/token auth so the handler can validate the ticket. That bypass was decided by hasPtyConnectTicketURL(url), a regex over the raw request URL, not by the route Effect actually dispatched, so authorization and routing could disagree about the path. The connect handler also looked the PTY up before checking origin and ticket, so an unauthenticated caller with a junk ticket or foreign Origin got 404 vs 403 and could probe which PTY IDs exist.

Ported from upstream:

  • anomalyco/opencode#58258: both authorization layers (packages/opencode instance HttpApi and packages/server) read HttpRouter.RouteContext and only bypass when route.route.path === PTY_CONNECT_PATH and a ticket query is present. The regex helpers are replaced by a shared PTY_CONNECT_PATH route constant used by the endpoint definitions.
  • anomalyco/opencode@7b39a338a0: both connect handlers check origin and consume the ticket before the PTY existence check.

All changes wrapped in altimate_change markers tagged upstream_fix:.

How did you verify your code works?

  • New test in test/server/httpapi-pty.test.ts: a junk ticket and a cross-origin connect to a missing PTY both return 403. It fails on main (404) and passes here.
  • test/upstream/adversarial/upi-server.test.ts updated for the route constant; httpapi-pty, upi-server and httpapi-listen tests pass (22 pass, 8 existing todo).
  • bun run typecheck clean in packages/opencode and packages/server; bun run script/upstream/analyze.ts --markers --base origin/main --strict clean.

Cost side effects

None. No model calls, queries or resources added.

Screenshots / recordings

N/A, no UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR
  • I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"

Written by Devin


Summary by cubic

Fixes PTY WebSocket connect authorization so the ticket bypass is keyed to the matched route rather than a raw-URL regex, and bad-origin or bad-ticket requests now return 403 before revealing whether a PTY exists.

Bug Fixes

  • Both authorization layers (packages/opencode and packages/server) now read HttpRouter.RouteContext and only bypass credential checks when the matched route is the PTY connect path with a ticket query, so authorization cannot disagree with dispatch.
  • The connect handlers now validate origin and consume the ticket before the PTY existence check, so junk tickets and cross-origin requests to missing PTYs get 403 instead of 404.
  • Replaced the regex path helpers with a shared PTY_CONNECT_PATH route constant used by both endpoint definitions.

Written for commit f269fbd. Summary will update on new commits.

View guided diff Turn on auto-fix

@coderabbitai

coderabbitai Bot commented Oct 28, 2026

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 59af72f4-cd25-46aa-86d2-824a87d6fbcd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devin-ai-integration

Copy link
Copy Markdown
Author

CI note: the TypeScript job reports 1 test(s) failed, but I can't open the job log from this session (log storage host isn't reachable), and re-running the job via the API returns 403.

Locally on this branch the PTY/auth suites pass: httpapi-pty, httpapi-v2-pty, httpapi-instance-route-auth, httpapi-listen, httpapi-public-openapi, upi-server and test/upstream. The only local failures are test/cli/run time-budget subprocess tests and skill create scaffold, which fail the same way on main in this environment (no node, timing-sensitive). Could a maintainer re-run the job or say which test failed?

Written by Devin

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PTY connect ticket auth bypass is decided from the raw URL, not the routed path

0 participants