fix(conductor): require auth on loopback when --key is set (closes #726) - #727
Open
Kailigithub wants to merge 1 commit into
Open
fix(conductor): require auth on loopback when --key is set (closes #726)#727Kailigithub wants to merge 1 commit into
Kailigithub wants to merge 1 commit into
Conversation
…define#726) RemoteAuth exempted 127.0.0.1 / ::1 callers from the Authorization check, letting any page with a fetch() reach POST /subagent etc. when --key was supplied. With CORSMiddleware(allow_origins=["*"]) still on line 122, that extended to cross-origin pages visited while the conductor runs. Drop the loopback exemption. When --key is set, every caller must send the matching Basic header. Default launch (no --key) keeps historical no-auth behavior so local installs are unaffected. Defer CORSMiddleware origin tightening and --key default to follow-up PRs to keep this change small and focused. Adds frontends/test_issue_726_loopback_auth.py covering 7 cases with the git-stash three-step dance proving test 1 fails on main and passes on the fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #726
frontends/conductor.pyRemoteAuthmiddleware exempts loopback callers(
127.0.0.1,::1) from the auth check whenever--keyis supplied:Combined with
CORSMiddleware(allow_origins=["*"], allow_methods=["*"], allow_headers=["*"])on line 122, this means a visited web page can
fetch('http://127.0.0.1:8900/subagent')and reach
POST /subagent,action=input,/approvalwithout any auth — cross-principaltask dispatch and instruction injection into the user's agent session.
This PR ships the narrow half of the issue's proposed fix: remove the loopback exemption.
When
--keyis supplied, every caller (loopback or not) must send the matchingAuthorization: Basicheader. The default launch (no--key) keeps the historicalno-auth behavior so existing local installs are unaffected.
Change
class RemoteAuth: def __init__(self, app): self.app = app async def __call__(self, scope, receive, send): - remote = (scope.get("client") or ("",))[0] got = dict(scope.get("headers", [])).get(b"authorization", b"") want = b"Basic " + base64.b64encode(f"conductor:{args.key}".encode()) - if args.key and remote not in ("127.0.0.1", "::1") and not secrets.compare_digest(got, want): + if args.key and not secrets.compare_digest(got, want): if scope["type"] == "websocket": return await send({"type": "websocket.close", "code": 1008}) return await PlainTextResponse("Unauthorized", 401, {"WWW-Authenticate": 'Basic realm="Conductor"'})(scope, receive, send) await self.app(scope, receive, send)Verification
Adds
frontends/test_issue_726_loopback_auth.pycovering 7 cases:--keyRun the three-step dance (test fails on
main, passes on the fix branch):Deferred (not in this PR)
Per #726's
Suggested change, two other pieces remain — both are larger diffs andstrictly independent of the loopback exemption:
CORSMiddleware(allow_origins=["*"])at line 122 → explicit origin allow-list--keyhaving no default at line 33 → auto-generate and write to a fileThese are deferred to follow-up PRs to keep this change ≤5 source lines (per the
project's review principles in
CONTRIBUTING.md: "small change radius","net line count: ideally negative or zero for refactors"). Happy to draft the
narrow piece for either as a separate PR if the maintainer concurs with the
split.