feat(import): bind OpenAPI security schemes safely

This commit is contained in:
bsodfather committed 2026-09-27 23:42:11 +03:00
1 parent c562d5368d
commit 41a0e46110
38 files changed
+4651 -590

No files matched your search

@@ -4,6 +4,7 @@ use tracing::warn;
pub(super) struct MaterializedDependencies {
pub(super) snapshots: Vec<crank_import::rest::ExternalDocumentSnapshot>,
pub(super) secret_literal_rejected: bool,
envelopes: Vec<ImportJobSourceEnvelope>,
canonical_uris: Vec<String>,
guards: Vec<SourceDetachGuard>,
@@ -21,6 +22,7 @@ impl MaterializedDependencies {
fn empty() -> Self {
Self {
snapshots: Vec::new(),
secret_literal_rejected: false,
envelopes: Vec::new(),
canonical_uris: Vec::new(),
guards: Vec::new(),
@@ -207,6 +209,26 @@ impl AdminService {
);
continue;
};
match crank_import::rest::scan_secret_literals(&bytes) {
Ok(findings) if !findings.is_empty() => {
materialization_failure(
"security_scan",
"literal_credentials_rejected",
result.snapshots.len(),
);
result.secret_literal_rejected = true;
break;
}
Ok(_) => {}
Err(_) => {
materialization_failure(
"security_scan",
"invalid_document",
result.snapshots.len(),
);
continue;
}
}
let Ok(references) = crank_import::rest::external_reference_uris(
&document,
&self.external_reference_normalization,
@@ -368,6 +390,14 @@ impl AdminService {
}
let document = String::from_utf8(verified.bytes)
.map_err(|_| ApiError::openapi_upload(locale, "source_integrity"))?;
let findings = crank_import::rest::scan_secret_literals(document.as_bytes())
.map_err(|_| ApiError::openapi_upload(locale, "source_integrity"))?;
if !findings.is_empty() {
return Err(ApiError::openapi_upload(
locale,
"literal_credentials_rejected",
));
}
let digest =
crank_import::rest::SourceDigest::parse(dependency.digest.digest_hex().to_owned())
.map_err(|_| ApiError::openapi_upload(locale, "source_integrity"))?;