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 — [Bug]: OAuth callback server (port 19876) not stopped after authentication completes · Issue #23563 · anomalyco/opencode

[Bug]: OAuth callback server (port 19876) not stopped after authentication completes #23563

New issue
Copy link
New issue
Copy link
Closed
#32245
Closed
[Bug]: OAuth callback server (port 19876) not stopped after authentication completes#23563
#32245
Copy link
Assignees
kitlangton

Description

@hchangjae
hchangjae
opened on Apr 20, 2026
Issue body actions

Description

The OAuth callback server started on port 19876 during authenticate() is never stopped after authentication completes (success or failure). The server remains bound to the port for the lifetime of the process.

This causes cross-instance CSRF errors when multiple opencode TUI instances are running:

  1. Instance A starts, triggers OAuth → callback server starts on port 19876 → auth succeeds → server stays running
  2. Instance B starts, triggers OAuth → ensureRunning() detects port in use → skips server start
  3. Instance B registers its OAuth state in its own process-local pendingAuths Map
  4. Browser callback arrives at port 19876 → handled by Instance A → Instance A's pendingAuths is empty → "Invalid or expired state parameter - potential CSRF attack"

Steps to reproduce

  1. Start opencode TUI (Instance A) with a remote MCP server requiring OAuth
  2. Complete OAuth authentication successfully
  3. Start another opencode TUI (Instance B) in a different terminal
  4. Instance B attempts OAuth for the same MCP server
  5. Browser opens, user approves, but callback fails with CSRF error

Expected behavior

The callback server should stop after authentication completes (when no other OAuth flows are pending), releasing port 19876 for subsequent auth flows.

Actual behavior

The callback server remains running indefinitely. McpOAuthCallback.stop() is never called after authenticate() completes. The only callers of stop() are:

  • Internal reconfiguration in ensureRunning() (when port/path changes)
  • Test cleanup (afterEach)

Proposed fix

Add a stopIfIdle() function that stops the server only when pendingAuths is empty, and call it after authenticate() completes. This is safe for concurrent auth flows — the server only stops when all pending auths are resolved.

OpenCode version

1.14.19

Related issues

  • All MCP oauth flow return potential CSRF attack #9510 (CSRF state mismatch — closed, root cause not fixed)
  • Remote MCP OAuth: browser never opens for re-authentication after session loss #16893 (re-auth browser never opens)

Activity

  1. hchangjae commented on Apr 20, 2026

    @hchangjae
    hchangjae
    on Apr 20, 2026
    Author
    More actions

    Duplicate of #23562

  2. hchangjae
    closed this as completedon Apr 20, 2026
  3. github-actions
    assigned
    rekram1-node
    on Apr 20, 2026
  4. github-actions
    added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 20, 2026
  5. github-actions commented on Apr 20, 2026

    @github-actions
    github-actionsBot
    on Apr 20, 2026 – with GitHub Actions
    Contributor
    More actions

    This issue might be a duplicate of an existing issue. Please check:

    • [Bug]: OAuth callback server not stopped after authentication, causing cross-instance CSRF failures #23562: Same root cause — OAuth callback server (port 19876) not stopped after authenticate() completes, causing cross-instance CSRF failures. Same author, same proposed fix.
  6. hchangjae
    reopened this on Apr 22, 2026
  7. hchangjae
    marked [Bug]: OAuth callback server not stopped after authentication, causing cross-instance CSRF failures #23562 as a duplicate of this issue on Apr 22, 2026
  8. hchangjae commented on Apr 22, 2026

    @hchangjae
    hchangjae
    on Apr 22, 2026
    Author
    More actions

    This issue might be a duplicate of an existing issue. Please check:

    I closed #23562

  9. thdxr
    removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  10. thdxr
    assigned
    kitlangton
    and unassigned
    rekram1-node
    on May 3, 2026
  11. dnl1 commented on May 9, 2026

    @dnl1
    dnl1
    on May 9, 2026
    More actions

    Hey! Any updates on it? I'm facing same issue

  12. rekram1-node
    closed this as completedin #32245on Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @kitlangton
    kitlangton

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.