Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(sanitize): redact secret names one step outside KEY/TOKEN, and dotless eyJ tokens

luisfnicolau4927e9f3c924
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c0229db6..5d7ffe58 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
provider. (#1026)
### Fixed
+- The sanitizer now redacts `*_KEY_ID`, `*_PASSPHRASE`, `*_SIGNING_KEY`,
+ `*_PEPPER` and `*_SALT` assignments (e.g. an S3 `…_ACCESS_KEY_ID`, an auth
+ token pepper) and dotless base64 JSON tokens such as Cloudflare tunnel
+ tokens (`eyJ…`, 40+ characters); SHAs, UUIDs and short `eyJ` fragments are
+ left alone.
- Fixed interrupted launchers blocking an immediate managed-workstream restart
by adding explicit `ai-memory run --force-unlock` recovery. The server
atomically expires and replaces only a lease attributed to the same
diff --git a/crates/ai-memory-core/src/sanitize.rs b/crates/ai-memory-core/src/sanitize.rs
index d2a5d179..51be49dc 100644
--- a/crates/ai-memory-core/src/sanitize.rs
+++ b/crates/ai-memory-core/src/sanitize.rs
@@ -20,8 +20,9 @@
//! Facebook Graph EAA…, Telegram bot tokens, GoHighLevel pit-…, Slack
//! xoxb/xoxp…, AWS AKIA/ASIA…), PEM-bracketed private
//! keys, URL-embedded credentials (`postgres://user:pass@host`), and
-//! anything matching the generic `*_(KEY|TOKEN|SECRET|PASSWORD|
-//! CREDENTIAL)=value` shape. Operators can extend the list via
+//! dotless base64 JSON tokens (Cloudflare tunnel tokens), and anything
+//! matching the generic `*_(KEY|KEY_ID|TOKEN|SECRET|PASSWORD|CREDENTIAL|
+//! PEPPER|SALT|…)=value` shape. Operators can extend the list via
//! `[sanitize].extra_patterns` and exempt substrings via
//! `[sanitize].allowlist` — the allowlist is checked *per match*, so a
//! pattern still runs but an allowlisted span survives unchanged.
@@ -134,6 +135,13 @@ const BUILTIN_PATTERNS: &[(&str, &str)] = &[
r"eyJ[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{16,}\.[A-Za-z0-9_\-]{16,}",
"jwt",
),
+ // A base64 JSON object with no dots: Cloudflare tunnel tokens
+ // (`cloudflared service install eyJ…` is how the dashboard hands one out)
+ // and other opaque `{"…` blobs the JWT rule's three segments miss. `eyJ` is
+ // only base64 for `{"`, so the 40-character floor is what separates a
+ // credential from a short encoded fragment; config that long is pasted as
+ // JSON, not base64.
+ (r"eyJ[A-Za-z0-9_\-+/]{40,}={0,2}", "base64_json_token"),
// PEM private key blocks — multi-line, lazy match.
(
r"(?s)-----BEGIN [A-Z ]*PRIVATE KEY-----.*?-----END [A-Z ]*PRIVATE KEY-----",
@@ -174,9 +182,13 @@ const BUILTIN_PATTERNS: &[(&str, &str)] = &[
"env_secret",
),
// Generic env-var catch-all: any *_KEY / *_TOKEN / *_SECRET /
- // *_PASSWORD / *_CREDENTIAL[S] / *_PRIVATE_KEY assignment.
+ // *_PASSWORD / *_CREDENTIAL[S] / *_PRIVATE_KEY assignment, plus the
+ // suffixes one step outside those: `*_KEY_ID` (the other half of an S3
+ // pair, e.g. `LITESTREAM_ACCESS_KEY_ID`), `*_PASSPHRASE`, `*_SIGNING_KEY`,
+ // and `*_PEPPER` / `*_SALT`, which turn a stolen hash table into a usable
+ // one.
(
- r#"(?i)\b[A-Z][A-Z0-9_]*_(KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL|CREDENTIALS|PRIVATE_KEY)"?\s*[=:]\s*\S+"#,
+ r#"(?i)\b[A-Z][A-Z0-9_]*_(KEY|KEY_ID|TOKEN|SECRET|PASSWORD|PASSWD|PASSPHRASE|CREDENTIAL|CREDENTIALS|PRIVATE_KEY|SIGNING_KEY|PEPPER|SALT)"?\s*[=:]\s*\S+"#,
"env_secret",
),
// Filesystem paths that commonly contain credentials. The separator
@@ -485,6 +497,58 @@ mod tests {
Sanitizer::builtin()
}
+ #[test]
+ fn scrubs_the_suffixes_one_step_outside_key_and_token() {
+ // Fixtures are FAKE shapes, not real values.
+ for (input, secret) in [
+ (
+ "LITESTREAM_ACCESS_KEY_ID=fake0000fake0000fake0000fake0000",
+ "fake0000fake0000fake0000fake0000",
+ ),
+ (
+ "AI_MEMORY_AUTH_TOKEN_PEPPER=fakepepperfakepepperfakepepper00",
+ "fakepepperfakepepperfakepepper00",
+ ),
+ ("PASSWORD_SALT: fakesaltfakesalt00", "fakesaltfakesalt00"),
+ ("GPG_PASSPHRASE=correct-horse-fake", "correct-horse-fake"),
+ ("RELEASE_SIGNING_KEY=fakesigningkey000", "fakesigningkey000"),
+ ] {
+ let out = s().scrub(input);
+ assert!(!out.contains(secret), "{input} -> {out}");
+ assert!(out.contains("[REDACTED:env_secret]"), "{input} -> {out}");
+ }
+ }
+
+ #[test]
+ fn scrubs_a_dotless_base64_json_token() {
+ // The shape of a Cloudflare tunnel token: base64 of `{"a":"…","t":"…"}`
+ // with no dots, handed out as a shell command rather than an assignment.
+ let token = "eyJhIjoiRkFLRUZBS0VGQUtFRkFLRUZBS0VGQUtFIiwidCI6IkZBS0VGQUtFIn0=";
+ let out = s().scrub(&format!("cloudflared service install {token}"));
+ assert!(!out.contains(token), "{out}");
+ assert_eq!(
+ out,
+ "cloudflared service install [REDACTED:base64_json_token]"
+ );
+ }
+
+ #[test]
+ fn ordinary_identifiers_survive_the_wider_rules() {
+ for keep in [
+ // A git SHA, a SHA-256 digest, a UUID and a version string.
+ "commit 1f0775428a9e4b1c2d3e4f5a6b7c8d9e0f1a2b3c",
+ "sha256 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
+ "request 3b58f2d3-c1ac-81b2-b387-dd04ff9a3d11",
+ "version 2.4.2",
+ // `eyJ` is only base64 for `{"`: a short run is not a credential.
+ "payload eyJhIjoi",
+ // The suffixes are words in prose, not assignments.
+ "add a pinch of SALT and a KEY_ID column",
+ ] {
+ assert_eq!(s().scrub(keep), keep);
+ }
+ }
+
#[test]
fn scrubs_bearer_token() {
let out = s().scrub("Authorization: Bearer abcdef0123456789ABCDEF0123456789");