Security / DevTools / Open Source
Google Magika:用 AI 判斷檔案真實內容類型,補上副檔名與 MIME 偵測的盲點
Threads @allenhsu3 分享 Google Magika:AI-powered file content type detection,可判斷檔案真實內容,避免惡意 PDF 或偽裝副檔名的 script。查證 GitHub google/magika:約 17.6k stars、Apache-2.0、Python/Rust/JS/Go bindings;README 稱模型僅數 MB、CPU 毫秒級、以約 100M samples / 200+ content types 訓練,在測試集平均約 99% precision/recall,Google 用於 Gmail/Drive/Safe Browsing routing,也整合 VirusTotal/abuse.ch。
2026年7月25日1 分鐘閱讀👁 6
Security × File Type Detection × AI Classifier
副檔名會騙人;Magika 看的是檔案內容本身
Magika 是 Google 開源的 AI-powered file type detection 工具,用來快速判斷檔案真實內容類型,讓安全掃描與內容政策處理能送到正確 pipeline。
| 項目 | 查證結果 |
|---|---|
| Repo | google/magika |
| Stars / forks | 約 17,557 stars、1,092 forks。 |
| License | Apache-2.0。 |
| 語言 / binding | CLI(Rust)、Python API、Rust、JavaScript/TypeScript、Go WIP。 |
| 模型與資料 | README 稱模型數 MB、CPU 毫秒級;約 100M samples、200+ content types;測試集約 99% precision/recall。 |
| 實務使用 | Google 用於 Gmail、Drive、Safe Browsing 的 scanner routing;整合 VirusTotal 與 abuse.ch。 |
適合放在哪些流程
- 上傳入口:不要只信副檔名或 Content-Type header。
- 郵件附件掃描:先判定真實類型,再送對應 scanner。
- 資料湖治理:混雜檔案進 S3/Blob storage 前先分類。
- Agent 工具安全:AI agent 讀檔前先識別是否為 script、binary、archive、document。
安全 caveat:Magika 是 file type detector,不是 malware scanner。它能幫你識別「這其實是什麼檔」,但不能單獨判斷「是否惡意」。正確做法是把它放在多層掃描 pipeline 的前段。