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

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:
Sharang ParnerkarandClaude Opus 5 committed 2026-09-21 12:55:02 +02:00
1 parent 924554f397
commit c33f98ccbc
5 files changed
+39 -17

No files matched your search

+19 -2
View File
@@ -211,12 +211,21 @@ pub struct SbomFilter {
pub has_vulns: Option<bool>, pub has_vulns: Option<bool>,
#[serde(default)] #[serde(default)]
pub license: Option<String>, pub license: Option<String>,
#[serde(default = "default_page")] #[serde(default = "default_page", deserialize_with = "de_page")]
pub page: u64, pub page: u64,
#[serde(default = "default_limit")] #[serde(default = "default_limit", deserialize_with = "de_limit")]
pub limit: i64, 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)] #[derive(Deserialize)]
pub struct SbomExportParams { pub struct SbomExportParams {
pub repo_id: String, pub repo_id: String,
@@ -375,6 +384,14 @@ mod tests {
assert_eq!(literal_regex(&long).len(), MAX_SEARCH_LEN); 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] #[test]
fn findings_filter_clamps_the_same_way() { fn findings_filter_clamps_the_same_way() {
let f: FindingsFilter = serde_json::from_str(r#"{"limit":5000,"page":0}"#).unwrap(); let f: FindingsFilter = serde_json::from_str(r#"{"limit":5000,"page":0}"#).unwrap();
+10 -10
View File
@@ -43,11 +43,15 @@ pub struct GraphData {
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct SearchParams { pub struct SearchParams {
pub q: String, pub q: String,
#[serde(default = "default_search_limit")] /// Clamped to `1..=MAX_PAGE_SIZE` while deserializing, like every list.
pub limit: usize, #[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 50
} }
@@ -290,15 +294,11 @@ pub async fn search_symbols(
// Simple text search on qualified_name and name fields // Simple text search on qualified_name and name fields
let filter = doc! { let filter = doc! {
"repo_id": &repo_id, "repo_id": &repo_id,
"name": { "$regex": &params.q, "$options": "i" }, // Literal substring, not a caller-supplied regex (same fix as #64).
"name": { "$regex": super::dto::literal_regex(&params.q), "$options": "i" },
}; };
let nodes: Vec<CodeNode> = match db let nodes: Vec<CodeNode> = match db.graph_nodes().find(filter).limit(params.limit).await {
.graph_nodes()
.find(filter)
.limit(params.limit as i64)
.await
{
Ok(cursor) => collect_cursor_async(cursor).await, Ok(cursor) => collect_cursor_async(cursor).await,
Err(e) => { Err(e) => {
tracing::warn!("Failed to search graph nodes: {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()); filter.insert("repo_id", repo_id.as_str());
} }
let page = params.page.unwrap_or(1).max(1); // Same bounds as every other list: a negative limit or a huge page used to
let limit = params.limit.unwrap_or(50).min(200); // wrap `skip` into an enormous offset.
let skip = (page - 1) * limit as u64; 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 let total = db
.cve_notifications() .cve_notifications()
@@ -99,7 +99,7 @@ pub async fn list_targets(
Query(params): Query<PaginationParams>, Query(params): Query<PaginationParams>,
) -> Result<Json<ApiResponse<Vec<OnboardedTarget>>>, StatusCode> { ) -> Result<Json<ApiResponse<Vec<OnboardedTarget>>>, StatusCode> {
let db = tenant_db(&agent, &tenant).await?; 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 let total = db
.onboarded_targets() .onboarded_targets()
.count_documents(doc! {}) .count_documents(doc! {})
+1 -1
View File
@@ -104,7 +104,7 @@ pub async fn list_sbom(
query.insert("license", license); query.insert("license", license);
} }
let skip = (filter.page.saturating_sub(1)) * filter.limit as u64; let skip = filter.skip();
let total = db let total = db
.sbom_entries() .sbom_entries()
.count_documents(query.clone()) .count_documents(query.clone())