redact-secret 0.1.0-beta.15

Deterministic secret detection and redaction for runtime data and AI context: scans text locally before it reaches logs, storage, telemetry, tools, or model context. Side-effect free: no runtime network, filesystem, environment, telemetry, secret storage, or UI.
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
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
//! Built-in detectors in canonical registration order.
//!
//! This module is private. The built-in set is reached only through
//! [`DetectorRegistry::with_built_in`](crate::DetectorRegistry::with_built_in),
//! so which detectors exist, how they are constructed, and what they retain
//! are all free to change without breaking a caller. What is public is the
//! observable consequence of the order below: it is the registry order used
//! as the fourth overlap tie breaker, so it must match the TypeScript oracle
//! and the conformance corpus.

mod additional_providers;
mod ai_inference;
mod anthropic;
mod apify;
mod atlassian;
mod aws;
mod aws_bedrock;
mod axiom;
mod azure_devops;
mod baseten_api_key;
mod bearer_token;
mod bitwarden;
mod browserbase;
mod buildkite;
mod catalog;
mod cerebras;
mod clickhouse_cloud;
mod clojars;
mod cloudflare;
mod composio;
mod confluent;
mod connection_string;
mod convex;
mod crates_io;
mod curl_user;
mod databricks;
mod datadog;
mod daytona;
mod discord;
mod doppler;
mod dynatrace;
mod e2b;
mod elevenlabs;
mod firebase;
mod firecrawl;
mod fly;
mod generic_token;
mod github;
mod gitlab;
mod google_oauth;
mod grafana;
mod helicone;
mod heroku;
mod honeycomb;
mod inngest;
mod jwt;
mod keyword_gated_keys;
mod langfuse;
mod langsmith;
mod linear;
mod mailchimp;
mod mailgun;
mod mapbox;
mod microsoft_entra;
mod neon;
mod netlify;
mod new_relic;
mod notion;
mod nvidia;
mod okta;
mod onepassword;
mod openai;
mod ory_token;
mod otpauth;
mod paddle;
mod pattern;
mod pinecone;
mod polar;
mod posthog;
mod postman;
mod prefilter;
mod private_key;
mod pydantic_logfire;
mod resend;
mod rubygems;
mod ruleset_adapter;
mod runpod;
mod scoped_context;
pub(crate) mod selected;
mod sendgrid;
mod sentry;
mod shopify;
mod slack;
mod sonarqube;
mod sourcegraph;
mod square;
mod stripe;
mod telegram;
mod terraform;
mod text;
mod together_tavily;
mod travisci;
mod trigger_dev;
mod twilio;
mod unkey;
mod vault;
mod vercel;
mod wandb;
mod xata;

use crate::types::Detector;
use connection_string::ConnectionStringDetector;
use private_key::PrivateKeyDetector;

pub(crate) use catalog::{declared_common_types, declared_types};
use prefilter::Literals;
pub(crate) use prefilter::{LiteralMatcher, RequiredLiterals, ScanScope};

pub(crate) use aws::{carries_aws_access_key_id, has_open_aws_secret_candidate_line_in};
pub(crate) use bearer_token::has_open_bearer_authorization;
pub(crate) use confluent::has_open_confluent_properties_in;
#[cfg(test)]
pub(crate) use curl_user::candidate_count as curl_user_candidate_count;
pub(crate) use curl_user::has_open_curl_command;
pub(crate) use generic_token::{
    RULESET_NAMES_DETECTOR_ID, generic_token_ruleset_names_detector,
    has_open_contextual_assignment, is_reserved_name, normalize_name,
};
pub(crate) use heroku::has_open_heroku_legacy_context_in;
pub(crate) use keyword_gated_keys::{has_open_deepgram_request_in, has_open_provider_sibling_in};
pub(crate) use private_key::PrivateKeyRetentionTracker;
pub(crate) use ruleset_adapter::RulesetDetector;
pub(crate) use scoped_context::has_open_scoped_context_in;
pub(crate) use text::has_open_list_item_pair_in;
pub(crate) use twilio::has_open_twilio_cli_table_in;
#[cfg(test)]
pub(crate) use {
    aws::has_open_aws_secret_candidate_line,
    confluent::has_open_confluent_properties,
    heroku::has_open_heroku_legacy_context,
    keyword_gated_keys::{has_open_deepgram_request, has_open_provider_sibling},
    scoped_context::has_open_scoped_context,
    text::has_open_list_item_pair,
    twilio::has_open_twilio_cli_table,
};

/// The most complete lines any lookback retention hint reads back: the
/// `*_in` hints above each read their own last lines of one tail of this
/// length (issue #1060).
pub(crate) const MAX_LOOKBACK_LINES: usize = {
    let counts = [
        heroku::LOOKBACK_LINES,
        twilio::CLI_TABLE_LOOKBACK_LINES,
        confluent::PROPERTIES_LOOKBACK_LINES,
        keyword_gated_keys::MAX_HTTP_BLOCK_LINES,
        keyword_gated_keys::MAX_SIBLING_LINES,
        scoped_context::SCOPED_LOOKBACK_LINES,
        // `has_open_list_item_pair_in` and `has_open_aws_secret_candidate_line_in`.
        1,
        2,
    ];
    let mut max = 0;
    let mut index = 0;
    while index < counts.len() {
        if counts[index] > max {
            max = counts[index];
        }
        index += 1;
    }
    max
};

/// The last [`MAX_LOOKBACK_LINES`] complete lines of `input`, oldest first,
/// that every `has_open_*_in` lookback hint reads: computed once per closed
/// line instead of once per hint (issue #1060).
#[cfg(test)]
pub(crate) fn lookback_tail(input: &str) -> Vec<&str> {
    text::last_lines(input, MAX_LOOKBACK_LINES)
}

/// A [`lookback_tail`] held inline: no allocation per closed line (issue
/// #1074). Lines are right-aligned in `lines`; `start` is the first used slot.
pub(crate) struct LookbackTail<'a> {
    lines: [&'a str; MAX_LOOKBACK_LINES],
    start: usize,
}

impl<'a> LookbackTail<'a> {
    /// A tail with no lines, which every hint reads as the empty input.
    pub(crate) const fn empty() -> Self {
        Self {
            lines: [""; MAX_LOOKBACK_LINES],
            start: MAX_LOOKBACK_LINES,
        }
    }

    /// The lines, oldest first.
    pub(crate) fn as_slice(&self) -> &[&'a str] {
        &self.lines[self.start..]
    }
}

/// The last `count` (at most [`MAX_LOOKBACK_LINES`]) complete lines of
/// `input`: exactly `last_lines(input, count)`, and so a window of
/// [`lookback_tail`] whenever `count` is at least the window a hint reads.
pub(crate) fn lookback_tail_lines(input: &str, count: usize) -> LookbackTail<'_> {
    let count = count.min(MAX_LOOKBACK_LINES);
    let mut tail = LookbackTail::empty();
    let complete = input.strip_suffix('\n').unwrap_or(input);
    let bytes = complete.as_bytes();
    let mut end = bytes.len();
    while MAX_LOOKBACK_LINES - tail.start < count {
        let start = text::line_start_before(complete, end);
        tail.start -= 1;
        tail.lines[tail.start] = &complete[start..end];
        if start == 0 {
            break;
        }
        end = if bytes[start - 1] == b'\n' {
            start - 1
        } else {
            start
        };
    }
    tail
}

/// `true` when appending `appended` to any input leaves both
/// [`has_open_contextual_assignment`] and [`has_open_bearer_authorization`]
/// unchanged. Each first skips trailing [`text::is_js_whitespace`] and then
/// reads only what precedes it, so text made of nothing else is invisible to
/// them. The incremental session relies on this to re-evaluate the two tail
/// checks only when a line with other content closes (issue #986).
pub(crate) fn is_open_tail_neutral(appended: &str) -> bool {
    appended.chars().all(text::is_js_whitespace)
}

/// `true` when a detector can read `unit` (the scan copy of one closed
/// incremental unit) as the continuation of text on an earlier line, so
/// scanning it after that text can differ from scanning it alone. The
/// incremental session never batches such a unit with the units before it
/// (issue #985; the per-detector audit is in [`docs/audits/evidence/985/`](https://github.com/redact-secret/redact-secret/tree/2816897f96c405c3eb8c87a0c70eba5df273c121/docs/audits/evidence/985)).
///
/// Two built-in grammars skip [`text::is_js_whitespace`], line terminators
/// included, between their parts:
///
/// - `generic-token`'s assignment grammar between a name and its `=`/`:`
///   operator (`parse_name_and_operator`), so a unit starting with an
///   operator can bind to a name on an earlier line;
/// - `bearer-token`'s header grammar around the `:` of `authorization:`
///   and before `bearer` (`match_scheme_at`), so a unit starting with `:` or
///   `bearer` can complete a header begun on an earlier line.
///
/// Since issue #990 their retention hints hold every such layout the
/// grammars accept in one unit (a backticked, glued or escaped quoted name,
/// a JWK member, `Proxy-Authorization:`), so a unit that closes behind one
/// no longer binds to it. The exclusion is kept as a guard: it costs a
/// batch split on rare lines, and it keeps each batch equal to per-unit
/// processing should a grammar and its hint drift apart again.
pub(crate) fn continues_previous_line(unit: &str) -> bool {
    let start = unit.trim_start_matches(text::is_js_whitespace);
    start.starts_with(['=', ':'])
        || start
            .get(..6)
            .is_some_and(|word| word.eq_ignore_ascii_case("bearer"))
}

/// Stable-sorts `candidates` by start offset, keeping emission order among
/// equal starts: `candidates.sort_by_key(|c| c.range().start())`.
///
/// Every detector that merges candidate streams sorts through this one
/// function, so the WebAssembly build carries a single instantiation of the
/// standard stable sort for `Candidate`; a per-detector closure instantiates
/// its own copy of about 6 KB (issue #1043).
#[inline(never)]
pub(super) fn sort_candidates_by_start(candidates: &mut [crate::types::Candidate]) {
    candidates.sort_by_key(|candidate| candidate.range().start());
}

/// A built-in detector as the registry holds it: a reference to a `static`
/// value, so building a built-in registry runs no per-detector constructor
/// and makes no per-detector allocation (issue #1043).
pub(crate) type BuiltInDetector = &'static (dyn Detector + Sync);

/// One row of a built-in table: the detector's id, written out, and the
/// detector. The registry takes the id from the row, so building a built-in
/// registry calls no detector's `id()`; under a lazily compiling
/// WebAssembly engine each such call compiled one more function inside
/// `initialize()` (issue #1043). Tests pin every row's id to its detector's
/// `id()`. A row dereferences to its detector.
pub(crate) struct BuiltInRow {
    pub(crate) id: &'static str,
    pub(crate) detector: BuiltInDetector,
}

impl std::ops::Deref for BuiltInRow {
    type Target = dyn Detector + Sync;

    fn deref(&self) -> &Self::Target {
        self.detector
    }
}

/// A [`BuiltInRow`] for `detector` under `id`.
const fn row(id: &'static str, detector: BuiltInDetector) -> BuiltInRow {
    BuiltInRow { id, detector }
}

/// Every built-in detector, in canonical registration order.
///
/// One static table rather than a `Vec` of boxes built per call: building
/// that `Vec` compiled to about 6 KB of WebAssembly that a lazily compiling
/// engine had to compile inside `initialize()` (issue #1043).
///
/// One entry per line by contract (`scripts/measure-detector-cost.mjs`
/// comments entries out by line), so the table is kept out of rustfmt.
#[must_use]
#[allow(clippy::too_many_lines)] // one line per built-in detector
pub(crate) fn built_in_detectors() -> &'static [BuiltInRow] {
    #[rustfmt::skip]
    static DETECTORS: &[BuiltInRow] = &[
        row("private-key", &PrivateKeyDetector),
        row("aws-access-key", &aws::AwsAccessKeyDetector),
        row("aws-secret-access-key", &aws::AwsSecretAccessKeyDetector),
        row("aws-bedrock-long-term-api-key", &aws_bedrock::AwsBedrockLongTermApiKeyDetector),
        row("aws-bedrock-short-term-api-key", &aws_bedrock::AwsBedrockShortTermApiKeyDetector),
        row("github-token", &github::GitHubTokenDetector),
        row("gitlab-token", &gitlab::GitlabTokenDetector),
        row("openai-token", &openai::OpenAiTokenDetector),
        row("anthropic-token", &anthropic::AnthropicTokenDetector),
        row("shopify-token", &shopify::ShopifyTokenDetector),
        row("vault-token", &vault::VaultTokenDetector),
        row("stripe-token", &stripe::StripeTokenDetector),
        row("slack-token", &slack::SlackTokenDetector),
        row("pypi-token", &additional_providers::PYPI),
        row("huggingface-token", &additional_providers::HUGGING_FACE),
        row("docker-token", &additional_providers::DOCKER),
        row("cloudflare-token", &cloudflare::CLOUDFLARE),
        row("digitalocean-token", &additional_providers::DIGITALOCEAN),
        row("linear-token", &linear::LINEAR),
        row("supabase-token", &additional_providers::SUPABASE),
        row("supabase-management-token", &additional_providers::SUPABASE_PAT),
        row("vercel-token", &vercel::VERCEL),
        row("npm-token", &additional_providers::NPM),
        row("google-api-key", &additional_providers::GOOGLE),
        row("google-oauth-client-secret", &google_oauth::GOOGLE_OAUTH_CLIENT_SECRET),
        row("sendgrid-token", &sendgrid::SendgridTokenDetector),
        row("microsoft-entra-client-secret", &microsoft_entra::MicrosoftEntraClientSecretDetector),
        row("azure-devops-personal-access-token", &azure_devops::AzureDevOpsPersonalAccessTokenDetector),
        row("notion-token", &notion::NotionTokenDetector),
        row("atlassian-api-token", &atlassian::AtlassianApiTokenDetector),
        row("twilio-auth-token", &twilio::TwilioAuthTokenDetector),
        row("twilio-api-key-secret", &twilio::TwilioApiKeySecretDetector),
        row("telegram-bot-token", &telegram::TelegramBotTokenDetector),
        row("discord-bot-token", &discord::DiscordBotTokenDetector),
        row("sentry-user-auth-token", &sentry::SentryUserAuthTokenDetector),
        row("sentry-org-auth-token", &sentry::SentryOrgAuthTokenDetector),
        row("datadog-api-key", &datadog::DatadogApiKeyDetector),
        row("datadog-application-key", &datadog::DATADOG_APPLICATION_KEY),
        row("datadog-application-key-legacy", &datadog::DatadogApplicationKeyLegacyDetector),
        row("grafana-service-account-token", &grafana::GrafanaServiceAccountTokenDetector),
        row("grafana-cloud-access-policy-token", &additional_providers::GRAFANA_CLOUD),
        row("new-relic-user-api-key", &new_relic::NewRelicUserApiKeyDetector),
        row("new-relic-license-key", &new_relic::NewRelicLicenseKeyDetector),
        row("mailchimp-api-key", &mailchimp::MailchimpMarketingApiKeyDetector),
        row("mailgun-api-key", &mailgun::MailgunApiKeyDetector),
        row("okta-api-token", &okta::OktaApiTokenDetector),
        row("firebase-server-key", &firebase::FirebaseServerKeyDetector),
        row("terraform-cloud-token", &terraform::TerraformCloudTokenDetector),
        row("pulumi-access-token", &additional_providers::PULUMI),
        row("replicate-api-token", &ai_inference::REPLICATE),
        row("groq-api-key", &ai_inference::GROQ),
        row("xai-api-key", &ai_inference::XAI),
        row("openrouter-api-key", &ai_inference::OPENROUTER),
        row("perplexity-api-key", &ai_inference::PERPLEXITY),
        row("fireworks-ai-api-key", &ai_inference::FIREWORKS),
        row("elevenlabs-api-key", &elevenlabs::ElevenLabsApiKeyDetector),
        row("together-ai-api-key", &together_tavily::TOGETHER_AI),
        row("tavily-api-key", &together_tavily::TAVILY),
        row("pinecone-api-key", &pinecone::PineconeApiKeyDetector),
        row("gitlab-runner-authentication-token", &gitlab::GitlabRunnerAuthenticationTokenDetector),
        row("databricks-personal-access-token", &databricks::DATABRICKS),
        row("confluent-cloud-api-secret", &confluent::CONFLUENT_CLOUD_API_SECRET),
        row("confluent-cloud-api-secret-legacy", &confluent::ConfluentLegacyApiSecretDetector),
        row("netlify-token", &netlify::NetlifyPersonalAccessTokenDetector),
        row("neon-api-key", &neon::NEON),
        row("langsmith-api-key", &langsmith::LangsmithApiKeyDetector),
        row("langfuse-secret-key", &langfuse::LangfuseSecretKeyDetector),
        row("postman-api-key", &postman::POSTMAN),
        row("postman-collection-access-key", &postman::POSTMAN_COLLECTION_ACCESS_KEY),
        row("heroku-api-key", &heroku::HEROKU_API_KEY),
        row("heroku-api-key-legacy", &heroku::HerokuApiKeyLegacyDetector),
        row("travisci-api-token", &travisci::TravisCiApiTokenDetector),
        row("mistral-api-key", &keyword_gated_keys::MistralApiKeyDetector),
        row("cohere-api-key", &keyword_gated_keys::CohereApiKeyDetector),
        row("ai21-api-key", &keyword_gated_keys::Ai21ApiKeyDetector),
        row("deepgram-api-key", &keyword_gated_keys::DeepgramApiKeyDetector),
        row("doppler-token", &doppler::DopplerTokenDetector),
        row("trigger-dev-token", &trigger_dev::TRIGGER_DEV),
        row("e2b-api-key", &e2b::E2B),
        row("posthog-token", &posthog::POSTHOG),
        row("helicone-api-key", &helicone::HELICONE),
        row("firecrawl-api-key", &firecrawl::FIRECRAWL),
        row("composio-api-key", &composio::COMPOSIO),
        row("convex-deployment-key", &convex::ConvexDeploymentKeyDetector),
        row("onepassword-service-account-token", &onepassword::OnePasswordServiceAccountTokenDetector),
        row("inngest-signing-key", &inngest::INNGEST_SIGNING_KEY),
        row("resend-api-key", &resend::RESEND_API_KEY),
        row("apify-api-token", &apify::APIFY_API_TOKEN),
        row("wandb-api-key", &wandb::WANDB_API_KEY),
        row("daytona-api-key", &daytona::DAYTONA_API_KEY),
        row("clickhouse-cloud-api-secret", &clickhouse_cloud::CLICKHOUSE_CLOUD_API_SECRET),
        row("nvidia-api-key", &nvidia::NVIDIA_API_KEY),
        row("browserbase-api-key", &browserbase::BROWSERBASE_API_KEY),
        row("runpod-api-key", &runpod::RUNPOD_API_KEY),
        row("cerebras-api-key", &cerebras::CEREBRAS_API_KEY),
        row("bitwarden-secrets-manager-access-token", &bitwarden::BitwardenSecretsManagerAccessTokenDetector),
        row("polar-token", &polar::POLAR),
        row("sonarqube-token", &sonarqube::SONARQUBE),
        row("rubygems-api-key", &rubygems::RUBYGEMS_API_KEY),
        row("clojars-deploy-token", &clojars::CLOJARS_DEPLOY_TOKEN),
        row("crates-io-token", &crates_io::CRATES_IO),
        row("dynatrace-token", &dynatrace::DynatraceTokenDetector),
        row("paddle-api-key", &paddle::PADDLE_API_KEY),
        row("honeycomb-api-key", &honeycomb::HONEYCOMB_INGEST_KEY),
        row("axiom-token", &axiom::AXIOM),
        row("xata-api-key", &xata::XATA),
        row("sourcegraph-token", &sourcegraph::SOURCEGRAPH),
        row("unkey-root-key", &unkey::UNKEY),
        row("buildkite-token", &buildkite::BUILDKITE),
        row("pydantic-logfire-token", &pydantic_logfire::LOGFIRE),
        row("square-token", &square::SQUARE),
        row("mapbox-token", &mapbox::MAPBOX),
        row("fly-token", &fly::FLY),
        row("ory-token", &ory_token::ORY_TOKEN),
        row("baseten-api-key", &baseten_api_key::BASETEN_API_KEY),
        row("jwt", &jwt::JwtDetector),
        row("bearer-token", &bearer_token::BearerTokenDetector),
        row("connection-string", &ConnectionStringDetector),
        row("otpauth-uri", &otpauth::OtpauthDetector),
        row("generic-token", &generic_token::GENERIC_TOKEN),
    ];
    DETECTORS
}

