From 907bba9bf00107a683d523206a477e684b20f68d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=BE=B7=E5=AE=87?= Date: Wed, 2 Sep 2026 19:09:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E7=B4=A7=E9=94=99=E8=AF=AF=E6=8A=A5?= =?UTF-8?q?=E5=91=8A=E5=85=83=E6=95=B0=E6=8D=AE=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 限制 OSS object key、SHA-256、归档大小及事件日志计数 在开发期直接启用新校验,不增加迁移兼容层 --- .../spacetime-module/src/error_report.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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()