Security

Xss : 跨網站腳本,在網站中,可以輸入js語法,取得cookies、token或轉址方式

https://docs.microsoft.com/zh-tw/aspnet/core/security/cross-site-scripting?view=aspnetcore-3.1

XSRF or CSRF : 跨站請求偽造 https://zh.wikipedia.org/wiki/%E8%B7%A8%E7%AB%99%E8%AF%B7%E6%B1%82%E4%BC%AA%E9%80%A0

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

XSRF or CSRF 對request的請求,可以偽照送回server端,大部份的framework有處理,使用圖形驗證碼、簡訊驗證碼、csrfToken

Mvc : 防偽權杖,也稱為要求驗證權杖 --@Html.AntiForgeryToken,action : ValidateAntiForgeryToken

CA3147 : httpGet 不用上 Token , https://docs.microsoft.com/zh-tw/visualstudio/code-quality/ca3147?view=vs-2019 

angularjs : AngularJS 會使用慣例來定址 CSRF。 如果伺服器傳送名稱為 XSRF-TOKEN的 cookie,則 AngularJS $http 服務會在將要求傳送至伺服器時,將 cookie 值新增至標頭。 此程式是自動的。

angular : HttpClient 支援的只是 XSRF 防護方案的客戶端這一半。 你的後端服務必須配置為給頁面設定 cookie ,並且要驗證請求頭,以確保全都是合法的請求。否則,Angular 預設的這種防護措施就會失效。

https://angular.tw/guide/http#security-xsrf-protection

webapi : 此外,使用 SSL 並不會防止 CSRF 攻擊,因為惡意網站可以傳送「HTTPs://」要求。 https://github.com/spboyer/webapi-antiforgery

1.IServiceCollection Add AddAntiforgery,及設定 HeaderName

2.Configure 設定每個Route的 Response,產生cookie的XSRF_TOKEN,供間接webapi使用

3.Http Put、Post、Delete的Action上增加ValidateAntiForgeryToken property

4.間接WebApi的 Headers,上加入 key : 1. HeaderName,及cookie的XSRF_TOKEN值

https://docs.microsoft.com/zh-tw/aspnet/web-api/overview/security/preventing-cross-site-request-forgery-csrf-attacks

Description : https://blog.techbridge.cc/2017/02/25/csrf-introduction/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

razor : JavaScriptEncoder.Encode

angular : 為了系統性的防範 XSS 問題,Angular 預設把所有值都當做不可信任的。 當值從範本中以屬性(Property)、DOM 元素屬性(Attribte)、CSS 類繫結或插值等途徑插入到 DOM 中的時候, Angular 將對這些值進行無害化處理(Sanitize),對不可信的值進行編碼。

mvc : 在基本層級 XSS 的運作方式是將您的應用程式,藉由將 <script> 標記插入轉譯的頁面中,或將 On* 事件插入元素中。

ref : 

https://docs.microsoft.com/zh-tw/aspnet/core/security/cross-site-scripting?view=aspnetcore-3.1

https://kevintsengtw.blogspot.com/2013/09/aspnet-mvc-csrf-ajax-antiforgerytoken.html

https://docs.angularjs.org/api/ng/service/$http

https://angular.tw/guide/security