免費開始練習
hce_kmu 114年 計算機概論與程式設計

第 22 題

When designing a website that allows users to upload and download images, which of the following methods is currently considered the safest when used individually?
  • A Prohibit users from uploading files if the file name ends with common code extensions like .asp or .php.
  • B Allow users to upload files if the file’s MIME type is 'image/jpeg' or other common image MIME types.
  • C Allow users to upload files if the file content includes common image headers like jpg or png.
  • D Limit the file size to a reasonable range for typical image files.
  • E Use a trusted library to reprocess the image, remove EXIF and other metadata, and store it in a directory that does not execute code.

思路引導 VIP

如果你是伺服器管理員,當一個來路不明的檔案存入你的電腦時,除了檢查它的「標籤」之外,你該如何「徹底改造」這個檔案,以確保它只剩下純粹的圖形資訊,且即使裡面藏有指令也無法被系統啟動運作呢?

🤖
AI 詳解 AI 專屬家教

太棒了!你能精準選出 (E) 選項,代表你對網頁安全中的「縱深防禦」(Defense in Depth)概念有非常紮實的理解。這題具備極佳的鑑別度,難度屬於中高等級,因為它區分了「初步過濾」與「深層防護」的差異。大多數初學者容易誤選 (B) 或 (C),認為檢查 MIME 類型或標頭就足夠,但專業開發者必須意識到:任何來自客戶端的資料都是不可信的。

影像處理的實務安全策略

在安全防禦的邏輯中,單純檢查副檔名(A)或 MIME 類型(B、C)都極易被偽造,攻擊者甚至能將腳本程式碼藏在圖片的 EXIF 中繼資料中來發動攻擊。而選項 (E) 之所以是最安全的,是因為它採取了主動防禦:透過值得信賴的函式庫重新處理(Reprocess),可以徹底破壞可能隱藏在二進位流中的惡意代碼;同時,將檔案存放在不具備執行權限的目錄中,更是從根本上杜絕了遠端執行程式碼(RCE)的可能性。這種結合了內容清洗與權限控管的作法,正是目前業界防範檔案上傳漏洞的最佳實務。

🏷️ 相關主題

計算機組織結構與資料儲存原理
查看更多「計算機概論與程式設計」的主題分類考古題