Skip to content

feat(cli): redact known secrets before trace and eval uploads - #888

Open
xeophon wants to merge 27 commits into
mainfrom
agent/redact-uploads
Open

feat(cli): redact known secrets before trace and eval uploads#888
xeophon wants to merge 27 commits into
mainfrom
agent/redact-uploads

Conversation

@xeophon

@xeophon xeophon commented Sep 2, 2026

Copy link
Copy Markdown
Member

Overview

Replaces #882 with a from-scratch, minimal implementation of the same goal: secrets do not leave the machine on upload. One ~75-line util in the CLI instead of a 973-line preflight module plus SDK changes.

What it does

prime traces upload, prime eval push, and the auto-push after prime eval run replace every known secret value with [REDACTED] before the bytes go out — in the JSONL lines and --context values, in the eval data and --name, and in the auto-push's metadata, metrics, and task type. Known values are:

  • the process environment's credentials: values under credential-like names (KEY|TOKEN|SECRET|PASSWORD|CREDENTIAL|COOKIE|AUTHORIZATION|AUTH|SIGNATURE|SIG|PAT as the name's last word, optionally numbered — compound names are head-final, so HF_TOKEN, X-Api-Key, PGPASSWORD, API_KEY_2 are credentials while TOKEN_URL, COOKIE_DOMAIN, KEY_FILE, SSH_AUTH_SOCK, KEYCLOAK_REALM are not), plus, for any value that is a URL (scheme://host…, never prose), the password (or bare user token) of its userinfo and its credential-named query values (DATABASE_URL, an authenticated HTTP_PROXY, wss://…?token=…); a value that is a JSON object is a mapping too and gets the same rules inside it (DOCKER_AUTH_CONFIG, a service-account blob); 8+ chars
  • the Prime API key
  • --secret <value> or --secret <file with one per line>, repeatable, on traces upload and eval push

Matching is exact, over the serialized JSON text: each JSON string is decoded and then searched again for quoted JSON inside it, recursively, so any escape spelling (\/, uppercase hex, …) at any nesting depth is matched. Only JSON strings are touched, so numbers and structure cannot be corrupted, ordinary text is never rewritten, and a line with no hit is uploaded byte-identical, so content-addressed receipts still replay on rerun. Local files are never modified. The command reports how many occurrences were replaced (.redacted in JSON output).

Deliberately not carried over from #882

  • Shape-based detection (provider key regexes, header/cookie/assignment grammars, OpenAPI and JSON-schema awareness). Every review round grew the pattern set and its false-positive guards (token_usage, oauth, BearerAuth, …). That is a scanner's job: run trufflehog over the file before uploading if you want it. The CLI redacts what it knows, which is also pi-share-hf's position.
  • SDK-level auto-redaction, push_evaluation, exact batching and async upload rewrites, the fingerprint API in prime-evals. The SDKs stay transports; redaction is a CLI concern, so no prime-evals release is needed and verifiers keeps no dependency on it.
  • Temp-file staging for traces upload: TracesClient.upload_lines already exists, so lines are redacted in a generator on the way to the batcher.

Companion

PrimeIntellect-ai/verifiers#2508 handles what only verifiers knows (client headers, harness env, resolved API keys, per-rollout tokens) with the same redactor. The two copies are intentionally independent so neither repo waits on the other's release.

Tests

test_redact.py covers escaping at several depths (including \/ and uppercase hex), the number/structure guarantee, and the secret sources. test_traces_command.py and test_eval_push.py check the commands end to end through Typer with stubbed clients: bytes untouched when nothing matches, secrets from env / API key / --secret literal / --secret file / --context / --name gone, local files unchanged.


Note

Medium Risk
Changes what leaves the machine on upload (security-sensitive); redaction is best-effort on known values only, so missed secrets or edge-case false negatives remain possible despite extensive tests.

Overview
Adds a small redact helper and wires it into prime traces upload, prime eval push, and the post-run eval auto-push so outbound payloads are scrubbed before they hit the platform.

Secret sources are credential-like env vars (plus URL/JSON-nested credentials), the Prime API key, and repeatable --secret (literal or one-per-line file). Matches are exact inside JSON strings only (including nested quoted JSON), replaced with [REDACTED]; local files stay unchanged. Commands print a yellow notice and JSON output includes redacted counts where applicable.

Traces now stream through upload_lines with per-line redaction instead of uploading the raw file bytes unchanged. Eval push redacts loaded eval data and CLI fields such as run_id and name so secrets in identifiers cannot leak.

Reviewed by Cursor Bugbot for commit bf4475f. Bugbot is set up for automated code reviews on this repo. Configure here.

`prime traces upload`, `prime eval push`, and the auto-push after `prime eval
run` replace every known secret value with `[REDACTED]` inside JSON strings
before the bytes leave the machine. Known values are credential-named
environment variables, the Prime API key, and `--secret` arguments (a literal
or a file with one per line). Matching is exact over the serialized JSON, in
every JSON spelling, inside strings only; a line with no hit is uploaded
byte-identical. Local files are never modified.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-02T17:33:41.464648Z bf4475f New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42b9dcbfcc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/commands/traces.py Outdated
Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated
Comment thread packages/prime/src/prime_cli/utils/eval_push.py Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 42b9dcb. Configure here.

Comment thread transfer-bulk-failures.jsonl Outdated
The redactor decodes each JSON string before matching, so every valid escape
spelling of the outer string is covered and one more nesting level of quoted
JSON documents is reached; strings without a hit keep their exact bytes.
`prime traces upload` also redacts `--context` values, and the auto-push after
`prime eval run` redacts metrics and task_type with the rest of the payload.
Drops a test artifact that was swept into the first commit.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad008f3212

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated
Comment thread packages/prime/src/prime_cli/commands/evals.py Outdated
The redactor no longer enumerates escape spellings: each JSON string is decoded
and then searched again for quoted JSON inside it, so any escape (including
`\/` and uppercase hex) at any nesting depth is matched, and the code shrinks.
`prime eval push --name` is redacted with the loaded eval data.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bef6ef918b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/commands/evals.py Outdated
Comment thread packages/prime/src/prime_cli/utils/eval_push.py Outdated
`prime eval push` and the auto-push after `prime eval run` pass all of their
inputs — identifiers included — through the redactor once before anything is
sent, so the whole outbound request is covered with no per-field carve-outs. A
secret inside an identifier makes the request fail rather than leak it.
`env_credentials` is the one rule for what counts as a credential in the
process environment: values under credential-like names, and the password (or
bare user token) inside a `scheme://user:password@host` value whatever its name
— DATABASE_URL, an authenticated HTTP_PROXY. Mirrors verifiers#2508.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0d1dcb5be6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated
Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated
A percent-encoded URL password is registered as written and decoded, since a
client echoes the decoded form. `--secret` probes the filesystem with
`os.path.isfile`, which is False for anything that cannot be a path, so a
literal longer than a filename no longer raises.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7d3b1e443c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f940c459a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74e4d149e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb91a03ddf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 80b39fe3fe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7abb41f154

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated
Comment thread packages/prime/src/prime_cli/utils/redact.py
…the marker

Credential-named query values register their unquote_plus spelling too. A
secret that begins with the marker's tail or ends with its head could be formed
by a replacement, so overlaps_marker extends the inside-the-marker check: such a
discovered value is skipped, an explicit --secret is refused.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 834dda9c90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37f934f37f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated
Only a value inside the marker is a placeholder to skip (or refuse when
explicit). A credential that contains or borders the marker was being dropped
from the known set, which uploads it for certain; registering it can miss only
an instance a replacement forms around another registered secret.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05cdc53b19

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 564c7b9f27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16ae2a08d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09d6404f18

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/prime/src/prime_cli/utils/redact.py Outdated
Compound names are head-final: TOKEN_URL names a URL, COOKIE_DOMAIN a domain,
KEY_FILE a file. The credential word therefore has to be the last segment
(optionally numbered, API_KEY_2), which generalises the AUTH rule to every word
and drops metadata values without an exclusion list.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bf4475fcd8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

console.print(f"\n[blue]Uploading evaluation results, using upstream: {env_identifier}[/blue]")

api_client = APIClient()
redactor = Redactor(known_secrets(api_client.api_key))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Carry the selected eval API key into redaction

When prime eval run is invoked with --api-key-var CRED (or any variable whose name does not match SECRET_NAME), _add_default_inference_and_key_args recognizes that variable as the inference credential, but this redactor is seeded only with the Prime platform key and heuristic environment discovery. If a saved result or log contains the inference key, the automatic upload therefore sends it unchanged; pass the selected variable's value through to push_eval_results_to_hub and register it explicitly.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant