ARES - authorized red-team engagement automation with dashboard, campaign scope, module orchestration, OPSEC controls, encrypted vault, and reporting.
Python active-directorycloud-securitydefensive-validationfastapigood-first-issuemitre-attackopsecreactred-teamreportingsecurity
fix(cli): configure local dev browser origin in dashboard dev and setup (fixes #54)
Mafifrizi8bc3763eba28
diff --git a/.env.example b/.env.exampleindex a65ec3d..072aae1 100644--- a/.env.example+++ b/.env.example@@ -8,10 +8,12 @@ARES_SECRET_KEY=CHANGE_ME_USE_openssl_rand_-hex_32ARES_API_HOST=127.0.0.1ARES_API_PORT=8080-ARES_DEBUG=false-# Browser authentication is same-origin only. Production requires one exact-# HTTPS origin; do not use a wildcard, multiple origins, or a path.-ARES_BROWSER_ORIGIN=https://ares.example.invalid+ARES_DEBUG=true+# Browser authentication is same-origin only.+# For local dev / quickstart (ARES_DEBUG=true), leave blank to default to http://127.0.0.1:5173.+# For production (ARES_DEBUG=false), set this to your exact HTTPS origin (e.g. https://ares.corp.local)+# and ensure that host is included in ARES_TRUSTED_HOSTS below.+ARES_BROWSER_ORIGIN=# JWT Algorithm# HS256 (default, symmetric): sign + verify with ARES_SECRET_KEY - suitable for single-servicediff --git a/ares/cli/typer_main.py b/ares/cli/typer_main.pyindex e37c755..24eb854 100644--- a/ares/cli/typer_main.py+++ b/ares/cli/typer_main.py@@ -1645,6 +1645,20 @@ def doctor(except Exception as exc:check("Settings loadable", "warn", str(exc)[:60])+ # Browser session policy+ try:+ from ares.core.browser_sessions import build_browser_session_policy+ from ares.core.config import get_settings+ _s = get_settings()+ _policy = build_browser_session_policy(_s)+ check("Browser session policy", "ok", f"{_policy.origin} (debug={_policy.debug})")+ except Exception as exc:+ check(+ "Browser session policy",+ "warn",+ f"{exc} - fix: set ARES_DEBUG=true for local dev or set valid HTTPS ARES_BROWSER_ORIGIN matching ARES_TRUSTED_HOSTS",+ )+# Summaryconsole.print()total = ok + warn + fail@@ -1855,8 +1869,12 @@ def _start_dashboard_process(*,popen_factory: Callable[..., subprocess.Popen] = subprocess.Popen,os_name: str | None = None,+ env: dict[str, str] | None = None,) -> subprocess.Popen:console.print(f"[cyan]{label}[/cyan] {' '.join(command)}")+ kwargs: dict[str, object] = dict(_popen_kwargs(os_name))+ if env is not None:+ kwargs["env"] = envreturn popen_factory(command,cwd=str(cwd),@@ -1865,7 +1883,7 @@ def _start_dashboard_process(stdin=subprocess.DEVNULL,text=True,bufsize=1,- **_popen_kwargs(os_name),+ **kwargs,)@@ -2054,12 +2072,18 @@ def _run_dashboard_dev(previous_signal_handlers = _install_dashboard_signal_handlers()try:+ backend_env = dict(os.environ)+ backend_env["ARES_DEBUG"] = "true"+ backend_env["ARES_BROWSER_ORIGIN"] = f"http://{ui_host}:{ui_port}"+ backend_env["ARES_TRUSTED_HOSTS"] = "localhost,127.0.0.1"+backend_process = _start_dashboard_process("backend",backend_command,root_path,popen_factory=popen_factory,os_name=os_name,+ env=backend_env,)if cleanup_job is not None:cleanup_job.assign(backend_process)@@ -2288,9 +2312,13 @@ def _run_python_setup(enc_val = _extract_env_value(existing, "ARES_ENCRYPTION_KEY")admin_val = _extract_env_value(existing, "ARES_DEFAULT_ADMIN_PASSWORD")+ origin_val = _extract_env_value(existing, "ARES_BROWSER_ORIGIN")+ debug_val = _extract_env_value(existing, "ARES_DEBUG")+has_placeholders = ("CHANGE_ME" in existingor (admin_val is not None and "YOUR_STRONG_ADMIN_PASSWORD_HERE" in admin_val)+ or (origin_val is not None and "example.invalid" in origin_val))missing_critical = (secret_val is None or secret_val == "" or "CHANGE_ME" in secret_val@@ -2315,6 +2343,14 @@ def _run_python_setup(admin_password = _setup_admin_password()updated = _upsert_env_value(updated, "ARES_DEFAULT_ADMIN_PASSWORD", admin_password)+ # Clean placeholder browser origin if pointing to example.invalid+ if origin_val is not None and "example.invalid" in origin_val:+ updated = _upsert_env_value(updated, "ARES_BROWSER_ORIGIN", "")++ # Default ARES_DEBUG to true for local installation if unset or invalid+ if debug_val is None or debug_val == "" or (debug_val.lower() == "false" and (origin_val is None or "example.invalid" in origin_val or origin_val == "")):+ updated = _upsert_env_value(updated, "ARES_DEBUG", "true")+env_path.write_text(updated, encoding="utf-8")if force:@@ -2338,6 +2374,10 @@ def _run_python_setup(template = _upsert_env_value(template, "ARES_SECRET_KEY", secrets.token_hex(32))template = _upsert_env_value(template, "ARES_ENCRYPTION_KEY", _setup_fernet_key())template = _upsert_env_value(template, "ARES_DEFAULT_ADMIN_PASSWORD", admin_password)+ template = _upsert_env_value(template, "ARES_DEBUG", "true")+ origin_in_template = _extract_env_value(template, "ARES_BROWSER_ORIGIN")+ if origin_in_template and "example.invalid" in origin_in_template:+ template = _upsert_env_value(template, "ARES_BROWSER_ORIGIN", "")env_path.write_text(template, encoding="utf-8")console.print(f"[green]OK[/green] .env created at {env_path}")console.print(f"Admin password: {admin_password}")diff --git a/scripts/setup.sh b/scripts/setup.shindex 60c4523..3530b7b 100644--- a/scripts/setup.sh+++ b/scripts/setup.sh@@ -55,6 +55,8 @@ updates = {env_path = Path(".env")lines = env_path.read_text(encoding="utf-8").splitlines()for index, line in enumerate(lines):+ if line.strip().startswith("ARES_BROWSER_ORIGIN=") and "example.invalid" in line:+ lines[index] = "ARES_BROWSER_ORIGIN="for prefix, value in updates.items():if line.strip().startswith(prefix) and ("CHANGE_ME" in line or line.strip() == prefix):lines[index] = valuediff --git a/tests/unit/test_cli_doctor.py b/tests/unit/test_cli_doctor.pyindex 9367916..38b65d2 100644--- a/tests/unit/test_cli_doctor.py+++ b/tests/unit/test_cli_doctor.py@@ -700,3 +700,58 @@ def test_setup_entrypoint_help(monkeypatch, capsys):output = capsys.readouterr().outassert "Usage: ares-setup" in outputassert "--force" in output+++def test_python_setup_cleans_invalid_browser_origin_placeholder(tmp_path, capsys):+ from ares.cli.typer_main import _run_python_setup++ (tmp_path / ".env").write_text(+ "ARES_SECRET_KEY=CHANGE_ME\n"+ "ARES_ENCRYPTION_KEY=CHANGE_ME\n"+ "ARES_DEFAULT_ADMIN_PASSWORD=YOUR_STRONG_ADMIN_PASSWORD_HERE\n"+ "ARES_DEBUG=false\n"+ "ARES_BROWSER_ORIGIN=https://ares.example.invalid\n",+ encoding="utf-8",+ )++ _run_python_setup(root=tmp_path, platform_name="win32", os_name="nt")++ content = (tmp_path / ".env").read_text(encoding="utf-8")+ assert "example.invalid" not in content+ assert "ARES_BROWSER_ORIGIN=" in content+ assert "ARES_DEBUG=true" in content+++def test_doctor_validates_browser_session_policy(monkeypatch, capsys):+ from ares.cli import typer_main+ from ares.core.browser_sessions import BrowserSessionPolicy++ # Test OK path+ called = []+ fake_policy = BrowserSessionPolicy(+ origin="http://127.0.0.1:5173",+ authority="127.0.0.1:5173",+ refresh_cookie_name="ares-dev-refresh",+ csrf_cookie_name="ares-dev-csrf",+ secure=False,+ debug=True,+ )+ monkeypatch.setattr(+ "ares.core.browser_sessions.build_browser_session_policy",+ lambda settings: fake_policy,+ )++ # Invoke doctor check directly or simulate doctor+ # Verify doctor check prints Browser session policy [OK]+ import ares.cli.typer_main as tm+ console_out = []+ monkeypatch.setattr(tm.console, "print", lambda *args, **kwargs: console_out.append(str(args)))++ # Doctor will run checks+ try:+ tm.doctor()+ except Exception:+ pass++ assert any("Browser session policy" in line for line in console_out)+diff --git a/tests/unit/test_dashboard_dev_launcher.py b/tests/unit/test_dashboard_dev_launcher.pyindex 348d4a3..0b8e4d9 100644--- a/tests/unit/test_dashboard_dev_launcher.py+++ b/tests/unit/test_dashboard_dev_launcher.py@@ -502,6 +502,9 @@ def test_dashboard_dev_launches_both_processes_and_cleans_up(monkeypatch, tmp_pa]assert launched[0].kwargs["cwd"] == str(tmp_path)assert launched[1].kwargs["cwd"] == str(tmp_path / "frontend")+ assert launched[0].kwargs["env"]["ARES_DEBUG"] == "true"+ assert launched[0].kwargs["env"]["ARES_BROWSER_ORIGIN"] == "http://127.0.0.1:5173"+ assert launched[0].kwargs["env"]["ARES_TRUSTED_HOSTS"] == "localhost,127.0.0.1"assert opened == []assert all(process.stopped for process in launched)assert [call[0][:2] for call in taskkill_calls] == [