/// Every built-in detector the `common` profile registers, in the same
/// relative order [`built_in_detectors`] gives them.
///
/// This function is written to reference only these six detectors. A
/// `common`-only artifact links no `provider` detector's code, because
/// nothing here calls into `built_in_detectors` or any `provider` module —
/// see `decision-define-detector-profile-and-pack-contract`'s reachability
/// rule. [`BUILT_IN_PACKS`] pins, in tests, that this list is exactly the
/// `Pack::Common` members of the canonical order.
#[must_use]
pub(crate) fn common_built_in_detectors() -> &'static [BuiltInRow] {
    #[rustfmt::skip]
    static DETECTORS: &[BuiltInRow] = &[
        row("private-key", &PrivateKeyDetector),
        row("jwt", &jwt::JwtDetector),
        row("bearer-token", &bearer_token::BearerTokenDetector),
        row("connection-string", &ConnectionStringDetector),
        row("otpauth-uri", &otpauth::OtpauthDetector),
        row("generic-token", &generic_token::GENERIC_TOKEN),
    ];
    DETECTORS
}

/// A built-in detector and the literals it declares for the shared
/// prefilter ([`prefilter`], issue #983).
///
/// Only [`built_in_entries`] and [`common_built_in_entries`] make one, from
/// the detectors this crate constructs, and the registry keeps the
/// declaration in a private field. It is never part of the public
/// `Detector` trait, so a custom detector neither declares nor inherits
/// one, even under a built-in id.
pub(crate) struct BuiltIn {
    pub(crate) id: &'static str,
    pub(crate) detector: BuiltInDetector,
    pub(crate) required: Option<RequiredLiterals>,
}

/// [`built_in_detectors`], each with its prefilter declaration.
#[must_use]
pub(crate) fn built_in_entries() -> Vec<BuiltIn> {
    built_in_detectors()
        .iter()
        .map(|row| BuiltIn {
            id: row.id,
            detector: row.detector,
            required: built_in_required_literals(row.id),
        })
        .collect()
}

/// [`common_built_in_detectors`], each with its prefilter declaration.
#[must_use]
pub(crate) fn common_built_in_entries() -> Vec<BuiltIn> {
    common_built_in_detectors()
        .iter()
        .map(|row| BuiltIn {
            id: row.id,
            detector: row.detector,
            required: common_required_literals(row.id),
        })
        .collect()
}

/// The prefilter declarations of the declared `full` built-ins (issue
/// #983), keyed by detector id. Plain data, so the declarations add almost
/// no code to a WebAssembly build.
///
/// Every declared detector names its literals from its own grammar
/// constants: a table-driven detector's shape prefixes, or the module's
/// `REQUIRED_LITERALS`. The 17 built-ins that cannot declare a
/// case-sensitive literal every candidate needs are absent (pinned by
/// `prefilter::tests::only_the_reviewed_built_ins_run_on_every_call`).
const DECLARED_LITERALS: &[(&str, &[Literals])] = &[
    ("aws-access-key", aws::REQUIRED_LITERALS),
    ("aws-secret-access-key", aws::SECRET_REQUIRED_LITERALS),
    (
        "aws-bedrock-long-term-api-key",
        aws_bedrock::LONG_TERM_REQUIRED_LITERALS,
    ),
    (
        "aws-bedrock-short-term-api-key",
        aws_bedrock::SHORT_TERM_REQUIRED_LITERALS,
    ),
    ("github-token", github::REQUIRED_LITERALS),
    ("gitlab-token", gitlab::REQUIRED_LITERALS),
    ("openai-token", openai::REQUIRED_LITERALS),
    ("anthropic-token", anthropic::REQUIRED_LITERALS),
    ("shopify-token", shopify::REQUIRED_LITERALS),
    ("vault-token", vault::REQUIRED_LITERALS),
    ("stripe-token", stripe::REQUIRED_LITERALS),
    ("slack-token", slack::REQUIRED_LITERALS),
    ("sendgrid-token", sendgrid::REQUIRED_LITERALS),
    (
        "microsoft-entra-client-secret",
        microsoft_entra::REQUIRED_LITERALS,
    ),
    (
        "azure-devops-personal-access-token",
        azure_devops::REQUIRED_LITERALS,
    ),
    ("notion-token", notion::REQUIRED_LITERALS),
    ("atlassian-api-token", atlassian::REQUIRED_LITERALS),
    ("telegram-bot-token", telegram::REQUIRED_LITERALS),
    ("sentry-user-auth-token", sentry::USER_REQUIRED_LITERALS),
    ("sentry-org-auth-token", sentry::ORG_REQUIRED_LITERALS),
    ("grafana-service-account-token", grafana::REQUIRED_LITERALS),
    ("new-relic-user-api-key", new_relic::USER_REQUIRED_LITERALS),
    ("mailchimp-api-key", mailchimp::REQUIRED_LITERALS),
    ("mailgun-api-key", mailgun::REQUIRED_LITERALS),
    ("okta-api-token", okta::REQUIRED_LITERALS),
    ("firebase-server-key", firebase::REQUIRED_LITERALS),
    ("terraform-cloud-token", terraform::REQUIRED_LITERALS),
    ("elevenlabs-api-key", elevenlabs::REQUIRED_LITERALS),
    (
        "gitlab-runner-authentication-token",
        gitlab::RUNNER_REQUIRED_LITERALS,
    ),
    ("netlify-token", netlify::REQUIRED_LITERALS),
    ("langsmith-api-key", langsmith::REQUIRED_LITERALS),
    ("langfuse-secret-key", langfuse::REQUIRED_LITERALS),
    ("doppler-token", doppler::REQUIRED_LITERALS),
    (
        "onepassword-service-account-token",
        onepassword::REQUIRED_LITERALS,
    ),
    (
        additional_providers::PYPI.detector_id(),
        &[Literals::Shapes(additional_providers::PYPI.shapes())],
    ),
    (
        additional_providers::DOCKER.detector_id(),
        &[Literals::Shapes(additional_providers::DOCKER.shapes())],
    ),
    (
        cloudflare::CLOUDFLARE.detector_id(),
        &[Literals::Shapes(cloudflare::CLOUDFLARE.shapes())],
    ),
    (
        linear::LINEAR.detector_id(),
        &[Literals::Shapes(linear::LINEAR.shapes())],
    ),
    (
        additional_providers::SUPABASE.detector_id(),
        &[Literals::Shapes(additional_providers::SUPABASE.shapes())],
    ),
    (
        vercel::VERCEL.detector_id(),
        &[Literals::Shapes(vercel::VERCEL.shapes())],
    ),
    (
        additional_providers::NPM.detector_id(),
        &[Literals::Shapes(additional_providers::NPM.shapes())],
    ),
    (
        additional_providers::GOOGLE.detector_id(),
        &[Literals::Shapes(additional_providers::GOOGLE.shapes())],
    ),
    (
        google_oauth::GOOGLE_OAUTH_CLIENT_SECRET.detector_id(),
        &[Literals::Shapes(
            google_oauth::GOOGLE_OAUTH_CLIENT_SECRET.shapes(),
        )],
    ),
    (
        datadog::DATADOG_APPLICATION_KEY.detector_id(),
        &[Literals::Shapes(datadog::DATADOG_APPLICATION_KEY.shapes())],
    ),
    (
        additional_providers::PULUMI.detector_id(),
        &[Literals::Shapes(additional_providers::PULUMI.shapes())],
    ),
    (
        ai_inference::REPLICATE.detector_id(),
        &[Literals::Shapes(ai_inference::REPLICATE.shapes())],
    ),
    (
        ai_inference::GROQ.detector_id(),
        &[Literals::Shapes(ai_inference::GROQ.shapes())],
    ),
    (
        ai_inference::XAI.detector_id(),
        &[Literals::Shapes(ai_inference::XAI.shapes())],
    ),
    (
        ai_inference::OPENROUTER.detector_id(),
        &[Literals::Shapes(ai_inference::OPENROUTER.shapes())],
    ),
    (
        ai_inference::PERPLEXITY.detector_id(),
        &[Literals::Shapes(ai_inference::PERPLEXITY.shapes())],
    ),
    (
        ai_inference::FIREWORKS.detector_id(),
        &[Literals::Shapes(ai_inference::FIREWORKS.shapes())],
    ),
    (
        together_tavily::TOGETHER_AI.detector_id(),
        &[Literals::Shapes(together_tavily::TOGETHER_AI.shapes())],
    ),
    (
        together_tavily::TAVILY.detector_id(),
        &[Literals::Shapes(together_tavily::TAVILY.shapes())],
    ),
    (
        databricks::DATABRICKS.detector_id(),
        &[Literals::Shapes(databricks::DATABRICKS.shapes())],
    ),
    (
        neon::NEON.detector_id(),
        &[Literals::Shapes(neon::NEON.shapes())],
    ),
    (
        postman::POSTMAN.detector_id(),
        &[Literals::Shapes(postman::POSTMAN.shapes())],
    ),
    (
        heroku::HEROKU_API_KEY.detector_id(),
        &[Literals::Shapes(heroku::HEROKU_API_KEY.shapes())],
    ),
    (
        trigger_dev::TRIGGER_DEV.detector_id(),
        &[Literals::Shapes(trigger_dev::TRIGGER_DEV.shapes())],
    ),
    (
        e2b::E2B.detector_id(),
        &[Literals::Shapes(e2b::E2B.shapes())],
    ),
    (
        posthog::POSTHOG.detector_id(),
        &[Literals::Shapes(posthog::POSTHOG.shapes())],
    ),
    (
        helicone::HELICONE.detector_id(),
        &[Literals::Shapes(helicone::HELICONE.shapes())],
    ),
    (
        firecrawl::FIRECRAWL.detector_id(),
        &[Literals::Shapes(firecrawl::FIRECRAWL.shapes())],
    ),
    (
        composio::COMPOSIO.detector_id(),
        &[Literals::Shapes(composio::COMPOSIO.shapes())],
    ),
    (
        inngest::INNGEST_SIGNING_KEY.detector_id(),
        &[Literals::Shapes(inngest::INNGEST_SIGNING_KEY.shapes())],
    ),
    (
        resend::RESEND_API_KEY.detector_id(),
        &[Literals::Shapes(resend::RESEND_API_KEY.shapes())],
    ),
    (
        apify::APIFY_API_TOKEN.detector_id(),
        &[Literals::Shapes(apify::APIFY_API_TOKEN.shapes())],
    ),
    (
        wandb::WANDB_API_KEY.detector_id(),
        &[Literals::Shapes(wandb::WANDB_API_KEY.shapes())],
    ),
    (
        daytona::DAYTONA_API_KEY.detector_id(),
        &[Literals::Shapes(daytona::DAYTONA_API_KEY.shapes())],
    ),
    (
        clickhouse_cloud::CLICKHOUSE_CLOUD_API_SECRET.detector_id(),
        &[Literals::Shapes(
            clickhouse_cloud::CLICKHOUSE_CLOUD_API_SECRET.shapes(),
        )],
    ),
    (
        nvidia::NVIDIA_API_KEY.detector_id(),
        &[Literals::Shapes(nvidia::NVIDIA_API_KEY.shapes())],
    ),
    (
        browserbase::BROWSERBASE_API_KEY.detector_id(),
        &[Literals::Shapes(browserbase::BROWSERBASE_API_KEY.shapes())],
    ),
    (
        runpod::RUNPOD_API_KEY.detector_id(),
        &[Literals::Shapes(runpod::RUNPOD_API_KEY.shapes())],
    ),
    (
        cerebras::CEREBRAS_API_KEY.detector_id(),
        &[Literals::Shapes(cerebras::CEREBRAS_API_KEY.shapes())],
    ),
    (
        "bitwarden-secrets-manager-access-token",
        bitwarden::REQUIRED_LITERALS,
    ),
    ("polar-token", &[Literals::Shapes(polar::POLAR.shapes())]),
    (
        "sonarqube-token",
        &[Literals::Shapes(sonarqube::SONARQUBE.shapes())],
    ),
    (
        "rubygems-api-key",
        &[Literals::Shapes(rubygems::RUBYGEMS_API_KEY.shapes())],
    ),
    (
        "clojars-deploy-token",
        &[Literals::Shapes(clojars::CLOJARS_DEPLOY_TOKEN.shapes())],
    ),
    (
        crates_io::CRATES_IO.detector_id(),
        &[Literals::Shapes(crates_io::CRATES_IO.shapes())],
    ),
    (
        dynatrace::ID,
        &[Literals::Strs(dynatrace::REQUIRED_LITERALS)],
    ),
    (
        paddle::PADDLE_API_KEY.detector_id(),
        &[Literals::Shapes(paddle::PADDLE_API_KEY.shapes())],
    ),
    (
        honeycomb::HONEYCOMB_INGEST_KEY.detector_id(),
        &[Literals::Shapes(honeycomb::HONEYCOMB_INGEST_KEY.shapes())],
    ),
    (
        axiom::AXIOM.detector_id(),
        &[Literals::Shapes(axiom::AXIOM.shapes())],
    ),
    (
        xata::XATA.detector_id(),
        &[Literals::Shapes(xata::XATA.shapes())],
    ),
    (
        sourcegraph::SOURCEGRAPH.detector_id(),
        &[Literals::Shapes(sourcegraph::SOURCEGRAPH.shapes())],
    ),
    (
        unkey::UNKEY.detector_id(),
        &[Literals::Shapes(unkey::UNKEY.shapes())],
    ),
    (buildkite::ID, &[Literals::Shapes(buildkite::SHAPES)]),
    (
        pydantic_logfire::ID,
        &[Literals::Shapes(pydantic_logfire::SHAPES)],
    ),
    (
        square::SQUARE.detector_id(),
        &[Literals::Shapes(square::SQUARE.shapes())],
    ),
    (mapbox::ID, &[Literals::Shapes(mapbox::SHAPES)]),
    (fly::ID, &[Literals::Shapes(fly::SHAPES)]),
    (
        additional_providers::HUGGING_FACE.detector_id(),
        &[Literals::Shapes(
            additional_providers::HUGGING_FACE.shapes(),
        )],
    ),
    (
        additional_providers::DIGITALOCEAN.detector_id(),
        &[Literals::Shapes(
            additional_providers::DIGITALOCEAN.shapes(),
        )],
    ),
    (
        additional_providers::SUPABASE_PAT.detector_id(),
        &[Literals::Shapes(
            additional_providers::SUPABASE_PAT.shapes(),
        )],
    ),
    (
        additional_providers::GRAFANA_CLOUD.detector_id(),
        &[Literals::Shapes(
            additional_providers::GRAFANA_CLOUD.shapes(),
        )],
    ),
    (
        confluent::CONFLUENT_CLOUD_API_SECRET.detector_id(),
        &[Literals::Shapes(
            confluent::CONFLUENT_CLOUD_API_SECRET.shapes(),
        )],
    ),
    (
        postman::POSTMAN_COLLECTION_ACCESS_KEY.detector_id(),
        &[Literals::Shapes(
            postman::POSTMAN_COLLECTION_ACCESS_KEY.shapes(),
        )],
    ),
    (ory_token::ID, &[Literals::Shapes(ory_token::SHAPES)]),
    (
        baseten_api_key::ID,
        &[Literals::Shapes(baseten_api_key::SHAPES)],
    ),
];

/// The prefilter declaration groups of the declared built-in `id`, resolved
/// when the crate is compiled (issue #1253): `None` for a detector that is
/// not in [`DECLARED_LITERALS`]. Evaluated in a `const` item, only the one
/// declaration it returns is linked, so a composed artifact carries the
/// literals of its selected detectors and none of the others.
const fn declared_literals(id: &str) -> Option<&'static [Literals]> {
    let mut index = 0;
    while index < DECLARED_LITERALS.len() {
        if catalog::const_str_eq(DECLARED_LITERALS[index].0, id) {
            return Some(DECLARED_LITERALS[index].1);
        }
        index += 1;
    }
    None
}

/// The prefilter declaration of the built-in detector `id`, or `None` when
/// it runs on every call.
fn built_in_required_literals(id: &str) -> Option<RequiredLiterals> {
    DECLARED_LITERALS
        .iter()
        .find(|(declared, _)| *declared == id)
        .map_or_else(
            || common_required_literals(id),
            |(_, groups)| RequiredLiterals::any_of(groups),
        )
}

/// The prefilter declaration of the `common` built-in detector `id`, or
/// `None` when it runs on every call. Names only `common` modules, like
/// [`common_built_in_detectors`].
fn common_required_literals(id: &str) -> Option<RequiredLiterals> {
    match id {
        "private-key" => RequiredLiterals::any_of(private_key::REQUIRED_LITERALS),
        "jwt" => RequiredLiterals::any_of(jwt::REQUIRED_LITERALS),
        "connection-string" => RequiredLiterals::any_of(connection_string::REQUIRED_LITERALS),
        "otpauth-uri" => RequiredLiterals::any_of(otpauth::REQUIRED_LITERALS),
        _ => None,
    }
}

/// Which profiles a built-in detector belongs to
/// (`decision-define-detector-profile-and-pack-contract`). Every built-in
/// detector has exactly one pack; `full` holds both.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Pack {
    /// Format-agnostic: a published structure or a credential-bearing
    /// context, not one issuer's token format. Ships in every profile.
    Common,
    /// One issuer's documented or reviewed token format. Ships only in
    /// `full`.
    Provider,
}

/// The canonical id and pack of every built-in detector, in canonical
/// order.
///
/// Pure data: constructing this array calls no detector constructor, so
/// referencing it — for example to compute the reserved-id set a smaller
/// profile's custom detectors must avoid — never pulls a `provider`
/// detector's code into a `common`-only artifact.
pub(crate) const BUILT_IN_PACKS: &[(&str, Pack)] = &[
    ("private-key", Pack::Common),
    ("aws-access-key", Pack::Provider),
    ("aws-secret-access-key", Pack::Provider),
    ("aws-bedrock-long-term-api-key", Pack::Provider),
    ("aws-bedrock-short-term-api-key", Pack::Provider),
    ("github-token", Pack::Provider),
    ("gitlab-token", Pack::Provider),
    ("openai-token", Pack::Provider),
    ("anthropic-token", Pack::Provider),
    ("shopify-token", Pack::Provider),
    ("vault-token", Pack::Provider),
    ("stripe-token", Pack::Provider),
    ("slack-token", Pack::Provider),
    ("pypi-token", Pack::Provider),
    ("huggingface-token", Pack::Provider),
    ("docker-token", Pack::Provider),
    ("cloudflare-token", Pack::Provider),
    ("digitalocean-token", Pack::Provider),
    ("linear-token", Pack::Provider),
    ("supabase-token", Pack::Provider),
    ("supabase-management-token", Pack::Provider),
    ("vercel-token", Pack::Provider),
    ("npm-token", Pack::Provider),
    ("google-api-key", Pack::Provider),
    ("google-oauth-client-secret", Pack::Provider),
    ("sendgrid-token", Pack::Provider),
    ("microsoft-entra-client-secret", Pack::Provider),
    ("azure-devops-personal-access-token", Pack::Provider),
    ("notion-token", Pack::Provider),
    ("atlassian-api-token", Pack::Provider),
    ("twilio-auth-token", Pack::Provider),
    ("twilio-api-key-secret", Pack::Provider),
    ("telegram-bot-token", Pack::Provider),
    ("discord-bot-token", Pack::Provider),
    ("sentry-user-auth-token", Pack::Provider),
    ("sentry-org-auth-token", Pack::Provider),
    ("datadog-api-key", Pack::Provider),
    ("datadog-application-key", Pack::Provider),
    ("datadog-application-key-legacy", Pack::Provider),
    ("grafana-service-account-token", Pack::Provider),
    ("grafana-cloud-access-policy-token", Pack::Provider),
    ("new-relic-user-api-key", Pack::Provider),
    ("new-relic-license-key", Pack::Provider),
    ("mailchimp-api-key", Pack::Provider),
    ("mailgun-api-key", Pack::Provider),
    ("okta-api-token", Pack::Provider),
    ("firebase-server-key", Pack::Provider),
    ("terraform-cloud-token", Pack::Provider),
    ("pulumi-access-token", Pack::Provider),
    ("replicate-api-token", Pack::Provider),
    ("groq-api-key", Pack::Provider),
    ("xai-api-key", Pack::Provider),
    ("openrouter-api-key", Pack::Provider),
    ("perplexity-api-key", Pack::Provider),
    ("fireworks-ai-api-key", Pack::Provider),
    ("elevenlabs-api-key", Pack::Provider),
    ("together-ai-api-key", Pack::Provider),
    ("tavily-api-key", Pack::Provider),
    ("pinecone-api-key", Pack::Provider),
    ("gitlab-runner-authentication-token", Pack::Provider),
    ("databricks-personal-access-token", Pack::Provider),
    ("confluent-cloud-api-secret", Pack::Provider),
    ("confluent-cloud-api-secret-legacy", Pack::Provider),
    ("netlify-token", Pack::Provider),
    ("neon-api-key", Pack::Provider),
    ("langsmith-api-key", Pack::Provider),
    ("langfuse-secret-key", Pack::Provider),
    ("postman-api-key", Pack::Provider),
    ("postman-collection-access-key", Pack::Provider),
    ("heroku-api-key", Pack::Provider),
    ("heroku-api-key-legacy", Pack::Provider),
    ("travisci-api-token", Pack::Provider),
    ("mistral-api-key", Pack::Provider),
    ("cohere-api-key", Pack::Provider),
    ("ai21-api-key", Pack::Provider),
    ("deepgram-api-key", Pack::Provider),
    ("doppler-token", Pack::Provider),
    ("trigger-dev-token", Pack::Provider),
    ("e2b-api-key", Pack::Provider),
    ("posthog-token", Pack::Provider),
    ("helicone-api-key", Pack::Provider),
    ("firecrawl-api-key", Pack::Provider),
    ("composio-api-key", Pack::Provider),
    ("convex-deployment-key", Pack::Provider),
    ("onepassword-service-account-token", Pack::Provider),
    ("inngest-signing-key", Pack::Provider),
    ("resend-api-key", Pack::Provider),
    ("apify-api-token", Pack::Provider),
    ("wandb-api-key", Pack::Provider),
    ("daytona-api-key", Pack::Provider),
    ("clickhouse-cloud-api-secret", Pack::Provider),
    ("nvidia-api-key", Pack::Provider),
    ("browserbase-api-key", Pack::Provider),
    ("runpod-api-key", Pack::Provider),
    ("cerebras-api-key", Pack::Provider),
    ("bitwarden-secrets-manager-access-token", Pack::Provider),
    ("polar-token", Pack::Provider),
    ("sonarqube-token", Pack::Provider),
    ("rubygems-api-key", Pack::Provider),
    ("clojars-deploy-token", Pack::Provider),
    ("crates-io-token", Pack::Provider),
    ("dynatrace-token", Pack::Provider),
    ("paddle-api-key", Pack::Provider),
    ("honeycomb-api-key", Pack::Provider),
    ("axiom-token", Pack::Provider),
    ("xata-api-key", Pack::Provider),
    ("sourcegraph-token", Pack::Provider),
    ("unkey-root-key", Pack::Provider),
    ("buildkite-token", Pack::Provider),
    ("pydantic-logfire-token", Pack::Provider),
    ("square-token", Pack::Provider),
    ("mapbox-token", Pack::Provider),
    ("fly-token", Pack::Provider),
    ("ory-token", Pack::Provider),
    ("baseten-api-key", Pack::Provider),
    ("jwt", Pack::Common),
    ("bearer-token", Pack::Common),
    ("connection-string", Pack::Common),
    ("otpauth-uri", Pack::Common),
    ("generic-token", Pack::Common),
];

