Files
hermes-agent/hermes_cli/plugin_host_http_auth.py
funky-xamarin 588f83a273 fix(plugins): preserve route authorization across hosted HTTP requests
(cherry picked from commit 9be287ee25ae513e009b657d97d62e5919ae8a12)
2026-10-18 03:27:52 -07:00

24 lines
852 B
Python

"""Carry route-local admission over the private plugin-host channel, without credentials."""
from fastapi import HTTPException
def admitted_for_sensitive_route(request) -> bool:
"""Preserve the normal guard's decision without changing unguarded plugin routes."""
from hermes_cli.web_server import _require_token
try:
_require_token(request)
except HTTPException as exc:
if exc.status_code != 401:
raise
return False
return True
def with_hosted_admission(app, authenticated):
"""Admission belongs to this IPC request, never to the cached plugin app."""
async def scoped(scope, receive, send):
state = dict(scope.get("state") or {})
state["hosted_http_authenticated"] = authenticated is True
await app({**scope, "state": state}, receive, send)
return scoped