zeph-core 0.22.2

Core agent loop, configuration, context builder, metrics, and vault for Zeph
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
// SPDX-License-Identifier: MIT OR Apache-2.0

use std::borrow::Cow;
use std::sync::LazyLock;

use base64::Engine as _;
use regex::Regex;
use zeph_common::secrets::{BEARER_TOKEN_PATTERN, JWT_PATTERN, PATH_PREFIXES, SECRET_PREFIXES};

/// Apply URL-credential stripping, secret redaction (including Bearer headers and JWTs),
/// and path sanitization in a single pass.
///
/// Returns `Cow::Borrowed` when no changes are needed (zero-allocation fast path).
#[must_use]
pub fn scrub_content(text: &str) -> Cow<'_, str> {
    // Strip URL-embedded credentials first (https://user:pass@host → https://[REDACTED]@host).
    let after_url: Cow<'_, str> = URL_CREDS_REGEX.replace_all(text, "${scheme}[REDACTED]@");
    let after_secrets: Cow<'_, str> = match redact_secrets(after_url.as_ref()) {
        Cow::Borrowed(_) => after_url,
        Cow::Owned(s) => Cow::Owned(s),
    };
    match sanitize_paths(after_secrets.as_ref()) {
        Cow::Borrowed(_) => after_secrets,
        Cow::Owned(s) => Cow::Owned(s),
    }
}

// Matches any secret prefix followed by non-whitespace characters.
// Using alternation so a single pass covers all prefixes. Prefixes come from
// zeph_common::secrets::SECRET_PREFIXES (the canonical, unescaped list — see #5917)
// and are regex-escaped here since e.g. `ya29.` contains a literal dot.
static SECRET_REGEX: LazyLock<Regex> = LazyLock::new(|| {
    let pattern = SECRET_PREFIXES
        .iter()
        .map(|p| regex::escape(p))
        .collect::<Vec<_>>()
        .join("|");
    let full = format!("(?:{pattern})[^\\s\"'`,;{{}}\\[\\]]*");
    Regex::new(&full).expect("secret redaction regex is valid")
});

static PATH_REGEX: LazyLock<Regex> = LazyLock::new(|| {
    let alt = PATH_PREFIXES.join("|");
    let full = format!(r#"(?:{alt})[^\s"'`,;{{}}\[\]]*"#);
    Regex::new(&full).expect("path redaction regex is valid")
});

// Matches basic-auth credentials embedded in URLs: https://user:pass@host
static URL_CREDS_REGEX: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(r"(?i)(?P<scheme>[a-z][a-z0-9+\-.]*://)(?P<creds>[^@/\s]+:[^@/\s]+@)")
        .expect("url credential redaction regex is valid")
});

// Matches `Authorization: Bearer <token>` headers, keeping the header name via capture group 1.
static BEARER_REGEX: LazyLock<Regex> =
    LazyLock::new(|| Regex::new(BEARER_TOKEN_PATTERN).expect("bearer redaction regex is valid"));

// Matches standalone JWTs (three Base64url-encoded segments separated by dots).
static JWT_REGEX: LazyLock<Regex> =
    LazyLock::new(|| Regex::new(JWT_PATTERN).expect("jwt redaction regex is valid"));

/// Replace tokens containing known secret patterns with `[REDACTED]`.
///
/// Detects secrets embedded in URLs, JSON values, and quoted strings (via the
/// [`zeph_common::secrets::SECRET_PREFIXES`] prefix list), `Authorization: Bearer` headers,
/// and standalone JWTs. Returns `Cow::Borrowed` when nothing was redacted (zero-allocation
/// fast path).
#[must_use]
pub fn redact_secrets(text: &str) -> Cow<'_, str> {
    // Fast path: check for any prefix substring before running the (more expensive)
    // alternation regex. Bearer/JWT regexes below are cheap enough to run unconditionally —
    // `Regex::replace_all` itself returns `Cow::Borrowed` when there is no match.
    let has_prefix_match = SECRET_PREFIXES.iter().any(|p| text.contains(*p));
    let after_prefixes: Cow<'_, str> = if has_prefix_match {
        SECRET_REGEX.replace_all(text, "[REDACTED]")
    } else {
        Cow::Borrowed(text)
    };

    let after_bearer: Cow<'_, str> =
        match BEARER_REGEX.replace_all(after_prefixes.as_ref(), "${1}[REDACTED]") {
            Cow::Borrowed(_) => after_prefixes,
            Cow::Owned(s) => Cow::Owned(s),
        };

    match JWT_REGEX.replace_all(after_bearer.as_ref(), "[REDACTED_JWT]") {
        Cow::Borrowed(_) => after_bearer,
        Cow::Owned(s) => Cow::Owned(s),
    }
}