/// Every built-in id, `full`'s reserved-id set: no custom detector in any
/// profile may reuse one of these, even a `provider` id a smaller profile
/// does not itself register
/// (`decision-define-detector-profile-and-pack-contract`, "Reserved ids").
pub(crate) fn built_in_ids() -> impl Iterator<Item = &'static str> {
    BUILT_IN_PACKS.iter().map(|(id, _)| *id)
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::is_identifier;
    use crate::types::{Candidate, Confidence, DetectorContext, Specificity};

    #[test]
    fn every_built_in_row_names_its_detectors_own_id() {
        // The registry takes a built-in's id from its table row (issue
        // #1043), so each row's id must be exactly what the detector says.
        for row in built_in_detectors()
            .iter()
            .chain(common_built_in_detectors())
        {
            assert_eq!(row.id, row.detector.id());
        }
    }

    #[test]
    fn built_in_ids_are_valid_and_unique() {
        let detectors = built_in_detectors();
        let mut ids: Vec<&str> = detectors.iter().map(|d| d.id()).collect();
        assert!(ids.iter().all(|id| is_identifier(id)));
        let count = ids.len();
        ids.sort_unstable();
        ids.dedup();
        assert_eq!(ids.len(), count);
    }

    #[test]
    #[allow(clippy::too_many_lines)]
    fn built_in_order_matches_the_typescript_oracle() {
        let detectors = built_in_detectors();
        let ids: Vec<&str> = detectors.iter().map(|d| d.id()).collect();
        assert_eq!(
            ids,
            vec![
                "private-key",
                "aws-access-key",
                "aws-secret-access-key",
                "aws-bedrock-long-term-api-key",
                "aws-bedrock-short-term-api-key",
                "github-token",
                "gitlab-token",
                "openai-token",
                "anthropic-token",
                "shopify-token",
                "vault-token",
                "stripe-token",
                "slack-token",
                "pypi-token",
                "huggingface-token",
                "docker-token",
                "cloudflare-token",
                "digitalocean-token",
                "linear-token",
                "supabase-token",
                "supabase-management-token",
                "vercel-token",
                "npm-token",
                "google-api-key",
                "google-oauth-client-secret",
                "sendgrid-token",
                "microsoft-entra-client-secret",
                "azure-devops-personal-access-token",
                "notion-token",
                "atlassian-api-token",
                "twilio-auth-token",
                "twilio-api-key-secret",
                "telegram-bot-token",
                "discord-bot-token",
                "sentry-user-auth-token",
                "sentry-org-auth-token",
                "datadog-api-key",
                "datadog-application-key",
                "datadog-application-key-legacy",
                "grafana-service-account-token",
                "grafana-cloud-access-policy-token",
                "new-relic-user-api-key",
                "new-relic-license-key",
                "mailchimp-api-key",
                "mailgun-api-key",
                "okta-api-token",
                "firebase-server-key",
                "terraform-cloud-token",
                "pulumi-access-token",
                "replicate-api-token",
                "groq-api-key",
                "xai-api-key",
                "openrouter-api-key",
                "perplexity-api-key",
                "fireworks-ai-api-key",
                "elevenlabs-api-key",
                "together-ai-api-key",
                "tavily-api-key",
                "pinecone-api-key",
                "gitlab-runner-authentication-token",
                "databricks-personal-access-token",
                "confluent-cloud-api-secret",
                "confluent-cloud-api-secret-legacy",
                "netlify-token",
                "neon-api-key",
                "langsmith-api-key",
                "langfuse-secret-key",
                "postman-api-key",
                "postman-collection-access-key",
                "heroku-api-key",
                "heroku-api-key-legacy",
                "travisci-api-token",
                "mistral-api-key",
                "cohere-api-key",
                "ai21-api-key",
                "deepgram-api-key",
                "doppler-token",
                "trigger-dev-token",
                "e2b-api-key",
                "posthog-token",
                "helicone-api-key",
                "firecrawl-api-key",
                "composio-api-key",
                "convex-deployment-key",
                "onepassword-service-account-token",
                "inngest-signing-key",
                "resend-api-key",
                "apify-api-token",
                "wandb-api-key",
                "daytona-api-key",
                "clickhouse-cloud-api-secret",
                "nvidia-api-key",
                "browserbase-api-key",
                "runpod-api-key",
                "cerebras-api-key",
                "bitwarden-secrets-manager-access-token",
                "polar-token",
                "sonarqube-token",
                "rubygems-api-key",
                "clojars-deploy-token",
                "crates-io-token",
                "dynatrace-token",
                "paddle-api-key",
                "honeycomb-api-key",
                "axiom-token",
                "xata-api-key",
                "sourcegraph-token",
                "unkey-root-key",
                "buildkite-token",
                "pydantic-logfire-token",
                "square-token",
                "mapbox-token",
                "fly-token",
                "ory-token",
                "baseten-api-key",
                "jwt",
                "bearer-token",
                "connection-string",
                "otpauth-uri",
                "generic-token",
            ]
        );
    }

    fn ids_of(detectors: &[BuiltInRow]) -> Vec<&str> {
        detectors.iter().map(|d| d.id()).collect()
    }

    #[test]
    fn built_in_packs_table_matches_the_real_full_registry() {
        let full = built_in_detectors();
        let full_ids = ids_of(full);
        let table_ids: Vec<&str> = built_in_ids().collect();
        assert_eq!(
            table_ids, full_ids,
            "BUILT_IN_PACKS must list exactly built_in_detectors()'s ids, in the same order"
        );
        assert_eq!(BUILT_IN_PACKS.len(), full_ids.len());
    }

    #[test]
    fn common_built_in_detectors_are_exactly_the_common_pack_in_canonical_order() {
        let common = common_built_in_detectors();
        let common_ids = ids_of(common);
        let table_common_ids: Vec<&str> = BUILT_IN_PACKS
            .iter()
            .filter(|(_, pack)| *pack == Pack::Common)
            .map(|(id, _)| *id)
            .collect();
        assert_eq!(common_ids, table_common_ids);
        assert_eq!(
            common_ids,
            vec![
                "private-key",
                "jwt",
                "bearer-token",
                "connection-string",
                "otpauth-uri",
                "generic-token",
            ]
        );

        // `common` is an order-preserving subsequence of `full`.
        let full = built_in_detectors();
        let full_ids = ids_of(full);
        let mut cursor = 0;
        for id in &common_ids {
            let found = full_ids[cursor..]
                .iter()
                .position(|full_id| full_id == id)
                .expect("every common id must appear in full");
            cursor += found + 1;
        }
    }

    #[test]
    fn every_built_in_has_exactly_one_pack_and_no_id_repeats() {
        let mut ids: Vec<&str> = BUILT_IN_PACKS.iter().map(|(id, _)| *id).collect();
        let count = ids.len();
        ids.sort_unstable();
        ids.dedup();
        assert_eq!(ids.len(), count, "BUILT_IN_PACKS must not repeat an id");
    }

    #[test]
    fn bearer_and_contextual_detectors_emit_competing_candidates() {
        let input = "auth = \"Bearer SYNTHETIC_REVOKED_BEARER_OVERLAP_1234\"";
        let context = DetectorContext::new(input.len());
        let bearer = bearer_token::BearerTokenDetector
            .detect(input, &context)
            .unwrap();
        let contextual = generic_token::GENERIC_TOKEN
            .detect(input, &context)
            .unwrap();

        assert_eq!(bearer.len(), 1);
        assert_eq!(contextual.len(), 1);
        assert_eq!(bearer[0].type_name(), "bearer_token");
        assert_eq!(bearer[0].confidence(), Confidence::High);
        assert_eq!(bearer[0].specificity(), Some(Specificity::Structural));
        assert_eq!(bearer[0].range().start(), 15);
        assert_eq!(bearer[0].range().end(), 52);
        assert_eq!(contextual[0].type_name(), "contextual_secret");
        assert_eq!(contextual[0].specificity(), Some(Specificity::Contextual));
        assert_eq!(contextual[0].range().start(), 8);
        assert_eq!(contextual[0].range().end(), 52);
        assert!(bearer[0].range().overlaps(contextual[0].range()));
    }

    #[test]
    fn basic_scheme_is_excluded_from_bearer_token_but_generic_token_still_claims_it() {
        let input = "Authorization: Basic ZGVtb3VzZXI6ZGVtb3Bhc3N3b3Jk";
        let context = DetectorContext::new(input.len());
        let bearer = bearer_token::BearerTokenDetector
            .detect(input, &context)
            .unwrap();
        let contextual = generic_token::GENERIC_TOKEN
            .detect(input, &context)
            .unwrap();

        assert!(
            bearer.is_empty(),
            "bearer-token only claims the literal 'bearer' scheme"
        );
        assert_eq!(contextual.len(), 1);
        assert_eq!(contextual[0].type_name(), "authorization_credential");
    }

    /// Issue #552: a genuine, marker-bearing legacy `sk-` key satisfies both
    /// `openai-token`'s reviewed contract and `generic-token`'s new bare
    /// vendor-prefixed policy layer at the identical range. The candidates
    /// compete, but never the finding: `openai-token`'s
    /// [`Specificity::Provider`] strictly dominates `generic-token`'s
    /// [`Specificity::Entropy`] in overlap resolution
    /// (`decision-resolve-overlap-precedence-by-resolved-action-severity`),
    /// so the in-contract key always keeps its own `openai_api_key` finding.
    #[test]
    fn openai_token_and_generic_token_policy_candidates_compete_and_provider_specificity_dominates()
    {
        let input = "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";
        let context = DetectorContext::new(input.len());
        let provider = openai::OpenAiTokenDetector.detect(input, &context).unwrap();
        let policy = generic_token::GENERIC_TOKEN
            .detect(input, &context)
            .unwrap();

        assert_eq!(provider.len(), 1);
        assert_eq!(provider[0].type_name(), "openai_api_key");
        assert_eq!(provider[0].confidence(), Confidence::High);
        assert_eq!(provider[0].specificity(), Some(Specificity::Provider));

        assert_eq!(policy.len(), 1);
        assert_eq!(policy[0].type_name(), "vendor_prefixed_credential");
        assert_eq!(policy[0].confidence(), Confidence::Medium);
        assert_eq!(policy[0].specificity(), Some(Specificity::Entropy));

        assert_eq!(provider[0].range(), policy[0].range());
        assert!(Specificity::Provider > Specificity::Entropy);
    }

    fn assert_provider_candidates(cases: &[(&str, &str)]) {
        let detectors = built_in_detectors();
        for (id, input) in cases {
            let registered = detectors
                .iter()
                .find(|detector| detector.id() == *id)
                .expect("every case id names a registered built-in detector");
            let context = DetectorContext::new(input.len());
            let candidates: Vec<Candidate> = registered.detect(input, &context).unwrap();
            assert_eq!(candidates.len(), 1, "{id}");
            assert_eq!(
                candidates[0].effective_specificity(),
                Specificity::Provider,
                "{id}"
            );
        }
    }

    #[test]
    fn established_built_in_provider_candidates_claim_provider_specificity() {
        let pypi_input = format!("pypi-{}", "SYNTHETIC_REVOKED_".repeat(5));
        let sendgrid_input =
            "SG.SYNTHETIC_REVOKED_0000.SYNTHETIC_REVOKED_SENDGRID_SECRET_000000000";
        let atlassian_input = format!(
            "ATAT{}",
            "SYNTHETIC_REVOKED_ATLASSIAN_API_TOKEN_BODY_".repeat(3)
        );
        let twilio_auth_token_input =
            "twilio AC0123456789abcdef0123456789abcde0 fedcba9876543210fedcba9876543210";
        let twilio_api_key_secret_input =
            "twilio SKaB3dE5gH7jK9mN1pQ3sT5vW7yZ9AbC3d zY9xW7vU5tS3rQ1pO9nM7lK5jI3hG1fE";
        let telegram_input = "123456:SYNTHETIC_REVOKED_TELEGRAM_BOT_TOKEN_SECRET";
        let discord_input = "MDAwMDAwMDAwMDAwMDAwMDAw.REVOKE.SYNTHETICREVOKEDBOTTOKENFIX";
        let confluent_legacy_input =
            "confluent SYNTHETIC0REVOKED0LegacyBareSecretValue0NoPrefix0ABCDEFGHIJKLMNO";
        let aws_bedrock_long_term_input = format!("ABSK{}", "U3ludGhldGljUmV2b2tlZA".repeat(6));
        let aws_bedrock_short_term_input = format!(
            "bedrock-api-key-{}{}",
            "YmVkcm9jay5hbWF6b25hd3MuY29tLz9BY3Rpb249Q2FsbFdpdGhCZWFyZXJUb2tlbiZYLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsP",
            "U3ludGhldGljUmV2b2tlZA".repeat(4)
        );
        let cases = [
            ("aws-access-key", "AKIASYNTHETICEXAMPLE"),
            (
                "aws-bedrock-long-term-api-key",
                aws_bedrock_long_term_input.as_str(),
            ),
            (
                "aws-bedrock-short-term-api-key",
                aws_bedrock_short_term_input.as_str(),
            ),
            (
                "github-token",
                &"ghp_SYNTHETICREVOKEDVALUE0000000000000000"[..40],
            ),
            ("gitlab-token", "glpat-SYNTHETIC_REVOKED_TOKEN_FIXTURE"),
            (
                "openai-token",
                "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",
            ),
            (
                "anthropic-token",
                "sk-ant-api03-SYNTHETIC_REVOKED_ANTHROPIC_KEY",
            ),
            ("shopify-token", "shpat_SYNTHETIC_REVOKED_SHOPIFY_TOKEN"),
            ("vault-token", "hvs.SYNTHETIC_REVOKED_VAULT_TOKEN"),
            ("stripe-token", "sk_live_SYNTHETICREVOKEDPROVIDERVALUE"),
            (
                "slack-token",
                "xoxb-1234567890123-3210987654321-SYNTHETICREVOKEDBOTSECRET1",
            ),
            ("pypi-token", pypi_input.as_str()),
            ("huggingface-token", "hf_SYNTHETICREVOKEDHUGGINGFACETOKEN01"),
            ("docker-token", "dckr_pat_SYNTHETICREVOKEDDOCKERPAT00"),
            (
                "cloudflare-token",
                "cfut_SYNTHETICREVOKEDCLOUDFLAREAPITOKENVALUE1deadbeef",
            ),
            (
                "digitalocean-token",
                "dop_v1_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
            ),
            (
                "linear-token",
                "lin_api_SYNTHETICREVOKEDLINEARAPITOKENVALUE01234",
            ),
            (
                "supabase-token",
                "sb_secret_SYNTHETIC_REVOKED_SUPA_CHECKSUM",
            ),
            (
                "supabase-management-token",
                "sbp_synthetic0revoked1provider2value3padding",
            ),
            ("vercel-token", "vcp_SYNTHETICREVOKEDPROVIDERVALUE"),
            ("npm-token", "npm_SYNTHETICREVOKEDNPMACCESSTOKENVALUE1"),
            ("google-api-key", "AIzaSYNTHETIC_REVOKED_GOOGLE_API_KEY012"),
            ("sendgrid-token", sendgrid_input),
            (
                "microsoft-entra-client-secret",
                "abc8Q~SYNTHETIC_REVOKED_ENTRA_SECRET_V",
            ),
            (
                "azure-devops-personal-access-token",
                "SYNTHETICREVOKEDAZUREDEVOPSPATVALUEFORCONFORMANCETESTINGPADDINGFIXTUREDATAZZAZDOabcd",
            ),
            (
                "notion-token",
                "secret_SYNTHETICREVOKEDNOTIONLEGACYTOKENVALUE00000",
            ),
            ("atlassian-api-token", atlassian_input.as_str()),
            ("twilio-auth-token", twilio_auth_token_input),
            ("twilio-api-key-secret", twilio_api_key_secret_input),
            ("discord-bot-token", discord_input),
            ("telegram-bot-token", telegram_input),
            ("confluent-cloud-api-secret-legacy", confluent_legacy_input),
        ];
        assert_provider_candidates(&cases);
    }

    #[test]
    #[allow(clippy::too_many_lines)]
    fn recent_built_in_provider_candidates_claim_provider_specificity() {
        let sentry_user_auth_token_input = format!("sntryu_{}", "0123456789abcdef".repeat(4));
        let sentry_org_auth_token_input = format!(
            "sntrys_eyJ{}_{}",
            &"SYNTHETICREVOKEDSENTRYORGPAYLOADFIXTURE0123456789".repeat(4)[..23],
            &"SigFixSYNTHETICREVOKED0123456789".repeat(2)[..43]
        );
        let grafana_sa_input = "glsa_SYNTHETICREVOKEDGRAFANASATOKEN01_deadbeef";
        let grafana_cloud_input = "glc_SYNTHETICREVOKEDGRAFANACLOUDACCESSPOLICYTOKEN";
        let datadog_api_key_input = "DD_API_KEY=0123456789abcdef0123456789abcdef";
        let datadog_application_key_input = "ddapp_SYNTHETIC0REVOKED0AppKeyBody012345";
        let datadog_application_key_legacy_input =
            "DD_APPLICATION_KEY=0123456789abcdef0123456789abcdef01234567";
        let new_relic_user_api_key_input = "NRAK-SYNTHETICREVOKEDNEWRELICUSA";
        let new_relic_license_key_input = "newrelic 0123456789abcdef0123456789abcdef01234567";
        let mailchimp_api_key_input = "mailchimp 0123456789abcdef0123456789abcdef-us6";
        let mailgun_api_key_input = "mailgun key-abcdefghijklmnopqrstuvwxyz012345";
        let okta_api_token_input = format!(
            "Authorization: SSWS 00{}",
            &"SYNTHETICREVOKEDOKTAAPITOKENFIXTUREPADDING0123456789"[..40]
        );
        let firebase_server_key_input = format!(
            "AAAA{}:{}",
            "SYNREV0",
            "SYNTHETICREVOKEDFIREBASEFCMLEGACYSERVERKEYFIXTUREPADDING0123456789SYNTHETICREVOKEDFIREBASEFCMLEGACYSERVERKEYFIXTUREPADDING0123456789ABCDWXYZ"
        );
        let terraform_cloud_token_input = format!(
            "SYNREV0REVOKED.atlasv1.{}",
            &"SYNTHETICREVOKEDTERRAFORMCLOUDTOKENFIXTUREPADDING0123456789ABCDEFGHIJKLMNOPQR"[..67]
        );
        let pulumi_access_token_input =
            format!("pul-{}", "0123456789abcdef0123456789abcdef01234567");
        let databricks_personal_access_token_input =
            format!("dapi{}", "0123456789abcdef0123456789abcdef");
        let confluent_cloud_api_secret_input =
            "cfltSYNTHETIC0REVOKED0PrefixedSecretValue0ABCDEFGHIJKLMNOPn2NMow";
        let netlify_token_input = "nfp_SYNTHETIC_REVOKED_NETLIFY_PAT_BODY01";
        let neon_api_key_input = format!(
            "napi_{}",
            "SyntheticRevokedNeonApiKey0000Fixture1111Body2222Padding33334444"
        );
        let langsmith_api_key_input = "lsv2_pt_0123456789abcdef0123456789abcdef_fedcba9876";
        let langfuse_secret_key_input = "sk-lf-0a1b2c3d-4e5f-4a6b-8c7d-0e1f2a3b4c5d";
        let postman_api_key_input = format!(
            "PMAK-{}-{}",
            "0123456789abcdef01234567", "0123456789abcdef0123456789abcdef01"
        );
        let heroku_api_key_input = format!(
            "HRKU-AA{}",
            "SYNTHETIC0REVOKED0HerokuOAuthAccessTokenBodyFixture0123456"
        );
        let heroku_api_key_legacy_input = "heroku 01234567-89ab-cdef-0123-456789abcdef";
        let travisci_api_token_input = "travis Syn7hRevok3dTrvCi0Tok1";
        let mistral_api_key_input =
            format!("MISTRAL_API_KEY={}", "aB3dE5gH7jK9mN1pQ3sT5vW7yZ9xC2Lq");
        let cohere_api_key_input = format!(
            "co = cohere.ClientV2(api_key=\"{}\")",
            "zY9xW7vU5tS3rQ1pO9nM7lK5jI3hG1fEaB3dE5gH"
        );
        let ai21_api_key_input = format!(
            "AI21Client(api_key='{}')",
            "Zz9Yy8Xx7Ww6Vv5Uu4Tt3Ss2Rr1Qq0Pp"
        );
        let deepgram_api_key_input = format!(
            "DEEPGRAM_API_KEY={}",
            "q7w3e9r1t5y8u2i4o6p0a1s3d5f7g9h2j4k6l8z0"
        );
        let replicate_api_token_input = format!("r8_{}", "SYNTHETIC_REVOKED-REPLICATE-TOKEN-001");
        let groq_api_key_input = format!(
            "gsk_{}",
            "SYNTHETICREVOKEDGROQAPIKEYVALUE000000000000000000001"
        );
        let xai_api_key_input = format!("xai-{}", "0123456789".repeat(8));
        let openrouter_api_key_input = format!("sk-or-v1-{}", "0123456789abcdef".repeat(4));
        let perplexity_api_key_input = format!("pplx-{}", "0123456789".repeat(4) + "abcdefgh");
        let fireworks_ai_api_key_input = format!("fw_{}", "SyntheticRevokedFwKey1");
        let elevenlabs_api_key_input = format!("sk_{}", "0123456789abcdef".repeat(3));
        let together_ai_api_key_input =
            format!("tgp_v1_{}", "Synth-Revoked_Together0Fixture9Body-Zq7_Kd2");
        let tavily_api_key_input = format!("tvly-dev-{}", "SyntheticRevokedTavilyFixture014");
        let pinecone_api_key_input = format!(
            "pcsk_SynTh_{}",
            "0123456789abcdef".repeat(4)[..63].to_owned()
        );
        let gitlab_runner_input = "glrt-SyntheticRevokedRunnerPayloadA1.01.0v0xy8zct";
        let doppler_token_input =
            format!("dp.st.{}", "SyntheticRevokedDopplerServiceToken00000000");
        let trigger_dev_token_input = format!("tr_prod_sk_{}", "SyntheticRevokedTrigger0");
        let e2b_api_key_input = format!("e2b_{}", "0123456789abcdef0123456789abcdef01234567");
        let posthog_token_input = format!("phx_{}", "SyntheticRevokedPosthogPersonalKeyFixture01");
        let helicone_api_key_input = format!("sk-helicone-{}", "synthet-icrevok-edfixtr-helico1");
        let firecrawl_api_key_input = format!("fc-{}", "0123456789ab4def8123456789abcdef");
        let composio_api_key_input = format!("ak_{}", "Synthetic_Revoked-Ak");
        let crates_io_token_input = format!("cio{}", "SyntheticRevokedCratesIoToken000");
        let dynatrace_token_input = format!(
            "dt0c01.{}.{}",
            "SYNTHETICREVOKEDDYNATRCE",
            "SYNTHETICREVOKED".repeat(4)
        );
        let paddle_api_key_input = format!(
            "pdl_sdbx_apikey_{}_{}_{}",
            "syntheticrevokedpaddle0000", "SyntheticRevokedSecret", "X9z"
        );
        let honeycomb_api_key_input = format!(
            "hcxik_{}{}",
            "syntheticrevokedhoneycombingestkey", "0123456789abcdefghijklmn"
        );
        let axiom_token_input = format!("xaat-{}", "5e7c0ded-0000-4000-8000-deadbeef0001");
        let xata_api_key_input = format!("xau_{}{}", "SyntheticRevokedXataApiKey", "0".repeat(7));
        let sourcegraph_token_input = format!("sgp_local_{}", "5e7c0ded".repeat(5));
        let unkey_root_key_input = format!(
            "unkey_{}unkeyv1{}",
            "Synthe1c", "SyntheticRevokedUnkeyRootKeyFixture1234567"
        );
        let buildkite_token_input = format!("bkua_{}", "5e7c0ded".repeat(5));
        let pydantic_logfire_token_input = format!("pylf_v1_us_{}", "5e7c0ded".repeat(5));
        let square_token_input = format!("EAAA{}{}", "5e7c0ded".repeat(7), "5e7c");
        let fly_token_input = format!("fm2_{}", "5e7c0ded".repeat(8));
        let ory_token_input = format!("ory_st_{}", "5e7c0ded".repeat(4));
        let mapbox_token_input = format!(
            "sk.eyJ{}.{}{}",
            "5e7c0ded".repeat(3),
            "5e7c0ded".repeat(2),
            "5e7c0d"
        );
        let wandb_api_key_input = format!(
            "wandb_v1_{}",
            &"SyntheticRevokedWandbApiKeyFixture".repeat(3)[..77]
        );
        let apify_api_token_input = format!("apify_api_{}", "SyntheticRevokedApifyToken0000000000");
        let daytona_api_key_input = format!("dtn_{}", "5e7c0ded".repeat(8));
        let clickhouse_cloud_api_secret_input =
            format!("4b1d{}", "SyntheticRevokedClickhouseSecret000000");
        let nvidia_api_key_input = format!(
            "nvapi-{}End",
            "SyntheticRevokedNvidiaApiKeyFixture_".repeat(2)
        );
        let browserbase_api_key_input = format!("bb_live_{}", "SyntheticRevokedBrowserbaseKey0000");
        let runpod_api_key_input = format!("rpa_{}", "SyntheticRevokedRunpodApiKey00000000");
        let cerebras_api_key_input =
            format!("csk-{}", &"SyntheticRevokedCerebrasApiKey_".repeat(2)[..48]);
        let resend_api_key_input = format!("re_{}_{}", "Synth3ic", "RevokedResendFixtureKey0");
        let inngest_signing_key_input = format!("signkey-test-{}", "5e7c0ded".repeat(8));
        let onepassword_service_account_token_input =
            format!("ops_eyJ{}", "SyntheticRevokedOnePasswordFixture".repeat(8));
        let convex_deployment_key_input = format!("convex-self-hosted|01{}", "deadbeef".repeat(9));
        let bitwarden_secrets_manager_access_token_input = format!(
            "0.{}.{}:{}==",
            "5e7c0ded-0000-4000-8000-5e7c0ded0000",
            "SyntheticRevokedBitwardenSecre",
            "SyntheticRevokedKey000"
        );
        let polar_token_input = format!(
            "polar_oat_{}",
            "SyntheticRevokedPolarOrganizationToken00000"
        );
        let sonarqube_token_input = format!("squ_{}", "5e7c0ded".repeat(5));
        let rubygems_api_key_input = format!("rubygems_{}", "5e7c0ded".repeat(6));
        let clojars_deploy_token_input = format!("CLOJARS_{}5e7c", "5e7c0ded".repeat(7));
        let cases = [
            (
                "sentry-user-auth-token",
                sentry_user_auth_token_input.as_str(),
            ),
            (
                "sentry-org-auth-token",
                sentry_org_auth_token_input.as_str(),
            ),
            ("datadog-api-key", datadog_api_key_input),
            ("datadog-application-key", datadog_application_key_input),
            (
                "datadog-application-key-legacy",
                datadog_application_key_legacy_input,
            ),
            ("grafana-service-account-token", grafana_sa_input),
            ("grafana-cloud-access-policy-token", grafana_cloud_input),
            ("new-relic-user-api-key", new_relic_user_api_key_input),
            ("new-relic-license-key", new_relic_license_key_input),
            ("mailchimp-api-key", mailchimp_api_key_input),
            ("mailgun-api-key", mailgun_api_key_input),
            ("okta-api-token", okta_api_token_input.as_str()),
            ("firebase-server-key", firebase_server_key_input.as_str()),
            (
                "terraform-cloud-token",
                terraform_cloud_token_input.as_str(),
            ),
            ("pulumi-access-token", pulumi_access_token_input.as_str()),
            ("replicate-api-token", replicate_api_token_input.as_str()),
            ("groq-api-key", groq_api_key_input.as_str()),
            ("xai-api-key", xai_api_key_input.as_str()),
            ("openrouter-api-key", openrouter_api_key_input.as_str()),
            ("perplexity-api-key", perplexity_api_key_input.as_str()),
            ("fireworks-ai-api-key", fireworks_ai_api_key_input.as_str()),
            ("elevenlabs-api-key", elevenlabs_api_key_input.as_str()),
            ("together-ai-api-key", together_ai_api_key_input.as_str()),
            ("tavily-api-key", tavily_api_key_input.as_str()),
            ("pinecone-api-key", pinecone_api_key_input.as_str()),
            ("gitlab-runner-authentication-token", gitlab_runner_input),
            (
                "databricks-personal-access-token",
                databricks_personal_access_token_input.as_str(),
            ),
            (
                "confluent-cloud-api-secret",
                confluent_cloud_api_secret_input,
            ),
            ("netlify-token", netlify_token_input),
            ("neon-api-key", neon_api_key_input.as_str()),
            ("langsmith-api-key", langsmith_api_key_input),
            ("langfuse-secret-key", langfuse_secret_key_input),
            ("postman-api-key", postman_api_key_input.as_str()),
            (
                "postman-collection-access-key",
                "PMAT-SynthRevoked0Postman0Pmat1",
            ),
            ("heroku-api-key", heroku_api_key_input.as_str()),
            ("heroku-api-key-legacy", heroku_api_key_legacy_input),
            ("travisci-api-token", travisci_api_token_input),
            ("mistral-api-key", mistral_api_key_input.as_str()),
            ("cohere-api-key", cohere_api_key_input.as_str()),
            ("ai21-api-key", ai21_api_key_input.as_str()),
            ("deepgram-api-key", deepgram_api_key_input.as_str()),
            ("doppler-token", doppler_token_input.as_str()),
            ("trigger-dev-token", trigger_dev_token_input.as_str()),
            ("e2b-api-key", e2b_api_key_input.as_str()),
            ("posthog-token", posthog_token_input.as_str()),
            ("helicone-api-key", helicone_api_key_input.as_str()),
            ("firecrawl-api-key", firecrawl_api_key_input.as_str()),
            ("composio-api-key", composio_api_key_input.as_str()),
            (
                "convex-deployment-key",
                convex_deployment_key_input.as_str(),
            ),
            (
                "onepassword-service-account-token",
                onepassword_service_account_token_input.as_str(),
            ),
            ("inngest-signing-key", inngest_signing_key_input.as_str()),
            ("resend-api-key", resend_api_key_input.as_str()),
            ("apify-api-token", apify_api_token_input.as_str()),
            ("wandb-api-key", wandb_api_key_input.as_str()),
            ("daytona-api-key", daytona_api_key_input.as_str()),
            (
                "clickhouse-cloud-api-secret",
                clickhouse_cloud_api_secret_input.as_str(),
            ),
            ("nvidia-api-key", nvidia_api_key_input.as_str()),
            ("browserbase-api-key", browserbase_api_key_input.as_str()),
            ("runpod-api-key", runpod_api_key_input.as_str()),
            ("cerebras-api-key", cerebras_api_key_input.as_str()),
            (
                "bitwarden-secrets-manager-access-token",
                bitwarden_secrets_manager_access_token_input.as_str(),
            ),
            ("polar-token", polar_token_input.as_str()),
            ("sonarqube-token", sonarqube_token_input.as_str()),
            ("rubygems-api-key", rubygems_api_key_input.as_str()),
            ("clojars-deploy-token", clojars_deploy_token_input.as_str()),
            ("crates-io-token", crates_io_token_input.as_str()),
            ("dynatrace-token", dynatrace_token_input.as_str()),
            ("paddle-api-key", paddle_api_key_input.as_str()),
            ("honeycomb-api-key", honeycomb_api_key_input.as_str()),
            ("axiom-token", axiom_token_input.as_str()),
            ("xata-api-key", xata_api_key_input.as_str()),
            ("sourcegraph-token", sourcegraph_token_input.as_str()),
            ("unkey-root-key", unkey_root_key_input.as_str()),
            ("buildkite-token", buildkite_token_input.as_str()),
            (
                "pydantic-logfire-token",
                pydantic_logfire_token_input.as_str(),
            ),
            ("square-token", square_token_input.as_str()),
            ("mapbox-token", mapbox_token_input.as_str()),
            ("fly-token", fly_token_input.as_str()),
            ("ory-token", ory_token_input.as_str()),
        ];
        assert_provider_candidates(&cases);
    }

    /// Issue #375 checkbox 5: a contract-rejected shape from one of the
    /// seven frozen provider families must stay silent when that provider's
    /// detector runs alone (`built_in_detectors` filtered to just its id,
    /// mirroring `assert_provider_candidates` above), while the *default*
    /// registry -- the full built-in set -- still masks the same value
    /// through `bearer-token` under a `Bearer` credential. No global
    /// suppression follows from one provider's own rejection.
    #[test]
    fn provider_only_scan_stays_silent_while_the_default_registry_still_masks_the_malformed_shape()
    {
        let cases: &[(&str, &str)] = &[
            (
                "openai-token",
                // Legacy left segment one byte short of the contracted 20.
                "sk-SYNTHETIC_REVOKED_1T3BlbkFJSYNTHETIC_REVOKED_0002",
            ),
            (
                "digitalocean-token",
                // 63 lowercase-hex bytes, one short of the contracted 64.
                "dop_v1_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd",
            ),
            (
                "docker-token",
                // 26-byte PAT body, one short of the contracted 27.
                "dckr_pat_SYNTHETICREVOKEDDOCKERPA",
            ),
            (
                "slack-token",
                // The two numeric bot sections run straight into the secret
                // with no separator: the exact beta.4 shape the frozen
                // contract rejects.
                "xoxb-1234567890123-3210987654321SYNTHETICREVOKEDBOTSECRET1",
            ),
            (
                "huggingface-token",
                // 33-byte body, one short of the contracted 34.
                "hf_SyntheticRevokedHuggingFaceTokenA",
            ),
            (
                "cloudflare-token",
                // Non-hex checksum suffix.
                "cfut_SYNTHETICREVOKEDCLOUDFLAREAPITOKENVALUE1ghijklmn",
            ),
            (
                "linear-token",
                // 39-byte body, one short of the contracted 40.
                "lin_api_SyntheticRevokedLinearApiTokenABCDEF012",
            ),
        ];

        let all_detectors = built_in_detectors();
        for (id, malformed) in cases {
            let provider_only = all_detectors
                .iter()
                .find(|detector| detector.id() == *id)
                .expect("every case id names a registered built-in detector");
            let context = DetectorContext::new(malformed.len());
            let candidates = provider_only.detect(malformed, &context).unwrap();
            assert!(
                candidates.is_empty(),
                "{id}: provider-only scan of a contract-rejected shape must stay silent"
            );

            let wrapped = format!("Authorization: Bearer {malformed}");
            let default_registry = crate::DetectorRegistry::with_built_in([]).unwrap();
            let findings = crate::scan(&wrapped, &default_registry, &crate::DefaultPolicy).unwrap();
            assert_eq!(
                findings.len(),
                1,
                "{id}: the default registry must still mask the same value as a Bearer credential"
            );
            assert_eq!(findings[0].detector(), "bearer-token", "{id}");
            assert_eq!(findings[0].type_name(), "bearer_token", "{id}");
        }
    }
}