2025年11月17日 星期一

[研究]GCB,IIS,「表單驗證Cookie 模式」從預設值 UseDeviceProfile 改為 GCB 建議值 UseCookies後那些套件功能會異常?

[研究]GCB,IIS,「表單驗證Cookie 模式」從預設值 UseDeviceProfile 改為 GCB 建議值 UseCookies後那些套件功能會異常?

2025-11-17

政府組態基準(Government Configuration Baseline,簡稱GCB)

TWGCB-04-014_Microsoft IIS 10政府組態基準說明文件v1.1_1141002




IIS 管理員\伺服器\站台\網站\管理\設定編輯器\動作\開啟功能\區段\system.web\authentication\forms\cookieless

表單驗證Cookie 模式 從預設值 UseDeviceProfile 改為 GCB 建議值 UseCookies 的影響?
那些 套件 功能會異常?

AngleSharp 0.17.1
AngleSharp.Css 0.17.0
Antlr 3.5.0.2
Aspose.Cells 25.10.0
Autofac 8.4.0
Autofac.WebApi2 6.1.1
Bootstrap.Datepicker 1.8.0.1
BouncyCastle.Cryptography 2.6.2
ByteSize 2.1.2
Chart.js 3.7.1
ClosedXML 0.105.0
ClosedXML.Parser 2.0.0
Common.Logging 3.4.1
Common.Logging.Core 3.4.1
DocumentFormat.OpenXml 3.3.0
DocumentFormat.OpenXml.Framework 3.3.0
EFUtilities 1.0.2
EntityFramework 6.5.1
Enums.NET 5.0.0
ExcelDataReader 3.8.0
ExcelDataReader.DataSet 3.8.0
ExcelNumberFormat 1.1.0
ExtendedNumerics.BigDecimal 3001.1.0.233
FastMember 1.5.0
FastMember.Signed 1.5.0
Font.Awesome 5.15.4
FontAwesome 4.7.0
FreeDataExports 1.1.12
FreeSpire.PDF 8.6.0
HtmlSanitizer 9.0.876
HtmlSanitizer 9.0.886
Irony 1.5.3
Irony.NetCore 1.1.11
JetBrains.Annotations 2025.2.2
LinqKit 1.3.8
LinqKit.Core 1.2.8
LogicExtensions 0.0.3
MailKit 4.14.1
MathNet.Numerics.Signed 5.0.0
Microsoft.AspNet.FriendlyUrls 1.0.2
Microsoft.AspNet.FriendlyUrls.Core 1.0.2
Microsoft.AspNet.FriendlyUrls.Core.zh-Hant 1.0.2
Microsoft.AspNet.Identity.Core 2.2.4
Microsoft.AspNet.Identity.Core.zh-Hant 2.2.4
Microsoft.AspNet.Identity.EntityFramework 2.2.4
Microsoft.AspNet.Identity.EntityFramework.zh-Hant 2.2.4
Microsoft.AspNet.Identity.Owin 2.2.4
Microsoft.AspNet.Identity.Owin.zh-Hant 2.2.4
Microsoft.AspNet.Providers.Core 2.0.0
Microsoft.AspNet.Providers.Core.zh-Hant 2.0.0
Microsoft.AspNet.ScriptManager.MSAjax 5.0.0
Microsoft.AspNet.ScriptManager.WebForms 5.0.0
Microsoft.AspNet.Web.Optimization 1.1.3
Microsoft.AspNet.Web.Optimization.WebForms 1.1.3
Microsoft.AspNet.Web.Optimization.zh-Hans 1.1.3
Microsoft.AspNet.Web.Optimization.zh-Hant 1.1.3
Microsoft.AspNet.WebApi 5.3.0
Microsoft.AspNet.WebApi.Client 6.0.0
Microsoft.AspNet.WebApi.Client.zh-Hant 6.0.0
Microsoft.AspNet.WebApi.Core 5.3.0
Microsoft.AspNet.WebApi.Core.zh-Hant 5.3.0
Microsoft.AspNet.WebApi.WebHost 5.3.0
Microsoft.AspNet.WebApi.WebHost.zh-Hant 5.3.0
Microsoft.Bcl.AsyncInterfaces 9.0.10
Microsoft.Bcl.Build 1.0.21
Microsoft.Bcl.Cryptography 9.0.10
Microsoft.Bcl.HashCode 6.0.0
Microsoft.CSharp 4.7.0
Microsoft.Extensions.DependencyInjection 9.0.10
Microsoft.Extensions.DependencyInjection.Abstractions 9.0.10
Microsoft.IO.RecyclableMemoryStream 3.0.1
Microsoft.NETCore.Platforms 7.0.4
Microsoft.Owin 4.2.3
Microsoft.Owin.Host.SystemWeb 4.2.3
Microsoft.Owin.Security 4.2.3
Microsoft.Owin.Security.Cookies 4.2.3
Microsoft.Owin.Security.OAuth 4.2.3
Microsoft.Web.Infrastructure 2.0.0
Microsoft.Win32.Primitives 4.3.0
MimeKit 4.14.0
Modernizr 2.8.3
Modernizr.New 3.4.0
Moment.js 2.30.1
NETStandard.Library 2.0.3
NLog 6.0.5
NLog.Schema 6.0.5
NPOI 2.7.5
NReco.PdfGenerator 1.2.1
NSax 1.0.2
Newtonsoft.Json 13.0.4
Newtonsoft.Json.Bson 1.0.3
Npoi.Mapper 6.2.2
Oracle.ManagedDataAccess 23.26.0
Owin 1.0
Portable.BouncyCastle 1.9.0
ProDotNetZip 1.20.0
RBush 4.0.0
RBush.Signed 4.0.0
Respond 1.4.2
RestSharp 106.15.0
RestSharp 112.1.0
Select2.js 4.0.13
SendGrid 9.29.3
SendGrid.CSharp.HTTP.Client 3.4.12
SendGrid.SmtpApi 1.4.6
SharpZipLib 1.4.2
SixLabors.Fonts 1.0.1
SixLabors.ImageSharp 3.1.11
Swashbuckle 5.6.0
Swashbuckle.Core 5.6.0
System.AppContext 4.3.0
System.Buffers 4.6.1
System.Collections 4.3.0
System.Collections.Concurrent 4.3.0
System.Collections.Immutable 9.0.10
System.Configuration.ConfigurationManager 9.0.10
System.Console 4.3.1
System.Diagnostics.Debug 4.3.0
System.Diagnostics.DiagnosticSource 9.0.10
System.Diagnostics.Tools 4.3.0
System.Diagnostics.Tracing 4.3.0
System.Formats.Asn1 9.0.10
System.Globalization 4.3.0
System.Globalization.Calendars 4.3.0
System.IO 4.3.0
System.IO.Compression 4.3.0
System.IO.Compression.ZipFile 4.3.0
System.IO.FileSystem 4.3.0
System.IO.FileSystem.Primitives 4.3.0
System.IO.Packaging 9.0.10
System.IO.Pipelines 9.0.10
System.IO.UnmanagedMemoryStream 4.3.0
System.Linq 4.3.0
System.Linq.Dynamic.Core 1.6.9
System.Linq.Expressions 4.3.0
System.Linq.Queryable 4.3.0
System.Memory 4.6.3
System.Net.Http 4.3.4
System.Net.Primitives 4.3.1
System.Net.Sockets 4.3.0
System.Numerics.Vectors 4.6.1
System.ObjectModel 4.3.0
System.Reflection 4.3.0
System.Reflection.Emit.ILGeneration 4.7.0
System.Reflection.Emit.Lightweight 4.7.0
System.Reflection.Extensions 4.3.0
System.Reflection.Primitives 4.3.0
System.Resources.ResourceManager 4.3.0
System.Runtime 4.3.1
System.Runtime.CompilerServices.Unsafe 6.1.2
System.Runtime.CompilerServices.Unsafe 7.0.0-preview.2.22152.2
System.Runtime.Extensions 4.3.1
System.Runtime.Handles 4.3.0
System.Runtime.InteropServices 4.3.0
System.Runtime.InteropServices.RuntimeInformation 4.3.0
System.Runtime.Numerics 4.3.0
System.Security.AccessControl 6.0.1
System.Security.Cryptography.Algorithms 4.3.1
System.Security.Cryptography.Encoding 4.3.0
System.Security.Cryptography.Pkcs 9.0.10
System.Security.Cryptography.Primitives 4.3.0
System.Security.Cryptography.X509Certificates 4.3.2
System.Security.Cryptography.Xml 9.0.10
System.Security.Permissions 9.0.10
System.Security.Principal.Windows 5.0.0
System.Text.Encoding 4.3.0
System.Text.Encoding.CodePages 9.0.10
System.Text.Encoding.Extensions 4.3.0
System.Text.Encodings.Web 9.0.10
System.Text.Json 9.0.10
System.Text.RegularExpressions 4.3.1
System.Threading 4.3.0
System.Threading.Tasks 4.3.0
System.Threading.Tasks.Extensions 4.6.3
System.Threading.Tasks.Parallel 4.3.0
System.Threading.Timer 4.3.0
System.ValueTuple 4.5.0
System.ValueTuple 4.6.1
System.Xml.Linq 3.5.21022.801
System.Xml.ReaderWriter 4.3.1
System.Xml.XDocument 4.3.0
WebActivatorEx 2.2.0
WebGrease 1.6.0
WkHtmlToPdf 1.0.2
X.PagedList 10.5.9
XLParser 1.7.5
ZString 2.6.0
bootstrap 3.4.1
bootstrap 5.3.8
elmah 1.2.2
elmah.corelibrary 1.2.2
html5-shiv 3.7.3
icheck-bootstrap 3.0.1
jQuery 3.7.1
jQuery-datetimepicker 2.4.5
jQuery.UI.Combined 1.14.1
jQuery.Validation 1.21.0
js-cookie 2.2.1
popper.js 1.16.1
starkbank-ecdsa 1.3.3
vue 2.6.11

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

ChatGPT

1️⃣ 預設值 vs GCB 建議值

設定 含義
UseDeviceProfile (預設) ASP.NET 表單驗證 Cookie 模式會依據瀏覽器特性自動選擇:對不支援 Cookie 的瀏覽器可能改用 URL 參數(cookieless)。
UseCookies (GCB 建議) 強制使用 Cookie 方式儲存表單驗證資訊,不再依瀏覽器支援狀態調整。

重點差異:
  • UseDeviceProfile 會在 URL 中加上 ;s=<session>(cookieless 模式),兼容老舊瀏覽器。
  • UseCookies 只靠 Cookie,無法在不支援 Cookie 的情況下運作。
  • URL 不再附帶驗證資訊,URL 可更乾淨、安全。

2️⃣ 潛在影響

2.1 使用者影響
  • 不支援 Cookie 的瀏覽器或禁用 Cookie 的用戶,登入會失敗。
  • URL 中不再傳驗證 token → 對防止 session 劫持有好處,但舊系統若依賴 URL session 可能出錯。
2.2 開發與套件影響

通常受影響的情境:
  1. 套件或自訂元件直接讀取 URL 中的驗證 token
    • 如某些舊版 FriendlyUrls、AJAX 跨頁套件。
  2. 使用 FormsAuthentication.GetAuthCookie() / FormsAuthenticationTicket 生成 URL
    • 如果程式依賴 cookieless URL 傳遞 ticket → 需要調整。
  3. 跨子網域或跨應用的舊 Session 管理
    • Cookie 限制域名、路徑,需要確認 domain 設定。

