Skip to content

Commit bafd8ac

Browse files
committed
fix(examples): redact tokens with python literal-string replace, not sed
The sed-based redact_log in demo.sh broke when one of the auth tokens contained a character that conflicted with sed's pattern parser ("unterminated substitute pattern" on the Codex JWT). The whole log tail then blanks on failure, hiding the very failure context we're trying to surface. Switch to a python subprocess that takes the tokens via argv and does literal str.replace. No regex, no delimiter games, no truncation. Signed-off-by: Alexander Watson <zredlined@gmail.com>
1 parent 7a9f82a commit bafd8ac

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

  • examples/agent-driven-policy-management

examples/agent-driven-policy-management/demo.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,25 @@ spin_clear() {
120120
# Redact host-side credentials from the agent log tail before printing on
121121
# failure. Codex shouldn't echo the token, but a misbehaving tool call (e.g.,
122122
# `curl -v`) could leak it; sanitize before showing the log.
123+
#
124+
# Uses python's literal `str.replace` rather than sed because tokens
125+
# (especially JWTs) can contain characters that break sed's pattern parser
126+
# — a sed delimiter collision in one of the substitutions blanks the entire
127+
# log tail, hiding the very failure context we're trying to surface.
123128
redact_log() {
124-
local replacement='[redacted]'
125-
sed \
126-
-e "s|${DEMO_GITHUB_TOKEN:-__no_github_token__}|${replacement}|g" \
127-
-e "s|${CODEX_AUTH_ACCESS_TOKEN:-__no_codex_access__}|${replacement}|g" \
128-
-e "s|${CODEX_AUTH_REFRESH_TOKEN:-__no_codex_refresh__}|${replacement}|g" \
129-
-e "s|${CODEX_AUTH_ACCOUNT_ID:-__no_codex_account__}|${replacement}|g"
129+
python3 - \
130+
"${DEMO_GITHUB_TOKEN:-}" \
131+
"${CODEX_AUTH_ACCESS_TOKEN:-}" \
132+
"${CODEX_AUTH_REFRESH_TOKEN:-}" \
133+
"${CODEX_AUTH_ACCOUNT_ID:-}" \
134+
<<'PY'
135+
import sys
136+
tokens = [t for t in sys.argv[1:] if t]
137+
for line in sys.stdin:
138+
for t in tokens:
139+
line = line.replace(t, "[redacted]")
140+
sys.stdout.write(line)
141+
PY
130142
}
131143

132144
fail() {

0 commit comments

Comments
 (0)