Skip to content

config: [security] provider.use deny policies are bypassed during config hot-reload — session traffic can silently go to a third-party free provider #52333

Open

Description

@adgjm73458

Description

During a config/plugin hot-reload there is a window where denied providers become selectable despite experimental.policies (deny-all + allowlist). If a prompt lands in that window, the session is silently switched to a denied provider and the request — system prompt, session history, code from tool results — goes to that external provider. The switch persists, so following messages keep using it. This defeats the point of policies as a guarantee that sensitive data never leaves approved infrastructure.

Static enforcement works fine on 2.0.20: opencode models shows only the allowed provider, and policies appear in GET /api/config. The problem only appears during the reload window, triggered by editing the config or a plugin file while a session is active.

Repro (2.0.20, Windows 10):

  1. Policies in opencode.jsonc: deny *, allow only your own provider:

    {
      "experimental": {
        "policies": [
          { "action": "provider.use", "resource": "*", "effect": "deny" },
          { "action": "provider.use", "resource": "my-provider", "effect": "allow" }
        ]
      }
    }
  2. Confirm /models shows only the allowed provider.

  3. While a session runs, save a change to the config or a plugin file (reload fires: provider.updated/model.updated in the server log).

  4. Send a message immediately.

  5. Observed twice: the session model switched to opencode/longcat-2.5-preview-free (free models.dev catalog model, denied by policy), recorded as model-switched in the session DB. No confirmation or error shown.

  6. After a service restart the session fails with ModelUnavailableError: Model unavailable: opencode/longcat-2.5-preview-free until the model is switched back manually.

Expected: enforcement should fail closed during reload — a denied provider must never be resolvable mid-reload, and an implicit model switch should require explicit user confirmation.

Actual: a silent, persistent switch to a denied third-party provider, with the request (system prompt, history, code) routed to it without any user-visible indication.

Related: #34971 and #35104 report policies not being enforced at all on 1.17.13. On 2.0.20 static enforcement works, so this is the remaining hole: the hot-reload window where enforcement is skipped. Filed separately since the symptom and the fix differ (fail-closed model resolution mid-reload).

Plugins

memory-reflex (local), cpp-diagnostics (local)

OpenCode version

2.0.20 (CLI), 2.0.19 (server, desktop-managed)

Steps to reproduce

See numbered steps 1–6 above.

Screenshot and/or share link

N/A — confirmed via server log and session DB.

Operating System

Windows 10 (10.0.19045), win32 x64

Terminal

Windows Terminal / Electron desktop app

Activity

  1. added
    needs:compliance
    on Sep 30, 2026
  2. github-actions commented on Sep 30, 2026

    @github-actions
    Contributor

    This issue doesn’t fully meet our contributing guidelines.

    What needs to be fixed:

    • Please shorten and rewrite the description in your own words. The repeated Summary, Security Impact, and Actual Behavior sections make it an excessively long, repetitive wall of text that reads as AI-generated. A concise summary with the key reproduction steps and expected/actual behavior is enough.

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


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

    • #34971: experimental.policies not enforced for model selection or LLM execution, including denied providers remaining selectable and executable.
    • #35104: provider.use deny policy not removing providers from model selection.

    If you believe this was flagged incorrectly, please let a maintainer know.

  3. removed
    needs:compliance
    on Sep 30, 2026
  4. github-actions commented on Sep 30, 2026

    @github-actions
    Contributor

    Thanks for updating the issue with clear reproduction steps and system details. It now meets the issue template requirements.

  5. vpteruel commented on Oct 4, 2026

    @vpteruel

    Related in impact, different in mechanism — filing for reference, no action needed on this issue.

    #53060 describes the same failure mode reaching a session (traffic silently switched to an unintended third-party free provider, and the switch persists), but arriving through agent frontmatter model: rather than provider.use policies during a hot-reload window.

    Two mechanics there that may be worth folding into the same fix:

    1. The agent registry appears to be resolved once per session and never refreshed, so editing model: in an existing .opencode/agents/*.md never reaches an already-open session.
    2. When the pinned model is missing from the catalog, resolution degrades to a different model on a different provider instead of failing — so provider.use deny policies can end up being the only thing standing between a session and a provider the user never selected.

    The nastiest observed variant: a session dispatched 63 consecutive subagent runs to the fallback provider across three days — including after the config was corrected to a valid model — because the degraded model had been cached and never re-resolved. Nothing is surfaced to the parent agent; the only trace is ModelUnavailableError in the server log.

    If the policy-bypass fix ends up centralizing model resolution, that would presumably cover this path too.

  6. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced the server-side part of this on 2.0.20, and it still happens on the latest dev (f0160a12).

    Setup: your policies (deny *, allow one custom provider), one custom provider with one model, and a trivial local plugin in .opencode/plugins/. Normally GET /api/model returns only the allowed provider's model. While I repeatedly saved the plugin file and polled GET /api/model, a large share of the responses contained only the opencode/* free models, such as opencode/big-pickle, which the policy denies, and not the allowed provider. That fits what you saw: if the client looks at the catalog in that window, the session's model seems to be gone, and it can fall back to the first model in the list.

    What I found:

    • Editing only opencode.jsonc did not trigger it in my test. Editing a plugin file did.
    • I checked this at the server API level. I did not drive the TUI or desktop app all the way to the model-switched entry.

    The script below reproduces it against a local opencode serve.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #52333: provider.use deny policies are not applied to the model catalog
    # while local plugins are reloading. Usage: ./repro.sh [opencode command...]
    # Default command: `opencode` from PATH (tested with @opencode/[email protected]).
    set -u
    OC=("${@:-opencode}")
    D=$(mktemp -d /tmp/opencode/oc52333.XXXX)
    PORT=4211
    export OPENCODE_SERVER_PASSWORD=repro-password
    mkdir -p "$D/.opencode/plugins"
    cat > "$D/opencode.jsonc" <<'EOF'
    {
      "provider": { "my-provider": { "name": "Mine", "npm": "@ai-sdk/openai-compatible",
        "options": { "baseURL": "http://127.0.0.1:9/v1", "apiKey": "x" },
        "models": { "m1": { "name": "M1", "limit": { "context": 8000, "output": 1000 } } } } },
      "experimental": { "policies": [
        { "action": "provider.use", "resource": "*", "effect": "deny" },
        { "action": "provider.use", "resource": "my-provider", "effect": "allow" } ] }
    }
    EOF
    printf '// v=0\nexport default { id: "local.p", setup: async () => ({}) }\n' > "$D/.opencode/plugins/p.ts"
    cd "$D"
    "${OC[@]}" serve --port $PORT > "$D/serve.log" 2>&1 &
    SERVER=$!
    trap 'kill $SERVER 2>/dev/null' EXIT
    for _ in $(seq 60); do curl -s -o /dev/null localhost:$PORT/ && break; sleep 1; done
    sleep 8
    URL="localhost:$PORT/api/model?directory=$D"
    echo "Before reload:"; curl -s -u opencode:$OPENCODE_SERVER_PASSWORD "$URL" | python3 -c 'import sys,json;print(sorted({m["providerID"]+"/"+m["id"] for m in json.load(sys.stdin)["data"]}))'
    # Edit the local plugin file repeatedly (triggers a plugin hot-reload) while polling the catalog.
    ( for i in $(seq 1 10); do echo "// v=$i" >> "$D/.opencode/plugins/p.ts"; sleep 0.7; done ) &
    end=$((SECONDS+9))
    echo "Catalog snapshots during reloads (count, size, providers):"
    while [ $SECONDS -lt $end ]; do
      curl -s -u opencode:$OPENCODE_SERVER_PASSWORD "$URL" | python3 -c 'import sys,json;d=json.load(sys.stdin)["data"];print(len(d),sorted({m["providerID"] for m in d}))' 2>&1
    done | sort | uniq -c
    wait

    Run it: bash repro.sh

  7. paulpierce34 commented on Nov 24, 2026

    @paulpierce34

    Adding analysis from reading the current source (dev, verified 2026-11-24) —
    the failure mode is still present, and the remaining gap is narrower than the
    original report suggests:

    Where enforcement actually happens. provider.use policies are enforced
    only when the provider catalog is rebuilt — ConfigPolicyPlugin removes denied
    providers from the catalog during the reload transform (config/plugin/policy.ts).
    Model.available() performs no policy evaluation at read time; it just filters
    by model.enabled. So every model resolution that happens between a config
    change and the transform completing reads the stale catalog.

    Status of the fix. PR #52682 ("enforce provider.use policies on available
    providers during config reload") proposed the right shape — evaluating
    provider.use inside provider.available() at read time — but it was closed
    unmerged on 2026-10-10. On today's dev, neither model.ts nor
    model-resolver.ts contains any provider.use check, so the read-time
    enforcement the PR proposed is still absent.

    The remaining unfixed vector is the fallback path. Two cases:

    • Pinned session model: now fails closed — if session.model leaves the
      catalog, SessionRunnerModel.select throws ModelUnavailableError instead of
      silently continuing. That half of the original report is fixed.
    • No pinned model: SessionRunnerModel.select falls back through the agent's
      model to ModelResolver.fallback(), which is
      models.available().find(hasPackage && supportsText) — the first model in the
      stale catalog, with no policy check. Under an enabled_providers-style
      deny-all + allowlist, a prompt that lands in the window resolves to a provider
      the policy denies, exactly as reported.

    Permission rules fail closed in the same window (a missing agent yields the
    deny-all default ruleset, and a missing agent errors the request), so provider
    selection is the only fail-open path during reloads.

    The read-time filter from #52682 would close both the selection race and the
    fallback path, and would also make the transform's removal job idempotent
    instead of load-bearing for correctness.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions