Skip to content

資訊揭露:client 的 model 字串未驗證即組路徑(存在性 oracle)+錯誤訊息回傳本機絕對路徑 #172

Description

@kiki830621

Problem

#165 的 verify 中,security lens 在被 sweep 觸及的檔案內發現兩項既有(非本次引入)的資訊揭露問題。因為它們不屬於 #165 的修復範圍、又會隨該 PR 的 rework 一起被翻動,單獨開案避免遺失。

Source: verify report

Type

bug

Priority

P2。皆非遠端可利用的高風險漏洞,但都會把本機檔案系統資訊洩漏給 MCP client。

Actual

一、client 提供的 model 字串直接進 appendingPathComponent

Sources/BestASRKit/Engines/WhisperCppEngine.swift 的模型路徑組裝:

let modelFile = modelDirectory.appendingPathComponent(
    Self.modelFileName(model: options.model, quantization: options.quantization))

options.model / options.quantization 來自 client(MCP transcribe 參數)。modelFileName 只做字串插值(ggml-\(model)-\(quant).bin),無任何路徑元素驗證。

../ 的 model 字串可跳出 modelDirectory。真正的影響不是任意讀檔(後續只把路徑交給 whisper-cli),而是檔案存在性 oracle:路徑不存在時錯誤訊息會回傳完整的預期路徑,存在時則進入下一階段——足以逐一探測本機檔案是否存在。

二、錯誤訊息新增 executable 絕對路徑並回傳給 client

#165SubprocessRunner 把錯誤訊息從 cannot launch adapter '<exe>' 改成含完整 executable 路徑的形式,且 timeout 訊息也新增了 '<exe>'。這些訊息會沿 MCP 回到 client,洩漏本機安裝路徑(含使用者家目錄名)。

(此項嚴格說是 #165 引入的措辭變更,但屬同一類資訊揭露,一併處理。)

Expected

  • model / quantization 在組路徑前驗證:拒絕含路徑分隔符與 .. 的值(allow-list 字元集為佳)
  • 模型不存在的錯誤訊息不回傳完整絕對路徑,改回傳相對於 modelDirectory 的檔名 + 一般性指引
  • 面向 client 的錯誤訊息移除本機絕對路徑;完整路徑只寫 server 端 log

Residue

未稽核其他 engine 是否有同類的 client 字串 → 路徑組裝(本次只查了 WhisperCppEngine,因為它落在 sweep 範圍內)。若要完整,需對所有接受 client 字串的路徑組裝點做一輪。

相關

  • #165 — 發現脈絡(verify)
  • #170 / #171 — 同批 follow-up 的另外兩軸

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions