use super::decision::should_suppress_inner;
use super::path_filter::{looks_like_secret_scanner_source, looks_like_vendored_minified_path};
use super::shape::{
contains_uuid_v4_substring, looks_like_credential_colliding_punctuation,
looks_like_email_address, looks_like_pure_identifier, looks_like_regex_literal_tail,
looks_like_scheme_prefixed_uri, looks_like_syntactic_punctuation_marker,
looks_like_url_or_path_segment, looks_like_word_separated_identifier,
};
use crate::context;
pub fn should_suppress_known_example_credential(
credential: &str,
path: Option<&str>,
context: context::CodeContext,
) -> bool {
should_suppress_known_example_credential_with_source(credential, path, context, None)
}
pub fn should_suppress_known_example_credential_with_source(
credential: &str,
path: Option<&str>,
context: context::CodeContext,
source_type: Option<&str>,
) -> bool {
should_suppress_inner(credential, path, context, source_type, false, false)
}
pub fn should_suppress_named_detector_finding(
credential: &str,
path: Option<&str>,
context: context::CodeContext,
source_type: Option<&str>,
detector_id: &str,
) -> bool {
let apply_tier_b = is_generic_or_entropy_detector(detector_id);
if apply_tier_b && looks_like_pure_identifier(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"pure_identifier_no_digit",
);
return true;
}
if apply_tier_b && looks_like_word_separated_identifier(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"word_separated_identifier",
);
return true;
}
if apply_tier_b && looks_like_scheme_prefixed_uri(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"scheme_prefixed_uri",
);
return true;
}
if looks_like_syntactic_punctuation_marker(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"syntactic_punctuation_marker",
);
return true;
}
if apply_tier_b && looks_like_credential_colliding_punctuation(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"credential_colliding_punctuation",
);
return true;
}
if apply_tier_b && looks_like_url_or_path_segment(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"url_or_path_segment",
);
return true;
}
if apply_tier_b && contains_uuid_v4_substring(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"contains_uuid_v4",
);
return true;
}
if looks_like_email_address(credential) {
crate::telemetry::record_example_suppression("pipeline", path, credential, "email_address");
return true;
}
if looks_like_vendored_minified_path(path) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"vendored_minified_path",
);
return true;
}
if source_type.is_some_and(|s| s.contains("binary-strings") || s.contains("archive-binary")) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"native_binary_strings",
);
return true;
}
if looks_like_secret_scanner_source(path) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"secret_scanner_source",
);
return true;
}
if path.is_some_and(|p| {
let bytes = p.as_bytes();
if crate::ascii_ci::ends_with_ignore_ascii_case(bytes, b".b64")
|| crate::ascii_ci::ends_with_ignore_ascii_case(bytes, b".base64")
{
return true;
}
let basename = bytes
.iter()
.rposition(|&b| b == b'/' || b == b'\\')
.map(|i| &bytes[i + 1..])
.unwrap_or(bytes);
basename
.get(..7)
.is_some_and(|p| p.eq_ignore_ascii_case(b"base64_"))
|| crate::ascii_ci::ci_find(basename, b"base64_string")
|| basename.eq_ignore_ascii_case(b"base64.txt")
}) && source_type.is_some_and(|s| s == "filesystem")
{
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"raw_base64_file",
);
return true;
}
if looks_like_regex_literal_tail(credential) {
crate::telemetry::record_example_suppression(
"pipeline",
path,
credential,
"regex_literal_tail",
);
return true;
}
let bypass_shape_gates = !detector_id.starts_with("generic-")
&& !detector_id.starts_with("entropy-")
&& !is_weakly_anchored_named_detector(detector_id)
&& detector_id != "private-key";
should_suppress_inner(
credential,
path,
context,
source_type,
false,
bypass_shape_gates,
)
}
fn is_generic_or_entropy_detector(detector_id: &str) -> bool {
detector_id.starts_with("generic-")
|| detector_id.starts_with("entropy-")
|| is_weakly_anchored_named_detector(detector_id)
}
pub fn is_weakly_anchored_named_detector(detector_id: &str) -> bool {
matches!(
detector_id,
"aerisweather-api-credentials"
| "base-api-credentials"
| "flickr-api-key"
| "saltstack-credentials"
| "census-api-key"
| "workato-api-credentials"
| "adobe-api-key"
| "alchemy-api-key"
| "azure-openai-api-key"
| "datadog-api-key"
| "etherscan-api-key"
| "spotify-client-credentials"
| "bamboohr-api-key"
| "calendly-api-key"
| "crowdin-api-token"
| "github-oauth-secret"
| "sonarcloud-token"
| "alertmanager-credentials"
| "azure-container-registry-token"
| "booking-com-api-credentials"
| "catchpoint-api-credentials"
| "cyberark-credentials"
| "dhl-api-credentials"
| "looker-api-credentials"
| "mlflow-tracking-credentials"
| "marketo-api-credentials"
| "okta-widget-api-credentials"
| "opencart-api-credentials"
| "playwright-test-credentials"
| "servicenow-api-key"
| "snowflake-account-info"
| "spacelift-api-key"
| "teamcity-api-credentials"
| "transifex-api-token"
| "tableau-api-token"
| "activecampaign-api-key"
| "chef-automate-token"
| "foundation-api-key"
| "getresponse-api-key"
| "rudder-api-token"
)
}