story 2-10-security-schemes-secrets: implemented and reviewed via bmad-loop
This commit is contained in:
1 parent
f5f40cb167
commit
ecfb4e788f
45 files changed
+6025
-829
No files matched your search
@@ -54,17 +54,101 @@ pub(super) fn matches_source(
|
||||
&& matches!(&node.value, CanonicalSourceValue::Array(items) if items.iter().any(|item| !matches!(item.value, CanonicalSourceValue::String(_))))
|
||||
}
|
||||
"secret_like_example" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
pointer.contains("/example") && matches!(&node.value, CanonicalSourceValue::String(value) if secret_like(pointer, value))
|
||||
matches!(&node.value, CanonicalSourceValue::String(value)
|
||||
if secret_like(pointer, value)
|
||||
|| super::metadata_findings::url_has_secret(value)
|
||||
|| (pointer.ends_with("/url") && !value.contains('@'))
|
||||
|| value == super::metadata_findings::REDACTED_LITERAL
|
||||
|| sanitized_secret_url(value))
|
||||
}
|
||||
"invalid_server" if is_error => invalid_server(pointer, node),
|
||||
"unsupported_security_requirement" if is_error => {
|
||||
matches!(&node.value, CanonicalSourceValue::Object(fields) if !fields.is_empty())
|
||||
|| invalid_security_requirement(pointer, node)
|
||||
}
|
||||
"invalid_security_requirements" if is_error => {
|
||||
!matches!(&node.value, CanonicalSourceValue::Array(_))
|
||||
|| matches!(&node.value, CanonicalSourceValue::Array(items) if items.iter().any(|item| !matches!(item.value, CanonicalSourceValue::Object(_))))
|
||||
}
|
||||
"invalid_security_requirement" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
!matches!(&node.value, CanonicalSourceValue::Object(_))
|
||||
}
|
||||
"unsupported_security_requirements" if is_error => ir
|
||||
.operations
|
||||
.iter()
|
||||
.find(|operation| finding.operation_key.as_deref() == Some(operation.key.as_str()))
|
||||
.is_some_and(|operation| {
|
||||
!operation.security_requirements.alternatives.is_empty()
|
||||
&& operation
|
||||
.security_requirements
|
||||
.alternatives
|
||||
.iter()
|
||||
.all(|alternative| !alternative.supported)
|
||||
}),
|
||||
"unsupported_security_and_requirement"
|
||||
if finding.severity == ImportFindingSeverity::Warning =>
|
||||
{
|
||||
matches!(&node.value, CanonicalSourceValue::Object(fields) if fields.len() > 1)
|
||||
}
|
||||
"unsupported_security_scheme" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
ir.security_schemes.get(&scheme_name).is_some_and(|scheme| {
|
||||
matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::Unsupported { .. })
|
||||
|| matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::ApiKey { location: crate::rest::model::SecurityParameterLocation::Cookie, .. })
|
||||
}) && matches!(&node.value, CanonicalSourceValue::Array(_))
|
||||
}
|
||||
"unsupported_security_scheme_definition"
|
||||
if finding.severity == ImportFindingSeverity::Warning =>
|
||||
{
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
ir.security_schemes.get(&scheme_name).is_some_and(|scheme| {
|
||||
matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::Unsupported { .. })
|
||||
}) && matches!(&node.value, CanonicalSourceValue::Object(_))
|
||||
}
|
||||
"unresolved_security_scheme" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
!ir.security_schemes.contains_key(&scheme_name)
|
||||
}
|
||||
"invalid_security_scopes" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
!matches!(&node.value, CanonicalSourceValue::Array(items) if items.iter().all(|item| matches!(item.value, CanonicalSourceValue::String(_))))
|
||||
}
|
||||
"unexpected_security_scopes" if finding.severity == ImportFindingSeverity::Warning => {
|
||||
let scheme_name = pointer
|
||||
.rsplit('/')
|
||||
.next()
|
||||
.unwrap_or_default()
|
||||
.replace("~1", "/")
|
||||
.replace("~0", "~");
|
||||
let supports_scopes = ir.security_schemes.get(&scheme_name).is_some_and(|scheme| {
|
||||
matches!(&scheme.kind, crate::rest::model::NormalizedSecuritySchemeKind::Unsupported { scheme_type: Some(kind) } if matches!(kind.as_str(), "oauth2" | "openIdConnect"))
|
||||
});
|
||||
!supports_scopes
|
||||
&& matches!(&node.value, CanonicalSourceValue::Array(items) if !items.is_empty())
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn sanitized_secret_url(value: &str) -> bool {
|
||||
value.contains("=[REDACTED]")
|
||||
|| ((value.contains("://") || value.starts_with("//")) && !value.contains('@'))
|
||||
}
|
||||
|
||||
fn parameter_style(
|
||||
pointer: &str,
|
||||
node: &CanonicalSourceNode,
|
||||
|
||||
Reference in new issue
Block a user