GSS 技術部落格
在這個園地裡我們將從技術、專案管理、客戶對談面和大家分享我們多年的經驗,希望大家不管是喜歡或是有意見,都可以回饋給我們,讓我們有機會和大家對話並一起成長!
若有任何問題請來信:gss_crm@gss.com.tw
字體大小: +
2 分鐘閱讀時間 (401 個字)

ASP.NET MVC處理 Checkmarx Information Exposure via Headers 問題

Information Exposure via Headers

在 ASP.NET 專案中,預設狀態下伺服器會自動在 Response Headers 中加入許多資訊性標頭,例如:

  • Server

  • X-AspNet-Version

  • X-AspNetMvc-Version

  • X-Powered-By

這些 Header 會洩露底層伺服器與框架版本,對有心人士來說,等同於公開潛在攻擊目標,有助於精確選擇攻擊手法。因此,在進行資安檢測時,常見如 Checkmarx 這類工具,會特別針對這些 Header 給予警告(Information Exposure via Headers)。

Checkmarx 掃描規則重點

Checkmarx 的 Information_Exposure_via_Headers 這條規則,要求專案必須在程式碼中明確處理 Header 移除,常見的要求包括:

Global.asax.cs 實作 Application_PreSendRequestHeaders 方法

必須直接於此事件內呼叫 HttpContext.Current.Response.Headers.Remove 移除如 ServerX-Powered-By 等標頭。例如:

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("Server");
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
// 其他初始化程式碼...
}

於 Application_Start 設定 MVC 回應標頭為停用

MvcHandler.DisableMvcResponseHeader 設為 true,防止 X-AspNetMvc-Version 出現在 Response Headers:

protected void Application_Start()
{
MvcHandler.DisableMvcResponseHeader = true;
// 其他初始化程式碼...
}

Checkmarx 掃描「只看程式」不看實際 Header

即使你確實已經透過 IIS 設定或其他方式移除這些 Header,Checkmarx 還是只會看 Global.asax.cs 是否有這些程式碼,跟實際網頁回傳什麼 Header 完全無關。

結論

要讓 Checkmarx Information_Exposure_via_Headers 掃描通過,一定要在程式碼裡面明確寫出移除 Header 的程式,如上所示。實務上,除了要確實移除 Header,還要寫「Checkmarx 想看的程式碼」,才能避免自動掃描誤報。

×
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

ABP Web專案整合 Azure Active Directory 驗證教學
如何用 C.ai 打造發票掃描 AI 機器人

相關文章

 

評論

尚無評論
已經注冊了? 這裡登入
2025年10月08日, 星期三

Captcha 圖像