WARDEN-WP-0026 T03: masking display filter (defense-in-depth)
- warden/mask.py: fingerprint()/mask_value() — presence, length, 8-char sha256 prefix; never the value. - proxy.proxy_fetch_fingerprint + `warden access --fingerprint`: masked status view (presence/length/hash) that emits no value, so it bypasses the T02 stdout guard. Lets two parties compare sha256 prefixes to confirm a shared value without seeing it (e.g. rotation landed). - documented as defense-in-depth (raw bao bypasses it) in OperatorAccessAssist.md and the module docstring. - tests: tests/test_mask.py + CLI fingerprint test. 299 pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
04c8b2ab1d
commit
fc0f18aa5c
7 changed files with 150 additions and 3 deletions
33
tests/test_mask.py
Normal file
33
tests/test_mask.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
"""Tests for the masking display filter (WARDEN-WP-0026 T03)."""
|
||||
from warden.mask import fingerprint, mask_value
|
||||
from warden.proxy import ResolvedFetch, proxy_fetch_fingerprint
|
||||
|
||||
|
||||
def test_mask_never_contains_the_value():
|
||||
secret = "ghp_realtokenvalue1234567890abcdef"
|
||||
masked = mask_value(secret)
|
||||
assert secret not in masked
|
||||
assert "hidden" in masked and "len=" in masked and "sha256:" in masked
|
||||
|
||||
|
||||
def test_fingerprint_reports_presence_and_length():
|
||||
fp = fingerprint("abcd")
|
||||
assert fp.present is True and fp.length == 4
|
||||
assert len(fp.sha256_prefix) == 8
|
||||
|
||||
|
||||
def test_absent_value_renders_absent():
|
||||
assert mask_value("") == "‹absent›"
|
||||
assert mask_value(None) == "‹absent›"
|
||||
assert fingerprint(None).present is False
|
||||
|
||||
|
||||
def test_fingerprint_is_stable_and_discriminating():
|
||||
assert fingerprint("token-A").sha256_prefix == fingerprint("token-A").sha256_prefix
|
||||
assert fingerprint("token-A").sha256_prefix != fingerprint("token-B").sha256_prefix
|
||||
|
||||
|
||||
def test_proxy_fingerprint_returns_mask_not_value():
|
||||
fp = proxy_fetch_fingerprint(ResolvedFetch(shell_cmd="printf 'the-secret-value'"))
|
||||
assert fp.present and fp.length == len("the-secret-value")
|
||||
assert "the-secret-value" not in fp.render()
|
||||
|
|
@ -364,3 +364,22 @@ def test_access_fetch_to_nonterminal_stdout_is_refused(tmp_path, monkeypatch):
|
|||
r = runner.invoke(app, ["access", "whynot-design-npm-publish", "--fetch", "--no-policy"])
|
||||
assert r.exit_code == 6
|
||||
assert "sanctioned transport" in r.output.lower() or "refusing" in r.output.lower()
|
||||
|
||||
|
||||
def test_access_fingerprint_masks_and_bypasses_stdout_guard(monkeypatch, tmp_path):
|
||||
"""--fingerprint prints a masked fingerprint (never the value) even to captured stdout."""
|
||||
_proxy_env(monkeypatch, tmp_path)
|
||||
monkeypatch.setenv("VAULT_TOKEN", "caller-token")
|
||||
|
||||
class _Fake:
|
||||
returncode = 0
|
||||
stdout = "top-secret-token-value"
|
||||
|
||||
monkeypatch.setattr("warden.proxy.subprocess.run", lambda *a, **k: _Fake())
|
||||
r = runner.invoke(
|
||||
app,
|
||||
["access", "whynot-design-npm-publish", "--fingerprint", "--no-policy"],
|
||||
)
|
||||
assert r.exit_code == 0
|
||||
assert "top-secret-token-value" not in r.output # value never shown
|
||||
assert "hidden" in r.output and "sha256:" in r.output
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue