[研究]SameSite用Chrome檢視
2025-05-06
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 20.2
********************************************************************************
Web.Config 內容
<?xml version="1.0" encoding="utf-8"?>
<!--
如需如何設定 ASP.NET 應用程式的詳細資訊,請前往
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.8" />
<httpRuntime targetFramework="4.8" />
<httpCookies httpOnlyCookies="true" sameSite="Strict" requireSSL="true" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
|
********************************************************************************
✅ 方法一:Application → Cookies(最清楚)
-
開啟你的網站
-
按
F12 開啟 DevTools
-
切到 Application
-
左側找到:
-
右側會看到表格欄位,其中包含:
-
Name
-
Value
-
Domain
-
Path
-
SameSite ← 重點
-
Secure
-
HttpOnly
SameSite 會顯示:
-
Lax
-
Strict
-
None
-
(空白 = 沒設定)
實際測試
✅ 方法二:Network → Response Header(最具「證據力」)
這個方法是你要「證明有設定」,比 Web.config 更有說服力 👍
-
開啟 DevTools → Network
-
重新整理頁面(F5)
-
點選任一 request(通常選主頁或 login)
-
切到 Headers
-
找:
例如你會看到:
👉 重點是:
-
SameSite=Lax / Strict / None
-
如果完全沒有 → 就是弱掃說的問題
下圖,實際測試,雖然有一些 Set 資訊,但沒有 Set-Cookie,比較有相關的是MySameSiteCookie=CookieValue
根據上面測試,ASP.NET WebForm + .NET Framework 4.8 的網站,Web.Config 雖然有設定 sameSite,但直接用 Chrome 是看不出來的。
和 ChatGPT 討論,
❌ 沒看到 Set-Cookie → 不代表沒設定 SameSite
如果首頁沒有做這些事:
-
沒用 Session
-
沒登入(FormsAuth)
-
沒手動寫 Cookie
👉 就不會送:
********************************************************************************
修改 Default.aspx.cs
using System;
using System.Web;
namespace WebApplication1
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Cookies.Add(new HttpCookie("TestCookie", "1")
{
SameSite = SameSiteMode.Strict,
Secure = true,
HttpOnly = true
});
}
}
}
|
這次可以看到
也就是檢測有無看到 SameSite 設定,不能當作有無做 SameSite 的依據。
(完)
相關
沒有留言:
張貼留言