Skip to content

The agent that grows with you

fix(dashboard-auth): treat a pasted openssl rand command as an unset basic-auth secret

unsupportedpastels0323a30052d7
diff --git a/plugins/dashboard_auth/basic/__init__.py b/plugins/dashboard_auth/basic/__init__.py
index 199e73178d9..a0423d12462 100644
--- a/plugins/dashboard_auth/basic/__init__.py
+++ b/plugins/dashboard_auth/basic/__init__.py
@@ -192,9 +192,10 @@ def _load_config_basic_auth_section() -> dict:
# Shell syntax that was written to .env/config without being run, e.g. a
-# ``$(openssl rand -base64 32)`` line inside a quoted heredoc. Base64 and hex never
-# contain these, and everyone who copied the same line would share the same key.
-_UNEXPANDED_SHELL_MARKERS = ("$(", "`")
+# ``$(openssl rand -base64 32)`` line inside a quoted heredoc, or the command (or a doc
+# placeholder naming it) pasted in place of its output. Base64 and hex never contain
+# these (nor a space), and everyone who copied the same line would share the same key.
+_UNEXPANDED_SHELL_MARKERS = ("$(", "`", "openssl rand")
def _resolve_secret(cfg_section: dict) -> bytes:
diff --git a/tests/plugins/dashboard_auth/test_basic_secret_shell_text.py b/tests/plugins/dashboard_auth/test_basic_secret_shell_text.py
index b254231f093..6d8af2eada5 100644
--- a/tests/plugins/dashboard_auth/test_basic_secret_shell_text.py
+++ b/tests/plugins/dashboard_auth/test_basic_secret_shell_text.py
@@ -31,7 +31,11 @@ def _clear_basic_env(monkeypatch):
monkeypatch.delenv(var, raising=False)
[email protected]("value", [LITERAL, "`openssl rand -base64 32`", "prefix-$(head -c 32 /dev/urandom)"])
+ LITERAL, "`openssl rand -base64 32`", "prefix-$(head -c 32 /dev/urandom)",
+ # The web-dashboard.md placeholder pasted as-is, a spaced "$ (", and a bare command.
+ "<32+ random bytes; openssl rand -base64 32>", "$ (openssl rand -base64 32)", "openssl rand -hex 32",
+])
def test_env_secret_with_shell_text_is_not_used(monkeypatch, caplog, value):
monkeypatch.setenv("HERMES_DASHBOARD_BASIC_AUTH_SECRET", value)
with caplog.at_level(logging.ERROR, logger=basic.logger.name):