Skip to content

Input hardening: DateParseError input truncate + since/until range sanity check #10

@kiki830621

Description

@kiki830621

Problem

Finding C1: DateParseError.description 可 reflect 任意長度 input

From verification of #5, #6 by security reviewer:
「可 reflect 任意長度 input → 建議 truncate 到 128 chars 防 response-size amplification」

雖然 MCP JSON response 有 newline-delimited frame,不會因為 input 長導致 injection,但呼叫端送 1MB string 會讓 errorResult body 也變 1MB,amplification 層面的 minor concern。

Finding C2: 缺 since_date > until_date 語意檢查

From verification of #5, #6 by security reviewer:
「缺 since_date > until_date 語意檢查:功能正確性問題,非安全」

使用者傳入 since_date: "2026-12-31", until_date: "2026-01-01" 目前會靜默回傳空陣列(filter 永遠排除),無錯誤提示。

Type

enhancement

Expected

  • DateParseError 顯示 input 截斷到 128 chars("abc..." 附省略標示)
  • handler 層加 if since > until → errorResult("since_date must be earlier than until_date")

Code Reference

  • Sources/CheTelegramAllMCPCore/DateParsing.swift:5-12 (truncate)
  • Sources/CheTelegramAllMCPCore/Server.swift:358-361, 488-491 (sanity check)

Related: #5, #6

Implementation history

  • 2026-04-27: C1 truncate at 128 chars + marker (commit e7a9515)
  • 2026-04-27: C2 added validateDateRange(_:_:) shared helper + 5 tests (commit d58f6b2)
  • 2026-04-27: validation moved to parser layer (HandlerArgs) not handler layer (Server)
  • 2026-04-27: verify-DA F2/F3 in-scope fix (commit 67451ef) — extended truncation to all errorResultFromParse messages + CHANGELOG precedence note

Current Status

Phase: closed
Last updated: 2026-04-27 by idd-close

Key Decisions

Scope Changes

  • F2 in-scope fix expanded protection to all error message paths
  • F3 in-scope fix documented behavior change

Blocking

(none)

Test counts

  • Batch total: 163 → 180 (+17)
    • +4 truncation, +5 since/until, +6 HandlerGlueTests, +2 verify-DA F2 cap

Commits

Follow-up (verify-DA)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions