Agent Zero AI framework
Preserve masked secrets across key casing changes
Alessandro63f0bbf8aaed
diff --git a/helpers/secrets.py b/helpers/secrets.pyindex c8ccb340e..593b9d9bf 100644--- a/helpers/secrets.py+++ b/helpers/secrets.py@@ -483,7 +483,7 @@ class SecretsManager:submitted_lines = self.parse_env_lines(submitted_text)existing_pairs: Dict[str, EnvLine] = {- ln.key: ln+ ln.key.upper(): lnfor ln in existing_linesif ln.type == "pair" and ln.key is not None}@@ -495,7 +495,7 @@ class SecretsManager:merged.append(sub)continue- key = sub.key+ key = sub.key.upper()submitted_val = sub.value or ""if key in existing_pairs and submitted_val == self.MASK_VALUE:diff --git a/helpers/secrets.py.dox.md b/helpers/secrets.py.dox.mdindex 045c6d6cf..20c6815bf 100644--- a/helpers/secrets.py.dox.md+++ b/helpers/secrets.py.dox.md@@ -36,6 +36,7 @@- Helper modules own reusable framework APIs and must preserve public callers unless all callers, tests, and docs are updated together.- The agent-facing `get_secrets_manager` masks and unpacks `API_KEY_*` and login/password credentials from `usr/.env`, every value from the global `usr/secrets.env`, and every value from the active project's `secrets.env`; ordinary runtime settings are not treated as secrets. `get_default_secrets_manager` remains scoped to the single writable `usr/secrets.env` file.- Secret serialization escapes backslashes, double quotes, and carriage returns in double-quoted values so global and project saves preserve their parsed values across disk reads and masked edits. Literal line feeds remain multiline; empty values, comments, and deletion semantics are unchanged.+- Masked secret merging matches keys using the same uppercase convention as parsing and masking, preserving values from lowercase or mixed-case entries. Explicit empty values still clear a secret, and omitted keys are deleted.- Update this file whenever public functions, classes, persistence behavior, path/security assumptions, side effects, or cross-module contracts change.- Observed side-effect areas: filesystem reads, filesystem writes, filesystem deletion, WebSocket state, settings/state persistence, secret handling.- Imported dependency areas include: `dataclasses`, `dotenv.parser`, `helpers`, `helpers.errors`, `helpers.extension`, `io`, `os`, `re`, `threading`, `time`, `typing`.diff --git a/tests/test_secrets.py b/tests/test_secrets.pyindex 020d085ed..945b7e898 100644--- a/tests/test_secrets.py+++ b/tests/test_secrets.py@@ -66,3 +66,24 @@ def test_secret_values_survive_save_and_masked_round_trip(tmp_path, monkeypatch,assert manager.load_secrets() == {"VALUE": value, "EMPTY": ""}assert manager.get_masked_secrets() == maskedassert "# Heading" in masked and "# Inline" in masked++[email protected]("stored_key, submitted_key", [+ ("lower_secret", "LOWER_SECRET"),+ ("Mixed_Secret", "mixed_SECRET"),+ ("UPPER_SECRET", "upper_secret"),+])+def test_masked_secret_merge_uses_case_insensitive_keys(tmp_path, monkeypatch, stored_key, submitted_key):+ monkeypatch.setattr(secrets.SecretsManager, "_instances", {})+ path = tmp_path / "secrets.env"+ path.write_text(f'{stored_key}="original-value" # Keep\nREMOVE="remove-me"\n')+ manager = secrets.SecretsManager.get_instance(str(path))+ masked = manager.get_masked_secrets().replace(stored_key.upper(), submitted_key)++ manager.save_secrets_with_merge(masked)+ assert manager.load_secrets() == {stored_key.upper(): "original-value", "REMOVE": "remove-me"}+ assert "# Keep" in manager.read_secrets_raw()++ manager.save_secrets_with_merge(f'{submitted_key}=""\nNEW="***"\n# Edited')+ assert manager.load_secrets() == {stored_key.upper(): ""}+ assert "# Edited" in manager.read_secrets_raw()