3️⃣ 套件影響判斷

對照你列出的套件,我列出可能受影響的類型:

類型 套件 影響可能性 說明
ASP.NET FriendlyUrls / WebForms Microsoft.AspNet.FriendlyUrls / Core / zh-Hant 中高 依 URL 參數辨識頁面或 Session,cookieless 取消可能需要調整。
ASP.NET Identity / Owin Cookie Microsoft.AspNet.Identity.* / Microsoft.Owin.Security.Cookies 現代版本已設計依賴 Cookie,通常安全。
AJAX / 前端表單套件 jQuery / Bootstrap.Datepicker / js-cookie / vue 只要 Cookie 可用,前端操作正常;若有依賴 URL session 的自訂整合才會異常。
PDF / Excel / 檔案套件 Aspose.Cells, FreeSpire.PDF, ClosedXML, ExcelDataReader 與表單驗證 Cookie 無關。
WebAPI / REST 套件 Microsoft.AspNet.WebApi.*, RestSharp, SendGrid WebAPI 通常靠 Token / OAuth,與 FormsAuthentication Cookie 無關。
加密 / 安全套件 BouncyCastle, starkbank-ecdsa 與認證方式無關。
Session / Memory 導向 System.*, FastMember, LinqKit 若程式有自訂 URL 取 Session,可能需要修改;大部分無影響。

結論:
  • 前端 URL 驅動 session 或依賴 cookieless token 的功能最可能異常。
  • 其他大部分套件(資料處理、PDF、Excel、WebAPI、加密)不會受影響。

4️⃣ 建議做法

  • 測試:在測試環境把 cookieless=UseCookies,模擬禁用 Cookie 的瀏覽器行為。
  • 檢查程式碼:
    • 搜尋 FormsAuthentication.RedirectFromLoginPage, FormsAuthenticationTicket 的使用。
    • 確認沒有依賴 URL 中的 SessionId。
  • 設定 Cookie domain/path:若有跨子網域需求,需要調整 <forms domain="..." path="/" />。
  • 記錄異常:針對可能出現登入失敗或 Session 遺失的頁面,加入 log 追蹤。

(完)

沒有留言:

張貼留言