fix(security): close the three list endpoints #297 missed (#64)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 5m52s
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 5m52s
A second pass over every `limit`/`page`/`$regex` in the handlers found three the first commit did not cover: - graph symbol search sent `q` to Mongo as a raw regex and took `limit` as an unclamped `usize` from the query string; - the SBOM list used its own `SbomFilter` paging fields without the deserialize-time clamp, so `?limit=10000000` still worked there; - notifications capped `limit` at 200 but allowed it to be negative and left `page` unbounded, so `(page - 1) * limit as u64` could wrap into an enormous skip. All three now use the shared clamp and `literal_regex`, and every handler computes `skip` through one bounded helper. No raw `$regex` on caller input remains in the agent. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
1 parent
924554f397
commit
c33f98ccbc
5 files changed
+39
-17
No files matched your search
@@ -211,12 +211,21 @@ pub struct SbomFilter {
|
||||
pub has_vulns: Option<bool>,
|
||||
#[serde(default)]
|
||||
pub license: Option<String>,
|
||||
#[serde(default = "default_page")]
|
||||
#[serde(default = "default_page", deserialize_with = "de_page")]
|
||||
pub page: u64,
|
||||
#[serde(default = "default_limit")]
|
||||
#[serde(default = "default_limit", deserialize_with = "de_limit")]
|
||||
pub limit: i64,
|
||||
}
|
||||
|
||||
impl SbomFilter {
|
||||
/// Documents to skip for this page. Bounded by construction.
|
||||
pub fn skip(&self) -> u64 {
|
||||
self.page
|
||||
.saturating_sub(1)
|
||||
.saturating_mul(self.limit as u64)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SbomExportParams {
|
||||
pub repo_id: String,
|
||||
@@ -375,6 +384,14 @@ mod tests {
|
||||
assert_eq!(literal_regex(&long).len(), MAX_SEARCH_LEN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sbom_filter_clamps_the_same_way() {
|
||||
let f: SbomFilter = serde_json::from_str(r#"{"limit":10000000,"page":0}"#).unwrap();
|
||||
assert_eq!(f.limit, MAX_PAGE_SIZE);
|
||||
assert_eq!(f.page, 1);
|
||||
assert_eq!(f.skip(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn findings_filter_clamps_the_same_way() {
|
||||
let f: FindingsFilter = serde_json::from_str(r#"{"limit":5000,"page":0}"#).unwrap();
|
||||
|
||||
@@ -43,11 +43,15 @@ pub struct GraphData {
|
||||
#[derive(Deserialize)]
|
||||
pub struct SearchParams {
|
||||
pub q: String,
|
||||
#[serde(default = "default_search_limit")]
|
||||
pub limit: usize,
|
||||
/// Clamped to `1..=MAX_PAGE_SIZE` while deserializing, like every list.
|
||||
#[serde(
|
||||
default = "default_search_limit",
|
||||
deserialize_with = "super::dto::de_limit"
|
||||
)]
|
||||
pub limit: i64,
|
||||
}
|
||||
|
||||
fn default_search_limit() -> usize {
|
||||
fn default_search_limit() -> i64 {
|
||||
50
|
||||
}
|
||||
|
||||
@@ -290,15 +294,11 @@ pub async fn search_symbols(
|
||||
// Simple text search on qualified_name and name fields
|
||||
let filter = doc! {
|
||||
"repo_id": &repo_id,
|
||||
"name": { "$regex": ¶ms.q, "$options": "i" },
|
||||
// Literal substring, not a caller-supplied regex (same fix as #64).
|
||||
"name": { "$regex": super::dto::literal_regex(¶ms.q), "$options": "i" },
|
||||
};
|
||||
|
||||
let nodes: Vec<CodeNode> = match db
|
||||
.graph_nodes()
|
||||
.find(filter)
|
||||
.limit(params.limit as i64)
|
||||
.await
|
||||
{
|
||||
let nodes: Vec<CodeNode> = match db.graph_nodes().find(filter).limit(params.limit).await {
|
||||
Ok(cursor) => collect_cursor_async(cursor).await,
|
||||
Err(e) => {
|
||||
tracing::warn!("Failed to search graph nodes: {e}");
|
||||
|
||||
@@ -40,9 +40,14 @@ pub async fn list_notifications(
|
||||
filter.insert("repo_id", repo_id.as_str());
|
||||
}
|
||||
|
||||
let page = params.page.unwrap_or(1).max(1);
|
||||
let limit = params.limit.unwrap_or(50).min(200);
|
||||
let skip = (page - 1) * limit as u64;
|
||||
// Same bounds as every other list: a negative limit or a huge page used to
|
||||
// wrap `skip` into an enormous offset.
|
||||
let page = params.page.unwrap_or(1).clamp(1, super::dto::MAX_PAGE);
|
||||
let limit = params
|
||||
.limit
|
||||
.unwrap_or(50)
|
||||
.clamp(1, super::dto::MAX_PAGE_SIZE);
|
||||
let skip = (page - 1).saturating_mul(limit as u64);
|
||||
|
||||
let total = db
|
||||
.cve_notifications()
|
||||
|
||||
@@ -99,7 +99,7 @@ pub async fn list_targets(
|
||||
Query(params): Query<PaginationParams>,
|
||||
) -> Result<Json<ApiResponse<Vec<OnboardedTarget>>>, StatusCode> {
|
||||
let db = tenant_db(&agent, &tenant).await?;
|
||||
let skip = (params.page.saturating_sub(1)) * params.limit as u64;
|
||||
let skip = params.skip();
|
||||
let total = db
|
||||
.onboarded_targets()
|
||||
.count_documents(doc! {})
|
||||
|
||||
@@ -104,7 +104,7 @@ pub async fn list_sbom(
|
||||
query.insert("license", license);
|
||||
}
|
||||
|
||||
let skip = (filter.page.saturating_sub(1)) * filter.limit as u64;
|
||||
let skip = filter.skip();
|
||||
let total = db
|
||||
.sbom_entries()
|
||||
.count_documents(query.clone())
|
||||
|
||||
Reference in new issue
Block a user