/// Replace absolute filesystem paths with `[PATH]` to prevent information disclosure.
#[must_use]
pub fn sanitize_paths(text: &str) -> Cow<'_, str> {
    if !PATH_PREFIXES.iter().any(|p| text.contains(*p)) {
        return Cow::Borrowed(text);
    }

    let result = PATH_REGEX.replace_all(text, "[PATH]");
    match result {
        Cow::Borrowed(_) => Cow::Borrowed(text),
        Cow::Owned(s) => Cow::Owned(s),
    }
}

/// Minimum length of a contiguous base64-alphabet run to treat as probable binary data.
///
/// Set well above a typical hash/ID length: natural language and code essentially never
/// produce 200+ unbroken base64-alphabet characters by accident, so this threshold favors
/// avoiding false positives on legitimate short tokens over catching chunked/wrapped base64
/// (e.g. MIME-encoded with embedded newlines), which will not match a single contiguous run.
const MIN_BLOB_LEN: usize = 200;

// Matches contiguous runs of base64-alphabet characters, optionally with trailing padding.
static BASE64_BLOB_REGEX: LazyLock<Regex> = LazyLock::new(|| {
    Regex::new(&format!(r"[A-Za-z0-9+/]{{{MIN_BLOB_LEN},}}={{0,2}}"))
        .expect("base64 blob redaction regex is valid")
});

