diff --git a/server-rs/crates/spacetime-module/src/error_report.rs b/server-rs/crates/spacetime-module/src/error_report.rs index 56b1e65c3..e0852fba3 100644 --- a/server-rs/crates/spacetime-module/src/error_report.rs +++ b/server-rs/crates/spacetime-module/src/error_report.rs @@ -2,6 +2,9 @@ use crate::*; const MAX_FIELD_CHARS: usize = 512; const MAX_NOTE_CHARS: usize = 2_000; +const MAX_ARCHIVE_SIZE_BYTES: u64 = 20 * 1024 * 1024; +const MAX_EVENT_COUNT: u32 = 100; +const MAX_LOG_COUNT: u32 = 5; const MAX_REPORTS_PER_IDENTITY_PER_HOUR: usize = 100; const REPORT_QUOTA_WINDOW_MICROS: i64 = 60 * 60 * 1_000_000; @@ -155,7 +158,24 @@ pub fn create_error_report_and_return( let submission_id = validate_text(&input.submission_id, "submission_id")?; let idempotency_key = validate_text(&input.idempotency_key, "idempotency_key")?; let object_key = validate_text(&input.object_key, "object_key")?; + if object_key != format!("agc/error-reports/v1/{batch_id}.zip") { + return Err("error_report.object_key 格式无效".to_string()); + } let archive_sha256 = validate_text(&input.archive_sha256, "archive_sha256")?; + if archive_sha256.len() != 64 + || !archive_sha256.bytes().all(|byte| byte.is_ascii_hexdigit()) + { + return Err("error_report.archive_sha256 必须是 64 位十六进制 SHA-256".to_string()); + } + if input.archive_size_bytes == 0 || input.archive_size_bytes > MAX_ARCHIVE_SIZE_BYTES { + return Err("error_report.archive_size_bytes 超出上限".to_string()); + } + if input.event_count == 0 || input.event_count > MAX_EVENT_COUNT { + return Err("error_report.event_count 超出上限".to_string()); + } + if input.log_count > MAX_LOG_COUNT { + return Err("error_report.log_count 超出上限".to_string()); + } if let Some(existing) = tx .db .error_report()