Skip to content

The agent that grows with you

fix(redact): mask the sign-in in a Webapp link that reaches a transcript

emozilla49591981732e
diff --git a/agent/redact.py b/agent/redact.py
index 245e14e295e..47c59918714 100644
--- a/agent/redact.py
+++ b/agent/redact.py
@@ -559,6 +559,12 @@ _URL_BARE_TOKEN_RE = re.compile(
# JWTs always start with "eyJ" (base64 "{"); 1-, 2- and 3-part forms.
_JWT_RE = re.compile(r"eyJ[A-Za-z0-9_-]{10,}(?:\.[A-Za-z0-9_=-]{4,}){0,2}")
+# Links ``hermes webapp`` prints that sign a browser in as the user: the gateway's browser credential
+# after ``hermes-session=`` and the one-use ticket of a ``/webapp/launch`` link. Both values are
+# URL-safe base64 (43 characters); the 20-character floor leaves placeholders and code (``${token}``).
+_WEBAPP_LINK_CREDENTIAL_RE = re.compile(
+ r"((?<![A-Za-z0-9_-])hermes-session=|/webapp/launch#(?:[^\s#]*?&)?ticket=)[A-Za-z0-9_-]{20,}")
+
# E.164 phone numbers, 7-15 digits; the lookahead rejects hex strings / identifiers.
_SIGNAL_PHONE_RE = re.compile(r"(\+[1-9]\d{6,14})(?![A-Za-z0-9])")
@@ -986,6 +992,11 @@ def redact_sensitive_text(text: str, *, force: bool = False, code_file: bool = F
if "eyJ" in text:
text = _JWT_RE.sub(lambda m: _mask_token(m.group(0)), text)
+ # A Webapp sign-in link signs a browser in as the user, so its credential is masked whatever the
+ # web-URL policy below.
+ if "hermes-session=" in text or "/webapp/launch#" in text:
+ text = _WEBAPP_LINK_CREDENTIAL_RE.sub(lambda m: m.group(1) + "***", text)
+
if redact_url_credentials: # opt-in; known credential shapes in URLs are caught above
# NOTE: Web-URL redaction (query params + userinfo + HTTP access-log request targets) is
# intentionally OFF. Many legitimate workflows pass opaque tokens through query strings — magic-link
diff --git a/tests/agent/test_redact.py b/tests/agent/test_redact.py
index 6742a00cc9d..ea0712372fe 100644
--- a/tests/agent/test_redact.py
+++ b/tests/agent/test_redact.py
@@ -1663,3 +1663,34 @@ class TestRedactForEgress:
from agent import redact as R
monkeypatch.setattr(R, "redact_sensitive_text", lambda *a, **k: (_ for _ in ()).throw(RuntimeError("boom")))
assert R.redact_for_egress("sk-live-0123456789abcdef") == R.REDACTION_UNAVAILABLE
+
+
+class TestWebappLaunchLinks:
+ """``hermes webapp`` prints a link that signs a browser in as the user: one with the gateway's
+ browser credential after ``#hermes-session=`` (what older gateways printed on macOS), or a one-use
+ launch ticket after ``/webapp/launch#ticket=``. Either opens the user's Hermes until it is spent or
+ replaced, so when Hermes runs the command through its terminal tool neither reaches the transcript.
+ The rest of the link stays readable."""
+
+ CREDENTIAL = "Zq7_" + "k3Lm" * 9 + "x9-" # the shape secrets.token_urlsafe(32) prints: 43 characters
+
+ def test_the_browser_credential_in_a_link_is_masked(self):
+ from agent.redact import redact_terminal_output
+
+ link = "http://127.0.0.1:9120/?profile=work#hermes-session=" + self.CREDENTIAL
+ out = redact_terminal_output(f"Open this link in your browser:\n {link}\n", "hermes webapp")
+ assert self.CREDENTIAL not in out
+ assert "http://127.0.0.1:9120/?profile=work#hermes-session=" in out
+
+ def test_a_launch_ticket_is_masked(self):
+ from agent.redact import redact_terminal_output
+
+ link = "http://127.0.0.1:9120/webapp/launch#ticket=" + self.CREDENTIAL + "&query=%3Fprofile%3Dwork"
+ out = redact_terminal_output(f"Open this one-use link:\n {link}\n", "hermes webapp --no-open")
+ assert self.CREDENTIAL not in out
+ assert "http://127.0.0.1:9120/webapp/launch#ticket=" in out and "&query=%3Fprofile%3Dwork" in out
+ assert self.CREDENTIAL not in redact_sensitive_text(link)
+
+ def test_code_that_builds_such_a_link_is_left_alone(self):
+ source = "target.hash = `hermes-session=${token}`\nconst FRAGMENT_KEY = 'hermes-session'\n"
+ assert redact_sensitive_text(source, code_file=True) == source