/// Replace long contiguous base64-alphabet runs with a length/hash marker.
///
/// Guards against tool output that embeds raw binary data (e.g. a vision tool returning
/// image bytes as plain text instead of a typed image part) from being written unredacted
/// to debug dumps. Returns `Cow::Borrowed` when no run is found (zero-allocation fast path).
///
/// Known limitations (accepted for this MVP heuristic, not solved): base64 wrapped with
/// embedded newlines (e.g. 76-char MIME line length) does not form one contiguous run and
/// slips through undetected. Similarly, two adjacent blobs concatenated with no separator can
/// either merge into one run that still clears the threshold, or — if an internal `=` from an
/// unaligned blob boundary sits mid-string — get split into two independently-scored fragments
/// that can each fall under the 200-character threshold and escape redaction even though the
/// combined data would have tripped the heuristic as a single run.
#[must_use]
pub fn redact_binary_blobs(text: &str) -> Cow<'_, str> {
    if !BASE64_BLOB_REGEX.is_match(text) {
        return Cow::Borrowed(text);
    }
    Cow::Owned(
        BASE64_BLOB_REGEX
            .replace_all(text, |caps: &regex::Captures<'_>| {
                let encoded = &caps[0];
                base64::engine::general_purpose::STANDARD
                    .decode(encoded)
                    .map_or_else(
                        |_| {
                            format!(
                                "<redacted possible binary data: undecodable, {} chars>",
                                encoded.len()
                            )
                        },
                        |bytes| {
                            let hash = blake3::hash(&bytes).to_hex();
                            format!(
                                "<redacted possible binary data: {} bytes, blake3:{}>",
                                bytes.len(),
                                &hash[..16]
                            )
                        },
                    )
            })
            .into_owned(),
    )
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::assert_matches;

    #[test]
    fn redacts_openai_key() {
        let text = "Use key sk-abc123def456 for API calls";
        let result = redact_secrets(text);
        assert_eq!(result, "Use key [REDACTED] for API calls");
    }

    #[test]
    fn redacts_stripe_live_key() {
        let text = "Stripe key: sk_live_abcdef123456";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("sk_live_"));
    }

    #[test]
    fn redacts_stripe_test_key() {
        let text = "Test key sk_test_abc123";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
    }

    #[test]
    fn redacts_aws_key() {
        let text = "AWS access key: AKIAIOSFODNN7EXAMPLE";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("AKIA"));
    }

    #[test]
    fn redacts_github_pat() {
        let text = "Token: ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("ghp_"));
    }

    #[test]
    fn redacts_github_oauth() {
        let text = "OAuth: gho_xxxxxxxxxxxx";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
    }

    #[test]
    fn redacts_private_key_header() {
        let text = "Found -----BEGIN RSA PRIVATE KEY----- in file";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("-----BEGIN"));
    }

    #[test]
    fn redacts_slack_tokens() {
        let text = "Bot token xoxb-123-456 and user xoxp-789";
        let result = redact_secrets(text);
        assert_eq!(result, "Bot token [REDACTED] and user [REDACTED]");
    }

    #[test]
    fn preserves_normal_text() {
        let text = "This is a normal response with no secrets";
        let result = redact_secrets(text);
        assert_eq!(result, text);
        assert_matches!(result, Cow::Borrowed(_));
    }

    #[test]
    fn handles_empty_string() {
        assert_eq!(redact_secrets(""), "");
    }

    #[test]
    fn multiple_secrets_redacted() {
        let text = "Keys: sk-abc123 AKIAIOSFODNN7 ghp_xxxxx";
        let result = redact_secrets(text);
        assert_eq!(result, "Keys: [REDACTED] [REDACTED] [REDACTED]");
    }

    #[test]
    fn preserves_multiline_whitespace() {
        let text = "Line one\n  indented line\n\ttabbed line\nsk-secret here";
        let result = redact_secrets(text);
        assert_eq!(
            result,
            "Line one\n  indented line\n\ttabbed line\n[REDACTED] here"
        );
    }

    #[test]
    fn preserves_code_block_formatting() {
        let text = "```rust\nfn main() {\n    let key = \"sk-abc123\";\n    println!(\"{}\", key);\n}\n```";
        let result = redact_secrets(text);
        assert!(result.contains("```rust\nfn"));
        assert!(result.contains("    let"));
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("sk-abc123"));
    }

    #[test]
    fn preserves_multiple_spaces() {
        let text = "word1   word2     word3";
        let result = redact_secrets(text);
        assert_eq!(result, text);
    }

    #[test]
    fn no_allocation_without_secrets() {
        let text = "safe text without any secrets";
        let result = redact_secrets(text);
        assert_matches!(result, Cow::Borrowed(_));
    }

    #[test]
    fn all_secret_prefixes_tested() {
        for prefix in SECRET_PREFIXES {
            let text = format!("token: {prefix}abc123");
            let result = redact_secrets(&text);
            assert!(result.contains("[REDACTED]"), "Failed for prefix: {prefix}");
            assert!(!result.contains(*prefix), "Prefix not redacted: {prefix}");
        }
    }

    #[test]
    fn redacts_google_api_key() {
        let text = "Google key: AIzaSyA1234567890abcdefghijklmnop";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("AIza"));
    }

    #[test]
    fn redacts_google_oauth_token() {
        let text = "OAuth token ya29.a0AfH6SMBx1234567890";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("ya29."));
    }

    #[test]
    fn redacts_gitlab_pat() {
        let text = "GitLab token: glpat-xxxxxxxxxxxxxxxxxxxx";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("glpat-"));
    }

    #[test]
    fn only_whitespace() {
        assert_eq!(redact_secrets("   \n\t  "), "   \n\t  ");
    }

    #[test]
    fn secret_at_end_of_line() {
        let text = "token: sk-abc123";
        let result = redact_secrets(text);
        assert_eq!(result, "token: [REDACTED]");
    }

    #[test]
    fn redacts_secret_in_url() {
        let text = "https://api.example.com?key=sk-abc123xyz";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("sk-abc123xyz"));
    }

    #[test]
    fn redacts_secret_in_json() {
        let text = r#"{"api_key":"sk-abc123def456"}"#;
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("sk-abc123def456"));
    }

    #[test]
    fn sanitize_home_path() {
        let text = "error at /home/user/project/src/main.rs:42";
        let result = sanitize_paths(text);
        assert_eq!(result, "error at [PATH]");
    }

    #[test]
    fn sanitize_users_path() {
        let text = "failed: /Users/dev/code/lib.rs not found";
        let result = sanitize_paths(text);
        assert!(result.contains("[PATH]"));
        assert!(!result.contains("/Users/"));
    }

    #[test]
    fn sanitize_no_paths() {
        let text = "normal error message";
        let result = sanitize_paths(text);
        assert_matches!(result, Cow::Borrowed(_));
    }

    #[test]
    fn redacts_huggingface_token() {
        let text = "HuggingFace token: hf_abcdefghijklmnopqrstuvwxyz";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("hf_"));
    }

    #[test]
    fn redacts_npm_token() {
        let text = "NPM token npm_abc123XYZ";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("npm_abc"));
    }

    #[test]
    fn redacts_docker_pat() {
        let text = "Docker token: dckr_pat_xxxxxxxxxxxx";
        let result = redact_secrets(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("dckr_pat_"));
    }

    use proptest::prelude::*;

    #[test]
    fn scrub_no_match_passthrough() {
        let text = "hello world, nothing sensitive here";
        let result = scrub_content(text);
        assert_matches!(result, Cow::Borrowed(_));
        assert_eq!(result.as_ref(), text);
    }

    #[test]
    fn scrub_only_secrets() {
        let text = "key: sk-abc123def";
        let result = scrub_content(text);
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("sk-abc123"));
        assert!(!result.contains("/home/"));
    }

    #[test]
    fn scrub_only_paths() {
        let text = "error at /Users/dev/project/src/main.rs:42";
        let result = scrub_content(text);
        assert!(result.contains("[PATH]"));
        assert!(!result.contains("/Users/dev/"));
    }

    #[test]
    fn scrub_secrets_and_paths_combined() {
        let text = "token sk-abc123 found at /home/user/config.toml";
        let result = scrub_content(text);
        assert!(result.contains("[REDACTED]"));
        assert!(result.contains("[PATH]"));
        assert!(!result.contains("sk-abc123"));
        assert!(!result.contains("/home/user/"));
    }

    #[test]
    fn scrub_secrets_no_paths() {
        // Secret found but no path → function returns Cow::Owned (modified string)
        let text = "use sk-abc123 for auth";
        let result = scrub_content(text);
        assert!(
            matches!(result, Cow::Owned(_)),
            "must return Cow::Owned when secret was found"
        );
        assert!(result.contains("[REDACTED]"));
        assert!(!result.contains("[PATH]"));
    }

    #[test]
    fn sanitize_paths_all_prefixes() {
        let cases = [
            ("/root/secrets.toml", "/root/"),
            ("/tmp/tmpfile.lock", "/tmp/"),
            ("/var/log/app.log", "/var/"),
        ];
        for (text, prefix) in cases {
            let result = sanitize_paths(text);
            assert!(result.contains("[PATH]"), "{prefix} must be sanitized");
            assert!(
                !result.contains(prefix),
                "{prefix} must be removed from output"
            );
        }
    }

    // ── #5917: Bearer/JWT coverage added to redact_secrets/scrub_content ──────────────

    #[test]
    fn redacts_bearer_token() {
        let result = redact_secrets("Authorization: Bearer eyJhbGciOiJSUzI1NiJ9.payload.signature");
        assert!(
            result.contains("[REDACTED]"),
            "Bearer token must be redacted: {result}"
        );
        assert!(
            !result.contains("eyJhbGciOiJSUzI1NiJ9"),
            "raw JWT header must not appear: {result}"
        );
        assert!(
            result.contains("Authorization:"),
            "header name must be preserved: {result}"
        );
    }

    #[test]
    fn redacts_bearer_token_case_insensitive() {
        let result = redact_secrets("authorization: bearer eyJhbGciOiJSUzI1NiJ9.payload.signature");
        assert!(
            result.contains("[REDACTED]"),
            "Bearer header match must be case-insensitive: {result}"
        );
    }

    #[test]
    fn redacts_standalone_jwt() {
        let jwt = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyMTIzIn0.SflKxwRJSMeKKF2";
        let input = format!("token value: {jwt} was found in logs");
        let result = redact_secrets(&input);
        assert!(
            result.contains("[REDACTED_JWT]"),
            "standalone JWT must be replaced with [REDACTED_JWT]: {result}"
        );
        assert!(
            !result.contains("eyJhbGci"),
            "raw JWT must not appear: {result}"
        );
    }

    #[test]
    fn redacts_alg_none_jwt_with_empty_signature() {
        let input = "token: eyJhbGciOiJub25lIn0.eyJzdWIiOiJ1c2VyIn0. was submitted";
        let result = redact_secrets(input);
        assert!(
            result.contains("[REDACTED_JWT]"),
            "alg=none JWT with empty signature must be redacted: {result}"
        );
    }

    #[test]
    fn scrub_content_redacts_secret_path_bearer_and_jwt_together() {
        let text =
            "key sk-abc123 at /home/user/f with Authorization: Bearer eyJhbG.pay.sig and eyJx.b.c";
        let result = scrub_content(text);
        assert!(result.contains("[REDACTED]"), "API key must be redacted");
        assert!(result.contains("[PATH]"), "path must be redacted");
        assert!(!result.contains("sk-abc123"), "raw API key must not appear");
        assert!(!result.contains("eyJhbG"), "raw JWT must not appear");
    }

    // ── #6315: redact_binary_blobs ──────────────────────────────────────────────────

    #[test]
    fn redact_binary_blobs_redacts_long_base64_run() {
        let payload = "A".repeat(300);
        let text = format!("tool output: {payload} end");
        let result = redact_binary_blobs(&text);
        assert!(result.contains("<redacted possible binary data:"));
        assert!(!result.contains(&payload));
        assert!(result.contains("bytes, blake3:"));
    }

    #[test]
    fn redact_binary_blobs_marker_is_stable_for_same_input() {
        let payload = "B".repeat(250);
        let first = redact_binary_blobs(&payload).into_owned();
        let second = redact_binary_blobs(&payload).into_owned();
        assert_eq!(first, second);
    }

    #[test]
    fn redact_binary_blobs_leaves_short_base64_looking_strings_alone() {
        let text = "id=".to_owned() + &"C".repeat(199);
        let result = redact_binary_blobs(&text);
        assert_matches!(result, Cow::Borrowed(_));
        assert_eq!(result.as_ref(), text);
    }

    #[test]
    fn redact_binary_blobs_leaves_non_base64_text_alone() {
        let text = "This is a normal sentence with no binary data in it at all.";
        let result = redact_binary_blobs(text);
        assert_matches!(result, Cow::Borrowed(_));
        assert_eq!(result.as_ref(), text);
    }

    #[test]
    fn redact_binary_blobs_does_not_over_redact_typical_short_ids() {
        // Typical UUIDs, git hashes, and hex digests are all well under MIN_BLOB_LEN.
        let text = "commit 77442b11d2f3, uuid 550e8400-e29b-41d4-a716-446655440000, sha256:abc123";
        let result = redact_binary_blobs(text);
        assert_matches!(result, Cow::Borrowed(_));
        assert_eq!(result.as_ref(), text);
    }

    #[test]
    fn redact_binary_blobs_undecodable_run_gets_fallback_marker() {
        // 200 'A's decode fine as base64 in isolation, so force an invalid-length run
        // (not a multiple of 4, no valid padding) to hit the undecodable fallback path.
        let payload = "A".repeat(201);
        let result = redact_binary_blobs(&payload);
        assert!(result.contains("<redacted possible binary data: undecodable"));
        assert!(!result.contains(&payload));
    }

    proptest! {
        #[test]
        fn redact_binary_blobs_never_panics(s in ".*") {
            let _ = redact_binary_blobs(&s);
        }

        #[test]
        fn redact_secrets_never_panics(s in ".*") {
            let _ = redact_secrets(&s);
        }

        #[test]
        fn sanitize_paths_never_panics(s in ".*") {
            let _ = sanitize_paths(&s);
        }

        #[test]
        fn redact_preserves_non_secret_text(s in "[a-zA-Z0-9 .,!?]{1,200}") {
            // Only test strings that genuinely contain nothing redact_secrets will touch:
            // no known secret prefix, no "eyJ" (JWT marker), no case-insensitive "bearer".
            let has_secret_prefix = SECRET_PREFIXES.iter().any(|p| s.contains(*p));
            let has_jwt_marker = s.contains("eyJ");
            let has_bearer_marker = s.to_lowercase().contains("bearer");
            if !has_secret_prefix && !has_jwt_marker && !has_bearer_marker {
                let result = redact_secrets(&s);
                assert_eq!(result.as_ref(), s.as_str());
            }
        }

        #[test]
        fn scrub_content_never_panics(s in ".*") {
            let _ = scrub_content(&s);
        }

        #[test]
        fn scrub_content_result_never_contains_raw_secret(s in ".*") {
            let result = scrub_content(&s);
            for prefix in SECRET_PREFIXES {
                assert!(
                    !result.contains(*prefix),
                    "scrub_content must redact prefix: {prefix}"
                );
            }
        }
    }
}