mirror of
https://github.com/BigBodyCobain/Shadowbroker.git
synced 2026-12-05 00:53:37 +01:00
With the dashboard bound to the network (make up-lan), the frontend proxy added the server ADMIN_KEY to every same-origin request and the backend trusted the frontend container as the local operator, so any device on the LAN that opened the dashboard had full control: DMs, contacts, gate keys and settings. The proxy cannot tell the local browser apart from other devices, because Next.js forwards client-supplied X-Forwarded-For verbatim (verified against next start: a remote client sending X-Forwarded-For: 127.0.0.1 reaches the backend as 127.0.0.1). SHADOWBROKER_LAN_MODE=1, set by make up-lan, now makes the proxy inject the admin key only for signed-in admin sessions and stops the backend trusting the frontend container. Loopback tools on the host keep working. For a backend behind nginx/Caddy on the same host, the new opt-in SHADOWBROKER_UNTRUSTED_LOOPBACK=1 makes loopback callers present the key too. Default installs are unchanged. Also compare the admin key in constant time at sign-in, and make the 403 message say how to sign in from another device. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UeX9wuqeVAQNr22zQHWj2H
46 lines
1.6 KiB
Python
46 lines
1.6 KiB
Python
"""LAN mode removes the implicit operator trust given to the frontend container."""
|
|
|
|
import pytest
|
|
from fastapi import HTTPException
|
|
|
|
import auth
|
|
|
|
|
|
class _Req:
|
|
def __init__(self, host, headers=None):
|
|
self.client = type("C", (), {"host": host})()
|
|
self.headers = headers or {}
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _frontend_ip(monkeypatch):
|
|
monkeypatch.setenv("SHADOWBROKER_TRUST_DOCKER_BRIDGE_LOCAL_OPERATOR", "1")
|
|
monkeypatch.setattr(auth, "_resolve_trusted_bridge_ips", lambda: {"172.18.0.5"})
|
|
monkeypatch.setattr(auth, "_current_admin_key", lambda: "k" * 32)
|
|
|
|
|
|
def test_frontend_container_is_trusted_outside_lan_mode(monkeypatch):
|
|
monkeypatch.delenv("SHADOWBROKER_LAN_MODE", raising=False)
|
|
auth.require_local_operator(_Req("172.18.0.5"))
|
|
|
|
|
|
def test_lan_mode_requires_admin_key_from_frontend_container(monkeypatch):
|
|
monkeypatch.setenv("SHADOWBROKER_LAN_MODE", "1")
|
|
with pytest.raises(HTTPException) as exc:
|
|
auth.require_local_operator(_Req("172.18.0.5"))
|
|
assert exc.value.status_code == 403
|
|
# A signed-in browser's session key is forwarded as X-Admin-Key.
|
|
auth.require_local_operator(_Req("172.18.0.5", {"X-Admin-Key": "k" * 32}))
|
|
|
|
|
|
def test_lan_mode_keeps_loopback_tools_working(monkeypatch):
|
|
monkeypatch.setenv("SHADOWBROKER_LAN_MODE", "1")
|
|
auth.require_local_operator(_Req("127.0.0.1"))
|
|
|
|
|
|
def test_untrusted_loopback_requires_admin_key(monkeypatch):
|
|
monkeypatch.setenv("SHADOWBROKER_UNTRUSTED_LOOPBACK", "1")
|
|
with pytest.raises(HTTPException):
|
|
auth.require_local_operator(_Req("127.0.0.1"))
|
|
auth.require_local_operator(_Req("127.0.0.1", {"X-Admin-Key": "k" * 32}))
|