Skip to content

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

Rust

fix(core): redact Gemini authorization API keys

Felipe Grilo0158dc37a106
diff --git a/crates/ai-memory-core/src/sanitize.rs b/crates/ai-memory-core/src/sanitize.rs
index d2a5d179..fca16857 100644
--- a/crates/ai-memory-core/src/sanitize.rs
+++ b/crates/ai-memory-core/src/sanitize.rs
@@ -91,8 +91,14 @@ const BUILTIN_PATTERNS: &[(&str, &str)] = &[
// no error and no way to recover it. The word boundaries keep a real key
// from being missed when it sits inside punctuation.
(r"\b(?:AKIA|ASIA)[0-9A-Z]{16}\b", "aws_key"),
- // Naked Google / Gemini API keys.
+ // Naked Google / Gemini API keys (legacy standard-key shape).
(r"AIza[A-Za-z0-9_\-]{30,}", "google_api_key"),
+ // Gemini authorization ("auth") keys. AI Studio has issued these instead
+ // of `AIza…` keys since 2026-05-28: `AQ.Ab` followed by a base64url tail
+ // (48 characters on a key issued 2026-10). The `.Ab` anchor keeps
+ // ordinary text such as "AQ.A" headings or `AQ.` abbreviations intact;
+ // the open tail floor matches the AIza rule's.
+ (r"AQ\.Ab[A-Za-z0-9_\-]{30,}", "google_api_key"),
// Google OAuth refresh tokens. Longer-lived than the AIza keys above:
// they mint fresh access tokens until explicitly revoked, so a leaked
// one outlives the session it came from.
@@ -516,6 +522,28 @@ mod tests {
assert!(!out.contains("AIzaSy"));
}
+ #[test]
+ fn scrubs_naked_gemini_auth_key() {
+ // SHAPE only (`AQ.Ab` + base64url tail), never a live value — same
+ // rule as the AIzaSy… fixture above.
+ let out = s().scrub("export it: AQ.AbFAKEfake0123456789abcdefghijklmn-_FAKE done");
+ assert!(out.contains("[REDACTED:"), "{out}");
+ assert!(!out.contains("AQ.AbFAKE"), "{out}");
+ assert!(out.ends_with(" done"), "{out}");
+ }
+
+ #[test]
+ fn leaves_short_aq_prefixed_text_alone() {
+ // Not a key: too short, or missing the `.Ab` anchor.
+ for text in [
+ "see AQ.Ab for details",
+ "AQ.A section",
+ "AQ.Xyz0123456789abcdefghijklmnopqrstuvwxyz",
+ ] {
+ assert_eq!(s().scrub(text), text);
+ }
+ }
+
// Every fixture below is a SHAPE, never a live value — same rule as the
// AIzaSy… test above, and the same `FAKE` convention used by the
// `ghp_FAKE…` fixture in ai-memory-wiki. Keep them obviously synthetic