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,
};
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,
1,
2,
];
let mut max = 0;
let mut index = 0;
while index < counts.len() {
if counts[index] > max {
max = counts[index];
}
index += 1;
}
max
};
#[cfg(test)]
pub(crate) fn lookback_tail(input: &str) -> Vec<&str> {
text::last_lines(input, MAX_LOOKBACK_LINES)
}
pub(crate) struct LookbackTail<'a> {
lines: [&'a str; MAX_LOOKBACK_LINES],
start: usize,
}
impl<'a> LookbackTail<'a> {
pub(crate) const fn empty() -> Self {
Self {
lines: [""; MAX_LOOKBACK_LINES],
start: MAX_LOOKBACK_LINES,
}
}
pub(crate) fn as_slice(&self) -> &[&'a str] {
&self.lines[self.start..]
}
}
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
}
pub(crate) fn is_open_tail_neutral(appended: &str) -> bool {
appended.chars().all(text::is_js_whitespace)
}
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"))
}
#[inline(never)]
pub(super) fn sort_candidates_by_start(candidates: &mut [crate::types::Candidate]) {
candidates.sort_by_key(|candidate| candidate.range().start());
}
pub(crate) type BuiltInDetector = &'static (dyn Detector + Sync);
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
}
}
const fn row(id: &'static str, detector: BuiltInDetector) -> BuiltInRow {
BuiltInRow { id, detector }
}
#[must_use]
#[allow(clippy::too_many_lines)] 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", µsoft_entra::MicrosoftEntraClientSecretDetector),
row("azure-devops-personal-access-token", &azure_devops::AzureDevOpsPersonalAccessTokenDetector),
row("notion-token", ¬ion::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
}
#[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
}
pub(crate) struct BuiltIn {
pub(crate) id: &'static str,
pub(crate) detector: BuiltInDetector,
pub(crate) required: Option<RequiredLiterals>,
}
#[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()
}
#[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()
}
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)],
),
];
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
}
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),
)
}
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,
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Pack {
Common,
Provider,
}
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),
];
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() {
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",
]
);
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");
}
#[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);
}
#[test]
fn provider_only_scan_stays_silent_while_the_default_registry_still_masks_the_malformed_shape()
{
let cases: &[(&str, &str)] = &[
(
"openai-token",
"sk-SYNTHETIC_REVOKED_1T3BlbkFJSYNTHETIC_REVOKED_0002",
),
(
"digitalocean-token",
"dop_v1_0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcd",
),
(
"docker-token",
"dckr_pat_SYNTHETICREVOKEDDOCKERPA",
),
(
"slack-token",
"xoxb-1234567890123-3210987654321SYNTHETICREVOKEDBOTSECRET1",
),
(
"huggingface-token",
"hf_SyntheticRevokedHuggingFaceTokenA",
),
(
"cloudflare-token",
"cfut_SYNTHETICREVOKEDCLOUDFLAREAPITOKENVALUE1ghijklmn",
),
(
"linear-token",
"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}");
}
}
}