Skip to content

Imp.Redaction misses private keys, GitHub and Hugging Face tokens, and long AWS keys #209

Closed

Description

@deepfates

Imp redacts run events, traces, trajectories and saved programs with Imp.Redaction.redact/1 before storing them, so a secret it misses is persisted.

Reproduced (Imp 0.5.0): Imp.Redaction.redact/1 returns these unchanged: a PEM private key (-----BEGIN PRIVATE KEY----- …), ghp_… GitHub tokens, hf_… Hugging Face tokens, and AKIA followed by 17 characters. It replaces a whole string that merely contains sk-… with [REDACTED], losing the surrounding text.

Imp has three separate secret pattern sets with different thresholds: Imp.Redaction (lib/imp/redaction.ex ~669-705), Imp.ExternalCommand (external_command.ex:477-480) and Imp.Optimizer.Budget (budget.ex:19-20; it does catch PEM keys).

What should be true: one pattern set, in Imp.Redaction, used by every caller; it catches the common credential shapes (PEM private key blocks, OpenAI/Anthropic sk-/sk-ant-, GitHub ghp_/gho_/ghu_/ghs_/ghr_/github_pat_, Hugging Face hf_, AWS AKIA/ASIA access keys, Slack xox?-, Bearer tokens, JWTs) and replaces only the secret, keeping surrounding text.

Done when: a table-driven test covers each shape (and a near-miss that must not be redacted); ExternalCommand and Optimizer.Budget use Imp.Redaction's patterns instead of their own; the redaction test fails if any pattern is removed.

Activity

  1. added
    bug
    on Sep 27, 2026
  2. deepfates commented on Sep 28, 2026

    @deepfates
    OwnerAuthor

    Correction to "What should be true": replacing only the secret and keeping the surrounding text was the wrong requirement, and it is withdrawn.

    The security review of #226 tested span replacement on a broad corpus of fake secrets. It showed secrets that 0.5.0 hides:

    • Credentials no pattern names, which 0.5.0 hides only because the whole string goes when any credential is found: SECRET_KEY_BASE, PGPASSWORD, cookies, Stripe/SendGrid/npm/PyPI/GitLab/Vault tokens, SigV4 Signature=, PGP keys, .netrc, curl -u.
    • Secrets alone in a string, because 0.5.0's hex-assignment rule and its case-insensitive Bearer/Basic matching were dropped.

    To compensate, #226 added rules keyed on names (token: …, session: …, api_key: …). These rewrote ordinary code, prose and JSON answers in 529 lines of the repo's own docs, lib and tests, and they silently changed saved program instructions and demos on Imp.Saving.dump |> load!.

    The corrected stance:

    • One rule, whole-string replacement. A string that contains a credential shape is replaced whole, as in 0.5.0.
    • One pattern set in Imp.Redaction, used by every caller. It holds 0.5.0's rules, all kept (hex assignments, case-insensitive schemes, credential key names in maps), plus the missing shapes above.
    • A new shape triggers replacement only if it is high-confidence. A token or key format, a PEM/PGP/PuTTY private key block, or a URL with a password in its user info. Loose name-based matching of assignments is out.
    • Captured command output is redacted line by line with that same rule, so one secret hides its line rather than the whole capture.

    Done when:

    • A table-driven test covers each shape and its near-miss.
    • No input that 0.5.0 redacts comes back unredacted. This is checked by running 0.5.0's Imp.Redaction and the new one over a shared corpus of fake secrets.
    • Running over the repo's own docs, livebooks, lib and test files changes only lines that hold fake secret fixtures.
    • A saved program's instructions and demos survive dump |> load! unchanged.
    • ExternalCommand and Budget use the one set.
    • Removing any pattern fails a test.
  3. deepfates commented on Sep 28, 2026

    @deepfates
    OwnerAuthor

    One more correction: captured command output is not redacted line by line. The re-review of #226 showed that line mode exposes secrets which sit next to a recognized one. For example, env | grep AWS prints AWS_ACCESS_KEY_ID=AKIA… followed by AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN, and 0.5.0 replaced that whole capture. So captured output follows the same rule as every other string: if it contains a credential shape, the whole capture is replaced.

  4. deepfates commented on Sep 28, 2026

    @deepfates
    OwnerAuthor

    Recorded divergence, from the review of #240. A name/value pair written as a two-element list is redacted wherever it is an element of a list, which is how JSON writes headers and options. A flat two-element list held directly as a field value is treated as data. Examples are input_keys: [:api_key, :question], a schema's "required" => ["api_key", "query"] and labels: ["token", "question"]: 0.5.0 corrupted these on save by reading them as a credential pair. So one input that 0.5.0 redacts is not redacted now: a flat ["api_key", value] held directly under a key that is not itself a credential name. It has the same shape as a list of two names, and corrupting saved programs is the worse failure.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions