[PR #5882] [MERGED] fix(agents): Beholder corrections 403 for anyone not on loopback #6980

Closed
opened 2026-10-23 04:15:25 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5882
Author: @GetBeholder
Created: 9/6/2026
Status: ✅ Merged
Merged: 9/6/2026
Merged by: @GetBeholder

Base: staging ← Head: fix/beholder-state-403


📝 Commits (3)

  • e2cbd0d agents: let Beholder corrections work when the browser is not on loopback
  • 7dc292f Drive the route in the reachability regression instead of reading its source
  • 8d832b7 Merge remote-tracking branch 'origin/staging' into fix/beholder-state-403

📊 Changes

2 files changed (+199 additions, -3 deletions)

View changed files

📝 packages/server/src/routes/agents.routes.ts (+19 -3)
➕ scripts/regressions/beholder-state-reachable.regression.ts (+180 -0)

📄 Description

Linked issue

Reported in Discord by a user running behind a reverse proxy:

also any manual change just gives a 403, with no errors in the log
I am running with a reverse proxy so i imagine that is the issue
cant even clear all, as it 403s
yeah its totally borked. even disabling the renabling the agent dosent clear the data

Their diagnosis was right on every point.

Why this change

PUT /api/agents/beholder-state/:chatId was behind requirePrivilegedAccess, which admits a request only from loopback or with an X-Admin-Secret header. A browser cannot send that header — the shipped Beholder package contains the string zero times — so behind a reverse proxy, on a LAN, or through a tunnel, every slot correction and the entire "start over" action was impossible, with no setting an operator could change. Following the error's own advice and setting ADMIN_SECRET would not have helped.

It failed silently at both ends. The gate does not log, so the server said nothing; and the panel's error toast was invisible until beholder 1.3.9, so the UI said nothing either. That is why it was reported as the whole feature being broken rather than one blocked action — and why "disabling and re-enabling the agent doesn't clear the data" followed, since the tracked state lives in the last successful run and the only route that clears it was the one returning 403.

The gate was the wrong tool here. This route writes one chat's own tracked state — the same class of act as editing a message in that chat — and chats.routes.ts guards none of its writes this way (zero uses in the entire file). Sitting next to the genuinely administrative routes in agents.routes.ts, import-policy and import, gave it company it does not keep.

What changed

  • Removed requirePrivilegedAccess from that one route, with the reasoning recorded inline so it is not reintroduced by someone tidying up an inconsistency.
  • Added scripts/regressions/beholder-state-reachable.regression.ts.

Unchanged, and what protects the route instead:

  • the app-wide Basic Auth hook registered in app.ts, which every route in the product sits behind;
  • the rate limit already configured on the route;
  • normalizeBeholderState, which refuses a malformed body rather than letting it reach the state the next prompt is built from.

import-policy and import keep their gate, and the regression asserts that too — the point is that this route was miscategorised, not that the gate is wrong.

Verification

Reproduced against a real server, authenticated, from a non-loopback address (192.168.x.x, which is what a reverse proxy looks like to the server):

request result
staging today PUT /api/agents/beholder-state/:chatId 403 ADMIN_SECRET is required for privileged APIs
this branch same request 200, correction persists

Both builds were run from the same working tree with the same data and credentials; the only difference was this change, set aside and restored with git stash to produce the "before" row.

The new regression asserts both halves: that requirePrivilegedAccess still rejects such a request when called (so nobody concludes the gate was harmless and the change unnecessary), and that this route no longer calls it. docker-proxy-auth.regression.ts still passes, which is the check that the gate itself is unmodified. Server typecheck clean.

Note for reviewers

This removes an authorization check, so it deserves a careful read rather than a rubber stamp. The argument is that the check was never reachable for the feature's actual users, protected nothing an authenticated caller could not already do through chats.routes.ts, and cost every non-loopback install the ability to correct its own data. If you would rather keep a check here, the consistent version would be { trustedNetwork: true } plus the client sending credentials — but that still leaves reverse-proxy users out, and the neighbouring GET on the same path has never been guarded at all.

🤖 Generated with Claude Code

https://claude.ai/code/session_01992DGH2exasKGaJiqRnteC

Summary by CodeRabbit

  • Bug Fixes

    • Beholder state corrections can now be submitted from browsers behind reverse proxies, LANs, and tunnels.
    • Requests continue to use application authentication, rate limiting, and request validation.
    • Nearby administrative routes remain protected by privileged access controls.
  • Tests

    • Added regression coverage confirming proxied access and preserving security controls for administrative routes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/5882 **Author:** [@GetBeholder](https://github.com/GetBeholder) **Created:** 9/6/2026 **Status:** ✅ Merged **Merged:** 9/6/2026 **Merged by:** [@GetBeholder](https://github.com/GetBeholder) **Base:** `staging` ← **Head:** `fix/beholder-state-403` --- ### 📝 Commits (3) - [`e2cbd0d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e2cbd0dbf9c02d4e3eae7720e297681a434e0794) agents: let Beholder corrections work when the browser is not on loopback - [`7dc292f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7dc292faedb2dbead23b5269f292cd669bf07223) Drive the route in the reachability regression instead of reading its source - [`8d832b7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8d832b7f18cf5ab229cb2eab131361c24105221c) Merge remote-tracking branch 'origin/staging' into fix/beholder-state-403 ### 📊 Changes **2 files changed** (+199 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/agents.routes.ts` (+19 -3) ➕ `scripts/regressions/beholder-state-reachable.regression.ts` (+180 -0) </details> ### 📄 Description ## Linked issue Reported in Discord by a user running behind a reverse proxy: > also any manual change just gives a 403, with no errors in the log > I am running with a reverse proxy so i imagine that is the issue > cant even clear all, as it 403s > yeah its totally borked. even disabling the renabling the agent dosent clear the data Their diagnosis was right on every point. ## Why this change `PUT /api/agents/beholder-state/:chatId` was behind `requirePrivilegedAccess`, which admits a request only from **loopback** or with an **`X-Admin-Secret`** header. A browser cannot send that header — the shipped Beholder package contains the string zero times — so behind a reverse proxy, on a LAN, or through a tunnel, every slot correction and the entire "start over" action was impossible, with no setting an operator could change. Following the error's own advice and setting `ADMIN_SECRET` would not have helped. It failed silently at both ends. The gate does not log, so the server said nothing; and the panel's error toast was invisible until beholder 1.3.9, so the UI said nothing either. That is why it was reported as the whole feature being broken rather than one blocked action — and why "disabling and re-enabling the agent doesn't clear the data" followed, since the tracked state lives in the last successful run and the only route that clears it was the one returning 403. The gate was the wrong tool here. This route writes **one chat's own tracked state** — the same class of act as editing a message in that chat — and `chats.routes.ts` guards none of its writes this way (zero uses in the entire file). Sitting next to the genuinely administrative routes in `agents.routes.ts`, `import-policy` and `import`, gave it company it does not keep. ## What changed - Removed `requirePrivilegedAccess` from that one route, with the reasoning recorded inline so it is not reintroduced by someone tidying up an inconsistency. - Added `scripts/regressions/beholder-state-reachable.regression.ts`. Unchanged, and what protects the route instead: - the **app-wide Basic Auth hook** registered in `app.ts`, which every route in the product sits behind; - the **rate limit** already configured on the route; - **`normalizeBeholderState`**, which refuses a malformed body rather than letting it reach the state the next prompt is built from. `import-policy` and `import` keep their gate, and the regression asserts that too — the point is that this route was miscategorised, not that the gate is wrong. ## Verification Reproduced against a real server, authenticated, from a non-loopback address (`192.168.x.x`, which is what a reverse proxy looks like to the server): | | request | result | |---|---|---| | **staging today** | `PUT /api/agents/beholder-state/:chatId` | **403** `ADMIN_SECRET is required for privileged APIs` | | **this branch** | same request | **200**, correction persists | Both builds were run from the same working tree with the same data and credentials; the only difference was this change, set aside and restored with `git stash` to produce the "before" row. The new regression asserts both halves: that `requirePrivilegedAccess` **still rejects** such a request when called (so nobody concludes the gate was harmless and the change unnecessary), and that this route no longer calls it. `docker-proxy-auth.regression.ts` still passes, which is the check that the gate itself is unmodified. Server typecheck clean. ## Note for reviewers This removes an authorization check, so it deserves a careful read rather than a rubber stamp. The argument is that the check was never reachable for the feature's actual users, protected nothing an authenticated caller could not already do through `chats.routes.ts`, and cost every non-loopback install the ability to correct its own data. If you would rather keep a check here, the consistent version would be `{ trustedNetwork: true }` plus the client sending credentials — but that still leaves reverse-proxy users out, and the neighbouring GET on the same path has never been guarded at all. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01992DGH2exasKGaJiqRnteC <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Beholder state corrections can now be submitted from browsers behind reverse proxies, LANs, and tunnels. - Requests continue to use application authentication, rate limiting, and request validation. - Nearby administrative routes remain protected by privileged access controls. - **Tests** - Added regression coverage confirming proxied access and preserving security controls for administrative routes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:15:25 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#6980
No description provided.