Repository navigation
fix(tier3): mask credentials at JSON-escaped line starts in judge evidence and keep RAGAS refusals - #547
Conversation
…evidence RAGAS writes the agent's messages into its prompt as JSON, and tool-call arguments are JSON, so a line break in the quoted text reaches the judge evidence redactor as the two characters "\n". Every credential pattern checks the character before the credential, which is then the letter "n", so a line that starts with an Authorization, Cookie or API-key header, a --token or -u user:password flag, or a key shape such as sk-proj-... was saved in clear in the RAGAS prompt and reply, while the same plain text was masked. _redact_judge_evidence now also redacts the text after each escaped "\n", "\r" or "\t" as the start of a line. The first pass over the whole text is unchanged, so nothing that was masked before is kept. The credential flag patterns also accept a JSON-escaped double-quoted value (--token \"value\"), as the header patterns already did. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…replies A RAGAS judge reply was saved as its text whenever it had any, so a reply with text and a tool call lost the tool-call arguments RAGAS parses. A reply with neither, such as a refusal or a content-filter stop, was saved as an empty "replied" entry, which dropped the refusal text and the finish reason behind the RAGAS failure that follows. The saved reply now holds the text and every tool call's arguments, one per line. A reply with neither is saved as the whole reply body, as an unparseable one already was. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e fixes Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A RAGAS request that repeats an earlier tool call writes the call's JSON arguments as JSON again, so each quote in them reaches the saved prompt after three backslashes. The header separator, the quote after an Authorization scheme, and the quoted-value openers of the credential and user flag patterns accepted at most one backslash, so a quoted `--token "value"`, `--user "user:password"` or a JSON or Python `Authorization`, API-key or `Cookie` header value escaped twice was saved in clear. These places now accept a run of up to eight backslashes before the quote, which covers three levels of escaping and keeps each pattern a bounded literal run. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n-ASCII characters json.dumps writes a tab as the two characters "\t" and, by default, a non-ASCII character as "\uXXXX". A header or flag whose name and value were separated by a tab therefore had the letter t between them, which no separator accepted, and a key, header or flag right after a no-break space, a curly quote or an arrow followed a hex digit, which defeats the word boundary and lookbehind checks. Both were saved in clear in RAGAS prompts and in the tool-call arguments that judge prompts quote. An escaped tab now counts as a blank in the header separator, after an Authorization scheme and between a credential flag and its value. The second redaction pass, which already treats the text after an escaped line break as the start of a line, now does the same after a "\uXXXX" escape, so it covers every JSON writer, not only the template's own. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ped quotes in judge evidence masking Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d line start An escaped tab between a header or flag and its value was only accepted mid-line. At the start of a JSON-escaped line, or right after a \uXXXX escape, the character before the name is the last letter or digit of the escape, so the first pass did not match, and the second pass split the text at the escaped tab and cut the name off from its value. An Authorization, Digest or API-key header value and a --token or -u value were then saved in clear, for example "\nAuthorization:\tBearer <token>" in a RAGAS prompt or "\n--token\t<value>" in a heredoc in tool-call arguments. The Authorization, Digest and API-key header patterns and the two flag patterns now also start right after an escaped \n, \r, \t or \uXXXX, so the first pass over the whole text handles these line starts. The second pass still covers key shapes such as sk-proj-... after an escape. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… keeps The judge evidence section said Cookie header values are masked also in JSON-escaped text. Two escaped shapes are not: a pair after ";" and an escaped tab, and a value after an escaped tab when the Cookie header itself follows an escape such as "\n". Say so, so the page matches what judge_attempts.json holds. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main now masks judge evidence with the shared security finding masker (#445), so its _redact_judge_evidence replaces this branch's judge-only header and flag patterns. The unreleased changelog entry moves out of the 0.9.0 section into Unreleased. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RAGAS 0.4 asks an OpenAI judge for a JSON-mode reply and parses its text, so a reply that has text keeps saving only that text, as before. Only a reply with no text and no tool call, such as a refusal or a content-filter stop, now saves the whole reply body, so the refusal or the finish reason is kept instead of an empty reply. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Judge evidence now goes through the shared finding masker. In JSON-escaped text, such as a RAGAS prompt or a JSON-mode reply, a line break is the two characters \n, so a Cookie header, a credential flag (--token, --password, -token, -u user:password, --cookie) or a key such as sk-proj- that starts the next line follows the letter n. The patterns that need a line start, a space or a word boundary there did not match, and those values were saved in clear. The same held after an escaped tab or non-ASCII character. The text between JSON escapes is now masked line by line before the whole text is masked as before. Masking line by line first also keeps an unquoted value on one line from reading through the escape into the next line's header name. This replaces the judge-only header and flag patterns this branch added before the shared masker landed, with their tests and docs. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
_redact_judge_evidence split the text at JSON escapes and masked each piece on its own before it masked the whole text. A form that runs over an escape was then cut there. The BEGIN line of a private key block was replaced on its own, so the whole-text pass no longer found the block and kept the key body. A continued command (sshpass -p, docker login -p and --password followed by an escaped backslash and line break), a quoted value with an escaped line break or tab, and a value that holds a non-ASCII escape (p\u00e4ss) or a backslash (C:\new) kept the part after the escape. Main masks all of these. The whole text is now masked first, as on main, and the text between "\n", "\r" and "\t" escapes is masked after it as lines of their own. A "\uXXXX" escape no longer splits the text, so a value that holds one and starts a line is masked whole. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main moved the Unreleased changelog entries around. The changelog takes main's file, and this branch's judge evidence masking entry stays under Unreleased > Fixed, after the behavior evidence entries. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rng1995
left a comment
There was a problem hiding this comment.
Reviewed the escape-split line pass and the RAGAS reply-body change. I probed 48 credential shapes in 16 text forms: plain text; JSON escaped once and twice, mid-line and after \n, \r\n and \t; an indent=4 RAGAS prompt; and after \u00a0, \u2028, \f, \b and an escaped quote. No value that main masks is kept here, and 238 of the combinations that main keeps are now masked. The refusal and content-filter reply body goes through the same _redact_judge_evidence and 8,000-character cap as a text reply, and RAGAS only talks to api.openai.com, whose reply fields carry no credentials. Redaction time stays linear: 150 KB of a\n takes 1.1 s here and 0.16 s on main. One P2 below. It is a gap in the shared masker that predates this PR, but the updated docs now say this case is covered.
Tool-call arguments reach every judge prompt as JSON text, so a quoted shell value arrives with escaped quotes (\"...\"). The shared finding masker read that form for credential flag values and assignments, but not for a quoted -u, --user or --proxy-user value, an attached MySQL -p value, a .netrc password, or the elements of an argv list. So `curl -u "admin:SECRET"`, `mysql -p"SECRET"` and `subprocess.run(["tool", "--password", "SECRET"])` in a tool call were saved in clear in judge_attempts.json, on main as well. Those patterns now take the escaped-quote form that credential flag values already use. The argv patterns also take escaped quotes, and "\n" escapes between elements. The -u URL, remote-path and date-format exclusions also see an escaped quote, so `pip install -U \"git+https://...\"`, `rsync -u \"host:/data\"` and `date -u \"+%H:%M\"` stay unmasked. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…older The judge evidence tests added in 6661151 build `curl -u "admin:{_QUOTED_SECRET}"` fixtures, and Gitleaks' curl-auth-user rule reads the f-string placeholder as a basic-auth credential. Allow exactly that placeholder in tests/tier3/test_judge_contracts.py, as the existing entry does for "admin:quoted-user-password". History scans keep 6661151, so the test text itself is left as is. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rng1995
left a comment
There was a problem hiding this comment.
One more P2 on the line pass, from an independent re-review of the current head: a credential flag value at the end of a JSON-escaped line still swallows the next line's flag or header name, so the next line's value is kept.
… a JSON escape An unquoted credential value that ends a line in JSON-escaped text reads the "\n" escape as one escaped character, so the whole-text pass masked the next line's flag or header name together with it: `--password A\n--token B` became `--password <redacted> B`. The line pass then found no name before B, and B was saved in clear in judge_attempts.json. This happened after --token, --password, -u, sshpass -p, docker login -p, aws configure set and npm config set values, inside quoted tool-call arguments and RAGAS prompts, escaped once or twice. _redact_judge_evidence keeps masking the whole text first, so forms that run over an escape stay masked whole. It now also runs the line pass over the lines of the original text, recovers the values it replaced there, and masks each of them wherever it is left in the result. As with configured credentials, only values of at least 8 characters are masked that way, so a shorter value after such a line is still kept; the CHANGELOG and docs say so. Each distinct line is masked once per call. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
aac2a96 masked each value that the line pass recovered from the original lines everywhere in the saved text, as a plain substring. A value that the shared masker flags by mistake (tokenizer_name: MODEL, api_key: Optional[str], password: required) was then erased from the whole prompt, also inside words ($GITHUB_TOKEN_FILE), and values shorter than 8 characters were still kept after a swallowed name. The value is now masked only where the whole pass left it: in the text between a marker and the next escape or marker that equals the rest of its line, from a character where an unquoted value that read on into the line stops, up to the next value masked there or the line end. Values of any length are masked there; other copies of a value are left as before. The lookup is one dict get per marker, so redaction stays linear: the inputs that took 11 to 17 s with aac2a96 take 0.3 to 1.0 s, as on f81cb6a. Tests pin short values, a value two lines after the swallowing value, and ordinary copies of masked values (model name, type annotation, YAML word, variable name, user id) that must stay. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6661151 let the argv login and MySQL context patterns read JSON-escaped quotes, so a \"login\" or \"mysql\" element now gives the attached -pVALUE rule a context in tool-call arguments. That rule failed at the backslash of a bare \"-p\" element and matched again from the bare quote after it, taking the backslash of the closing \" as the value. mkdir -p, ssh -p, git log -p and a prompting mysql -p within 256 characters of such an element became \"-p<redacted>", an invented password with the escape gone. The leftover bare quote also ended the JSON string for the assignment scanner, so a later "password: correct horse ..." was masked to its first word only. The attached -pVALUE element no longer starts at the bare quote of an escaped one. A real \"-pVALUE\" element is still masked. The other argv patterns cannot start there: the flag pattern needs the same quote on both sides of a name without backslashes, and the login, MySQL and sshpass patterns only find context. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
19d5c98 kept the attached -pVALUE rule from starting at any quote with a backslash before it. In an element escaped twice (\\\"-pVALUE\\\"), as when a RAGAS request repeats a tool call's JSON arguments as JSON, every quote has a backslash before it, so the rule could no longer match there and the value was left in clear. 2ef8839 masked it after a mysql or login element in plain, single-quoted or JSON-escaped text, and main after one in plain or single-quoted text. The rule now opens at the start of a backslash run, takes the whole run and its quote, and closes only with the same run and quote. An attached -pVALUE element is masked with its escapes intact at one, two or three escape levels, and a bare -p element (mkdir -p, a prompting mysql -p) is still not read as one at any of them. Signed-off-by: Narendran Raghavan <nraghavan@nvidia.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Follow-up to #429, which saves each RAGAS goal-scorer request and reply in
judge_attempts.json, and to #445, which moved judge evidence onto the shared security finding masker. On main, aCookieheader value, a credential flag value or a key that starts a line in JSON-escaped text, such as a RAGAS prompt or reply, is saved in clear. A RAGAS reply with no text and no tool call, such as a refusal, is saved as an empty reply.Changes
model_dump_json(indent=4)), and a JSON-mode reply quotes it again, so a line break there is the two characters\n. The shared masker'sCookieheader pattern needs a word boundary beforeCookie, and its credential flag and-upatterns need a space or quote before the flag. After\nthey see the lettern, soCookie: session=..., the values of--token,--password,-token,--cookieand-u user:password, and keys such assk-proj-...andghp_...were kept when they started a line. The same held after an escaped tab (\t).Authorizationand API-key header values were already masked there._redact_judge_evidencestill masks the whole text first, exactly as on main. That pass keeps every form that runs over an escape masked whole: a private key block, a continued command such assshpass -p \\\n..., a quoted value with an escaped line break or tab, and a value that holds\u00e4or a backslash. Then it splits the result at each\n,\rand\tescape and masks each piece again, with the shared masker and the key patterns, as a line of its own.\nescape as one escaped character, so the whole-text pass masks the next line's flag or header name with it:--password A\n--token Bbecomes--password <redacted> B, and the line pass then finds no name beforeB. A third step masks the lines of the original text, where the names are still in place, and masks each value they find only where the whole-text pass left it: in the text between a marker and the next escape or marker, when that text is the rest of the value's line from a place where an unquoted value stops (whitespace, a quote, a backtick or a shell operator). Values of any length are masked there. Other copies of the value in the text are not changed.json.dumpstext, socurl -u "admin:..."arrives as-u \"admin:...\". The shared masker now also reads JSON-escaped quotes for the-u/--user/--proxy-uservalue, the MySQL-pvalue, the.netrcpassword and argv lists such as["tool", "--password", "..."], in judge and security finding evidence. URLs (pip install -U \"git+https://...\"), remote paths (rsync -u \"host:/data\") and date formats (date -u \"+%H:%M\") are still kept._ragas_reply_textreturned""for a reply with no text and no tool call, such ascontent: nullwith arefusal, or acontent_filterorlengthstop with no text. Such a reply is now saved as the whole reply body, as an unparseable reply already was, so the refusal text and the finish reason are kept. A reply with text still saves only its text. RAGAS 0.4 asks an OpenAI judge for a JSON-mode reply (response_formatjson_object, no tools) and parses that text, so the saved text is what RAGAS scored.docs/tier3-live-evaluation.mdxdescribes the changes.CHANGELOG.mdhas one Fixed entry under Unreleased.Known trade-offs
\n,\ror\tescape. So at a line start, a quoted value with an escaped line break or tab, a continued command, or a value with a backslash beforen,rort(--token C:\\new..., where\\ncan also be a line break escaped twice) is masked up to that escape, and the rest is kept. Main keeps all of such a value. Anywhere else in a line, the whole-text pass masks it whole, as on main.\uXXXXescape does not start a line, so a credential right after an escaped non-ASCII character (\u00a0--token ...) is kept, as on main. Splitting there would cut values that hold such a character, such as--password p\u00e4ss....DB_PASSWORD=...\nrecall ... later) is kept, as on main. The value is also kept, as on main, when the rest of its line in the result differs from the original line before the next masked value, for example where the whole-text pass masked a configured credential there.--tokenlines about 1.05 s instead of 0.43 s, and 150 KB ofa\nabout 0.15 s instead of 0.12 s. The value lookup is one dictionary lookup per marker, so it stays linear: the review's adversarial inputs (hundreds of values that share a prefix) take 0.3 to 1.0 s, as on f81cb6a, and 736 KB made only of lines whose names are taken (16,000 pairs) takes about 2.1 s, against 0.5 s on main and 1.1 s on f81cb6a, which both keep all 16,000 of those values. It runs once per saved judge attempt.Cookie:\tsession=...,--token\t...), and a quoted value escaped twice (\\\"...\\\"). Both need further changes to the shared security finding masker.Tests
test_judge_evidence_masks_credentials_after_json_escaped_line_breaks: 11 credential shapes after\n,\r\nand\n\t, each escaped once and twice.test_judge_evidence_masks_credentials_after_json_escaped_tabs: aCookieheader,--tokenand-uafter an escaped tab.test_judge_evidence_masks_non_ascii_values_at_json_escaped_line_starts:--password,--token,-uand a quoted--tokenwhose value holds a\u00e4-style escape, at a line start, escaped once and twice.test_judge_evidence_masks_json_escaped_quoted_values:-u,--user=and--proxy-uservalues, MySQL-pand.netrcvalues, and argv lists for--password,--cookie,-u,login -p,sshpass -pand MySQL-p, in JSON-escaped quotes.test_judge_evidence_masks_consecutive_credential_lines_in_json_escaped_text: a--token,AuthorizationorCookievalue on the line after an unquoted--password,-u,--token,sshpass -pordocker login -pvalue, also two lines on and with 3- and 5-character values, in plain text and escaped once and twice.judge_goal_accuracy:test_ragas_evidence_masks_credentials_at_json_escaped_line_starts(anindent=4RAGAS-shaped prompt and a JSON-mode reply) andtest_ragas_evidence_masks_consecutive_credential_lines_in_tool_calls(tool-call arguments escaped twice, which also checks that a model name copied from a maskedtokenizer_name:line stays).test_ragas_reply_without_text_or_tool_calls_is_saved_as_the_reply_body: refusal, content filter and empty text.AuthorizationBearer and Digest,Api-Key) and 5 newtest_judge_evidence_keeps_ordinary_textcases, among them a URL, a remote path, a date format and argv flags in JSON-escaped quotes.test_judge_evidence_keeps_copies_of_line_values_elsewhere: a model name, a type annotation, a YAML word, a variable name and a user ID that a masked line also holds stay on the other lines. All 5 fail on aac2a96, which masked such values everywhere.test_judge_evidence_masks_private_key_blocks_in_json_escaped_text: RSA, EC, OpenSSH, PGP, encrypted and PKCS feat: consolidate OSS runtime, reporting, and provider updates #8 blocks, escaped once, twice and in anindent=4prompt.test_judge_evidence_masks_values_that_hold_escapes: quoted values with a line break or tab,--password,--token,-uand quoted--tokenvalues with a non-ASCII character, and values withab\norC:\new\, in plain text and escaped once and twice.test_judge_evidence_masks_multi_line_tool_call_arguments: a Write call with an OpenSSH key and a continuedsshpasscommand, throughbuild_conversation_summary.test_continued_credentials_never_reach_json_escaped_judge_evidence: the continued-command credential cases, escaped once and twice.test_ragas_evidence_masks_private_key_blocks_in_json_prompts_and_replies.tests/tier3/test_judge_contracts.py,tests/tier3/test_ragas_judge_evidence.pyandtests/tier3/test_security_finding_evidence.py: 659 passed. Against main c19b5d7's source: 56 failed, 603 passed.indent=4RAGAS prompt and escaped tabs, and three-line chains) finds no value that main masks and this branch keeps. Of the 16,142 values main keeps, 11,132 are masked here. The 5,010 that both keep are values with no name before them (echo VALUE) and later copies of a value whose line was masked. This repository's docs and source, cut into 5,618 JSON-escaped 40-line chunks, redact to the same text as on f81cb6a.test_harbor_template_secret_patterns,test_secret_redaction_patterns,test_verifier_python39_syntax,test_log_jwt_redaction,test_github_token_redactionandtests/test_verifier_error_redaction.py): 877 passed.test_grader_validation,test_run_budget,test_private_plugin_security,test_suggestion_groundingandtest_dataset_baseline_fairness: 750 passed. On 3.14, the Harbor runtime modules filtered to judge, redaction, evidence, RAGAS and secret tests: 113 passed;tests/test_oss_packaging.pyandtests/ci/test_secret_redaction.py: 100 passed.ruff checkpasses on the changed Python files.ruff format --checkpasses on them except for one line intests/tier3/test_judge_contracts.pythat this branch does not touch; main's copy of that file reports the same line. The OSS boundary scan passes.git merge-tree --write-treewith main f5bf6c1 is clean.🤖 Generated with Claude Code