顯示具有 Mend 標籤的文章。 顯示所有文章
顯示具有 Mend 標籤的文章。 顯示所有文章

2026年6月16日 星期二

[研究]Mend(WhiteSource)建議了不合理的for避免SQL Injection

[研究]Mend(WhiteSource)建議了不合理的for避免SQL Injection

2026-06-16


其中 choiceIDs 是 id=1 OR id=9 OR、、、的字串。

(完˙)

2026年6月12日 星期五

[研究]Mend(WhiteSource)建議了不合理的foreach避免SQL Injection

[研究]Mend(WhiteSource)建議了不合理的foreach避免SQL Injection

2026-06-12

Mend 建議把


SqlCommand command = new SqlCommand(sqlCommandString, conn); conn.Open();

改成


SqlCommand command = new SqlCommand(sqlCommandString, conn); foreach (string id in choiceIDs.Split(',')) { command.Parameters.AddWithValue("@id", id); } conn.Open();

因為同一個 SqlCommand.Parameters 集合裡面,參數名稱必須唯一,添加的名稱都是相同@id,這不合理,會導致 Exception。

(完)

[研究]Mend(WhiteSource)誤判NuGet 安裝 vue 的 .nupkg 有問題,砍掉會怎樣?

[研究]Mend(WhiteSource)誤判NuGet 安裝 vue 的 .nupkg 有問題,砍掉會怎樣?

2026-06-12

*****

.nupkg 通常只是 NuGet 套件安裝檔(壓縮包),並不是網站執行時實際使用的檔案。

刪掉:

不會影響

  • ASP.NET 網站執行
  • Vue.js 載入
  • IIS 運作
  • 瀏覽器執行 Vue

因為實際使用的是:

/Scripts/vue.js

/Scripts/vue.min.js

不在 packages 目錄

**********

敝人實際測試砍掉 vue.2.6.11.nupkg,用 Visual Studio 開啟方案操作後,vue.2.6.11.pkg 又自動建立回去。

Git 上傳時,因 packages 目錄都沒上傳, vue.2.6.11.nupkg 自然沒上傳。

詢問AI,

一般情況下,Fortify SAST(Fortify Static Code Analyzer, SCA)不會像 Visual Studio 或 NuGet 那樣自動幫你下載缺少的 packages 目錄。

一般情況下,Mend 通常不會主動幫您執行 NuGet Restore,也不會自動編譯 ASP.NET WebForm 專案。

因為 Jenkins 有設定

nuget.exe restore .\WebApplication1\WebApplication1.sln

會在 Jenkins Server 主機重新下載 packages 目錄所有檔案。

(完)


2026年6月11日 星期四

[研究]Mend (WhiteSource)對 Path Traversal建議導致程式異常

[研究]Mend (WhiteSource)對 Path Traversal建議導致程式異常

2025-06-11

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2

********************************************************************************

因為 Path/Directory Traversal,Mend建議把


string fileName = fd + FileUpload1.FileName;
ㄍㄞ

改成


string fileName = fd + FileUpload1.FileName; string normalizedPath = Path.GetFullPath(fileName); if (!normalizedPath.StartsWith(fd)) { throw new InvalidOperationException("Invalid file path."); }

結果功能異常。

********************************************************************************

做了些研究,

(1)參考這篇 (此狀況下,非必須改)

[研究]Web.Config 中路徑變數最後要加上 倒斜線嗎 ?
https://shaurong.blogspot.com/2026/06/webconfig.html

路徑結合推薦用 string file = Path.Combine(folder, "test.jpg");

(2)Path.GetFullPath 能正規化路徑,Mend 只對 fileName 做,沒對 fd 做。

程式改成下面


string fileName = fd + FileUpload1.FileName; string normalizedPath = Path.GetFullPath(fileName); if (!normalizedPath.StartsWith(GetFullPath(fd)))
{ throw new InvalidOperationException("Invalid file path."); }

結果功能異常。

實際測試正常了ˊ。

(完)

相關

2026年6月10日 星期三

[研究]Mend(WhiteSource)因XSS增加HttpUtility.HtmlEncode成功比例

[研究]Mend(WhiteSource)因XSS增加HttpUtility.HtmlEncode成功比例

2026-06-10

Mend(WhiteSource)因Cross-Site Scripting (XSS) 增加所建議的HttpUtility.HtmlEncode程式碼,

掃描隔天看,一堆還是說有弱點,



66個被報告仍有54個有弱點,成功率 18%,失敗率 82%,

Mend 亂改把 HTML Tag 包入 HttpUtility.HtmlEncode 的有 9個 (昨天發現後就改正了),Mend 亂改導致結果錯誤佔 13.63%。

而且說有弱點,給不出建議。

(完)

[研究]Mend(WhiteSource)為何連 ASP.NET WebForm 專案排除但未刪除的檔案都在掃瞄 ? Fortify SAST (SCA) 就不會 ?

[研究]Mend(WhiteSource)為何連 ASP.NET WebForm 專案排除但未刪除的檔案都在掃瞄 ? Fortify SAST (SCA) 就不會 ?

2026-06-10

Fortify SAST(SCA)通常以 Visual Studio 專案(.csproj/.sln) 為主。

它會依照:

<Compile Include="xxx.cs" />

<Content Include="xxx.aspx" />

來決定哪些檔案屬於專案。

因此:

  • 不在 .csproj 的檔案
  • 不參與 Build 的檔案

通常不會進入分析範圍。

*****

Mend SAST / Mend Code

很多情況下採用的是:檔案系統掃描(Filesystem Scan)

而非:MSBuild 專案掃描(Project Scan)

因此它會直接掃描:

D:\Project\

    aaa.cs

    bbb.cs

    old\

       test.aspx

只要副檔名符合規則:

*.cs

*.vb

*.aspx

*.js

*.ts

就可能被分析。

*****

如何避免?

方法 1:直接刪除

方法 2:設定 Mend Ignore

Mend 通常支援:

.mendignore

方法 3:將備份移出 Repository

(完)

[研究]Mend(WhiteSource)因SQL Injection亂改TSQL內容、亂改foreach結構

[研究]Mend(WhiteSource)因SQL Injection亂改TSQL內容、亂改foreach結構

2026-06-10



亂改(1) whereString 字串變數直接被抽掉,程式結果就不對。

亂改(2) 直接做了新的 foreach 內容,原來的被往下擠出 foreach

(完)

[研究]Mend (WhiteSource)用Server.HtmlEncode取代HttpUtility.HtmlEncode依然有問題且沒建議

[研究]Mend (WhiteSource)用Server.HtmlEncode取代HttpUtility.HtmlEncode依然有問題且沒建議

2026-06-10


下圖,Mend 給不出建議


(完)

2026年6月9日 星期二

[研究]Mend(WhiteSource)把不該做HttpUtility.HtmlEncode的
處理掉了

[研究]Mend(WhiteSource)把不該做HttpUtility.HtmlEncode的<br />處理掉了

2025-06-08

環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2

********************************************************************************
.cs 內容


//lblError.Text = lblError.Text + "匯入 " + affectRow.ToString() + " 筆<br />"; //lblError.Text = HttpUtility.HtmlEncode(lblError.Text + "匯入 " + affectRow.ToString() + " 筆<br />"); //Mend亂建議,上面應該改成下面 lblError.Text = HttpUtility.HtmlEncode(lblError.Text + "匯入 " + affectRow.ToString() + " 筆") + "<br />";

(完)

[研究]Mend (WhiteSource) 不明原因突然掛了

[研究]Mend (WhiteSource) 不明原因突然掛了

2026-06-09

雲端Mend (WhiteSource) 不明原因突然掛了,不過沒幾秒又正常了。(可能不到10秒,甚至5秒)


(完)

[研究]Mend (WhiteSource)能分辨 ASP.NET WebForm 和 MVC嗎?Fortify SAST (SCA) 、Checkmarx呢?

[研究]Mend (WhiteSource)能分辨 ASP.NET WebForm 和 MVC嗎?Fortify SAST (SCA) 、Checkmarx呢?

2026-06-09

Mend (WhiteSource) 對 ASP.NET WebForm 專案卻建議用 MVC 才有的 IsLocalUrl() 進行修改,Mend 不認得專案是 WebForm 或 MVC ? Fortify SAST (SCA) 源碼掃描可以認得 ? Checkmarx 源碼掃描可以認得 ?

*****

是的,這種情況其實很常見。

Mend(前身 WhiteSource)許多安全規則是以 Pattern Matching(模式比對) 或 Framework-Agnostic(框架無關) 的方式運作,因此有時候會出現:

  • ASP.NET WebForm 專案
  • 掃描結果卻建議使用 MVC 的 Url.IsLocalUrl()
  • 或建議使用 ASP.NET Core 的 API

這不代表程式一定有問題,而是 Mend 的 Rule Engine 偵測到「Open Redirect 風險」,然後套用了通用修復建議。

**********

Mend 是否能分辨 WebForm / MVC?

理論上可以部分辨識:

  • .aspx → WebForm
  • .cshtml → MVC/Razor
  • Controller 類別
  • Page 類別

但實務上:修補建議(Remediation Guidance)通常是共用的。

**********

Fortify SAST (SCA) 呢?

Fortify 比較強。

它有:

  • ASP.NET WebForms Rules
  • ASP.NET MVC Rules
  • ASP.NET Core Rules

能分析:

public partial class Login : System.Web.UI.Page

知道是 WebForm。

**********

Checkmarx 呢?

Checkmarx 介於兩者之間。

它的 C# Query Engine 能辨識:

  • WebForm
  • MVC
  • ASP.NET Core

**********

三者比較

項目 Mend Fortify SAST (SCA) Checkmarx
分辨 WebForm/MVC 部分 很好 好
Data Flow Analysis 較弱 很強 很強
Open Redirect 偵測 有 有 有
修補建議是否依框架調整 經常不準 通常準確 多半合理
ASP.NET WebForm 支援 基本 完整 完整
誤給 MVC API 建議 常見 少見 偶爾

**********

若 Mend 建議:Url.IsLocalUrl(returnUrl)

那幾乎可以判定:Mend 是套用了通用 Open Redirect 修補範本,沒有依據 WebForm 產生專屬修補建議。

(完)

[研究]Mend (WhiteSource) 建議密碼欄位 HtmlEncode 疑問

[研究]Mend (WhiteSource) 建議密碼欄位 HtmlEncode 疑問

2026-06-09

下圖,Mend (WhiteSource) 建議密碼欄位 HtmlEncode

但依據下面這篇,是不建議的

[研究]Mend (WhiteSource) 喜歡用的 HttpUtility.HtmlEncode 會影響那些字元?https://shaurong.blogspot.com/2026/06/mend-whitesource-httputilityhtmlencode.html

(完)

[研究]Mend (WhiteSource) 喜歡用的 HttpUtility.HtmlEncode 會影響那些字元?

[研究]Mend (WhiteSource) 喜歡用的 HttpUtility.HtmlEncode 會影響那些字元?

2026-06-09

續

[研究]Mend (WhiteSource) 包含 HTML Tag 字串,照建議用HttpUtility.HtmlEncode改完功能異常https://shaurong.blogspot.com/2026/06/mend-whitesource-html-tag.html

Mend (WhiteSource) 喜歡建議用 HttpUtility.HtmlEncode,也不管實際上該字串是否包含會被轉換掉,導致程式異常。

就算程式前一行已經明確給了包含 HTML Tag 的字串,也照樣推薦。

HttpUtility.HtmlEncode 會影響那些字元?

字元類型 是否通常被 HtmlEncode 改變
繁體中文字 否
簡體中文字 否
日文 否
韓文 否
全形中文標點 否
半形冒號 : 否
半形逗號 , 否
< 是
> 是
& 是
" 是
' 是

情境 HtmlEncode
Label.Text 顯示使用者輸入 ✓ 建議
Literal.Text 顯示使用者輸入 ✓ 建議
Response.Write 使用者輸入 ✓ 建議
Session 值顯示到畫面 ✓ 建議
SQL 參數 ✗ 無關(用 Parameterized Query)
密碼驗證 ✗ 不建議
Hash 計算 ✗ 不建議
URL 參數 ✗ 改用 HttpUtility.UrlEncode()

(完)


2026年6月8日 星期一

[研究]Mend (WhiteSource) 包含 HTML Tag 字串,照建議用HttpUtility.HtmlEncode改完功能異常

[研究]Mend (WhiteSource) 包含 HTML Tag 字串,照建議用HttpUtility.HtmlEncode改完功能異常

2026-06-08


ASP.NET WebForm,Mend (WhiteSource) 


if (Sample.IndexOf("附表1")>=0) { Item2 += " (<a href=/Manage/Attach1.aspx target=blank>附表1</a>)"; Label_Item2.Text = Item2; }

Mend (whiteSource) 建議把


Label_Item2.Text = Item2;

改為


Label_Item2.Text = HttpUtility.HtmlEncode(Item2);

*****

原本正常輸出


附表內容 (<a href=/Manage/Reply.aspx target=blank>附表1</a>)

照 Mend 改完變成 


附表內容 (&lt;a href=/Manage/Reply.aspx target=blank&gt;附表1&lt;/a&gt;)

功能異常

(完)

[研究]Mend(WhiteSource)建議 Session 用 HttpUtility.HtmlEncode,仍說有問題,但無建議

[研究]Mend(WhiteSource)建議 Session 用 HttpUtility.HtmlEncode,仍說有問題,但無建議

2026-06-08

ASP.NET WebForm,Mend (WhiteSource) 建議

Literal1.Text = Literal1.Text + "-" + (string)Session["MyName"];

改成

Literal1.Text = Literal1.Text + "-" + HttpUtility.HtmlEncode((string)Session["MyName"]);

改完後又說

A sensitive sink function was discovered. It causes a High severity Cross-Site Scripting vulnerability.

而建議是

No remediation was suggested by the AI. This may indicate that the finding is a false positive.

原本是 High,照建議修改後,還是 High。

*****

下圖,


下圖,照建議改完後,仍說有問題,但給不出建議。


(完)


[研究]Mend (WhiteSource) 第8次修改建議

[研究]Mend (WhiteSource) 第8次修改建議

2026-06-05

已經照Mend (WhiteSource)建議修改7次了,又來第8次修改建議。


Mend 掉入死迴圈了,一直堅持建議一個錯誤不能用的程式。

(完)

[研究]Mend (WhiteSource) 第7次修改建議

[研究]Mend (WhiteSource) 第7次修改建議

2026-06-05

已經照Mend (WhiteSource)建議修改6次了,又來第7次修改建議。


(1)提供的程式不能用

前人寫程式,Url 其實是字串變數。

(2) Mend 建議用的 IsLocalUrl() 根本不是 ASP.NET WebForm 提供的,是 ASP.NET MVC 的。

[研究]Mend(WhiteSource) 建議使用不認得的 IsLocalUrl
https://shaurong.blogspot.com/2026/05/mendwhitesource-islocalurl.html


(完)

[研究]Mend (WhiteSource) 第6次修改建議

[研究]Mend (WhiteSource) 第6次修改建議

2026-06-05

已經照Mend (WhiteSource)建議修改5次了,又來第六次修改建議。

(完)