2017年1月26日 星期四
Angular2-RC4 animate error
執行 angular2 RC4 版本的 web,之前都正常,
近日突然發生以下錯誤訊息,導致網頁無法正常執行∶
EXCEPTION: Error during instantiation of AnimationDriver! (ViewUtils -> RootRenderer -> DomRootRenderer -> AnimationDriver
執行環境是 firefox ,我的版本是 50.1 (隨時在更新),
剛好同事有較舊本的 firefox ,測試正常,更新後即發生一樣的錯誤狀況,
只好請出 google 找辦法,
( 不要問我為什麼不升級 QQ )
還好有人遇到類似的問題,
將 html 引用 <script...></script> 通通放到 </body> 的上面,就解決了,過關!!
參考∶ JSPM Angular2-rc2 build animate error
visual studio code debug for nodejs + express + consign
撰寫 nodejs 在 visual studio code 進行 debug,
可以參考∶ Node.js Applications with VS Code
簡單來說會在專案根目錄新增 .vscode 資料夾,再新增 launch.js 檔
並在 configurations/program 指定起啟程式,即可進行斷點除錯,如下圖
環境說明∶
- 關於 express server 端的程式碼皆放在「根目錄/api/」下
- 起啟的 js 檔放在「根目錄/api/index_debug.js」
- 其中使用 consign 指定載入順序,讓網站可正常執行,
如∶ config file -> db -> authority -> routing -> ....... -> start server
問題∶
在 api 資料夾直接下 command : $node index_debug.js 可正常執行,
但是直接在 visual studio code 執行 debug 卻什麼事情也沒發生,斷點也沒有反應,
solution:
查了一下 consign 文件,verbose 設為 false 會關掉 log,導致發生什麼事都不知道,
verbose 設為 true 後,即可發現是因為路徑問題導致
標籤:
consign,
nodejs,
visual studio code
2016年11月8日 星期二
The request filtering module is configured to deny a request that exceeds the request content length.
今天遇到上傳檔案問題,
上傳後直接跳 404.13 error!
error message :
The request filtering module is configured to deny a request that exceeds the request content length.
已確定在 httpRuntime 的 maxRequestLength 屬性設定上傳檔案大小的限制,
卻還是活生生的發生這個問題
<system.web> <httpRuntime maxRequestLength="104857600" targetFramework="4.6.1" /> </system.web>
搜尋了一下,原來還要在 system.webServer/security/requestFiltering/requestLimits 的
maxAllowedContentLength 屬性設定上傳檔案的限制,可以正常啦!
<system.webServer> <security> <requestFiltering> <requestLimits maxAllowedContentLength="104857600"></requestLimits> </requestFiltering> </security> </system.webServer>
附上網友的說明:
The maxRequestLength indicates the maximum file upload size supported by ASP.NET, the maxAllowedContentLength specifies the maximum length of content in a request supported by IIS. Hence, we need to set both maxRequestLength and maxAllowedContentLength values to upload large files.
2016年10月13日 星期四
MSBuild Error MSB4094
使用 MSBuild 的 XmlPoke 更新特定 element attribute 的值,卻拋出 exception:
error MSB4094: "..." is an invalid value for the "Value" parameter of the "XmlPoke" task. Multiple items cannot be passed into a parameter of type "Microsoft.Build.Framework.ITaskItem"
研究後發現,原來是我要更新的內容包含分號 ( ; ),必須將分號跳脫成 %3B 即可
Example:
<Compile Include="MyFile.cs;MyClass.cs"/>
↓↓↓↓↓
<Compile Include="MyFile.cs%3BMyClass.cs"/>
2016年9月30日 星期五
mysql workbench Error Code: 1175
在 mysql workbench 執行 SQL 發生以下錯誤:
Error Code: 1175
You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
該怎麼辦呢?
- 打開 mysql workbench
- Edit → Preferences
- workbench 6.0,選擇 SQL Queries 頁籤
- workbench 6.3,選擇 SQL Editor 頁籤
- 反勾選Safe Updates. Forbid UPDATEs And DELETEs with no key in WHERE clause or no LIMIT clause. Requires a reconnection
- workbench 重新連線
- 即可正常執行
2016年9月6日 星期二
Prevent Cross-Site Request Forgery (CSRF) using ASP.NET MVC’s AntiForgeryToken()
什麼是 Cross-Site Request Forgery (CSRF)
簡單來說,CSRF 就是使用者在不知情的情況,讓瀏覽器送出請求給目標網站以達攻擊目的。使用者進行網路驗證後,瀏覽器會將驗證資訊存在 Cookie , 若使用者未登出,此 Cookie 仍視為有效, 而使用者瀏覽其他網站時,會將此驗證資訊回傳 server 以便進行操作, 此時使用者在不自覺的情況下,瀏覽含有攻擊程式碼的網頁, 駭客可使用相同一份驗證資訊(使用者身份)進行攻擊。
如何預防 CSRF
在 View 上 加入 @Html.AntiForgeryToken()<!-- Contained in xxxxx.cshtml --> @model MileageStats.ServicesModel.User @Html.AntiForgeryToken()
在 client 端,即可檢視會產出 hidden input html
<!-- Rendered HTML in the client browser --> <input name="__RequestVerificationToken" type="hidden" value="H4zpQFvPdmEdGCLsFgeByj0xg+BODBjIMvtSl5anoNaOfX4V69Pt1OvnjIbZuYrpgzWxWHIjbn zFOLxP5SzVR4cM9XZeV78IPi8K4ewkM3k2oFkplrXL4uoAqy+aoSOg8s1m1qxrE7oeBBtvezEHCAs6nKE h2jAwn3w0MwmhkcDQiJfJK7hGvN0jXA4d7S8x7rbLxp4Y8IJZS9wka2eOLg==" />
在 controller action 加上 ValidateAntiForgeryTokenAttribute
// Contained in xxxxController.cs [HttpPost] [ValidateInput(false)] [ValidateAntiForgeryToken] public ActionResult Edit(....)
透過 AntiForgeryToken 來檢查連線是否是正常的,
簡單的兩個步驟就完成囉!
參考:https://msdn.microsoft.com/en-us/library/hh404095.aspx
2016年9月5日 星期一
Preventing Open Redirection Attacks
前一陣子維護的 web 進行安全性掃描,
被列了一個 issue ,就是 open redirection attack,
至於什麼是 open redirection attack ,又該如何解決呢?
有興趣就接著往下看吧!
舉例來說,當某頁面需要登入權限,但還未登入時,當輸入網址後,會被導至登入頁,
在登入成功後,透過 returnUrl 會再導回原頁面,
如:
當我想進入 http://somewebhost/xxx/list
因為還未登入,所以被導至 http://somewebhost/Account/LogOn?returnUrl=/xxx/list
但成功登入後,則透過 returnUrl 導至 http://somewebhost/xxx/list
這一切都很完美,但對有心人士來說,也很完美,
怎麼說呢? 就是透過 returnUrl 這個特性,可以把使用者導引至惡意網站,
可以這麼做,組成以下連結,讓使用者誤以為進入正確的網站(也許是某金融網站 )
http://somewebhost/Account/LogOn?returnUrl=http://someBadWeb/doSomething
但成功登入後,卻會將使用者導至另一個惡意網站,而使用者會以為是正常的登入成功,
可能因此填入重要個資,如信用卡號碼等等,
形成一種釣魚網站的手法,十分可怕
在 asp.net MVC3 以上的寫法,
使用 System.Web.Mvc.Url helper 類別方法 IsLocalUrl() ,
來判斷 returnUrl 是否是合法的,如下:
若不是 MVC 專案,
則可利用以下方法進行驗證:
以上就可以解決此 issue 囉!
參考:http://www.asp.net/mvc/overview/security/preventing-open-redirection-attacks
被列了一個 issue ,就是 open redirection attack,
至於什麼是 open redirection attack ,又該如何解決呢?
有興趣就接著往下看吧!
What's Open Redirection Attacks ?
Any web application that redirects to a URL that is specified via the request such as the querystring or form data can potentially be tampered with to redirect users to an external, malicious URL. This tampering is called an open redirection attack.舉例來說,當某頁面需要登入權限,但還未登入時,當輸入網址後,會被導至登入頁,
在登入成功後,透過 returnUrl 會再導回原頁面,
如:
當我想進入 http://somewebhost/xxx/list
因為還未登入,所以被導至 http://somewebhost/Account/LogOn?returnUrl=/xxx/list
但成功登入後,則透過 returnUrl 導至 http://somewebhost/xxx/list
這一切都很完美,但對有心人士來說,也很完美,
怎麼說呢? 就是透過 returnUrl 這個特性,可以把使用者導引至惡意網站,
可以這麼做,組成以下連結,讓使用者誤以為進入正確的網站(也許是某金融網站 )
http://somewebhost/Account/LogOn?returnUrl=http://someBadWeb/doSomething
但成功登入後,卻會將使用者導至另一個惡意網站,而使用者會以為是正常的登入成功,
可能因此填入重要個資,如信用卡號碼等等,
形成一種釣魚網站的手法,十分可怕
該如何預防?
就是檢查 returnUrl 是否是合法的,也就是說只能導至目前 host 下的網址,在 asp.net MVC3 以上的寫法,
使用 System.Web.Mvc.Url helper 類別方法 IsLocalUrl() ,
來判斷 returnUrl 是否是合法的,如下:
public ActionResult LogOn(LogOnModel model, string returnUrl) { if (Url.IsLocalUrl(returnUrl)) { return Redirect(returnUrl); } else { return RedirectToAction("Index", "Home"); } }
若不是 MVC 專案,
則可利用以下方法進行驗證:
public static bool IsUrlLocalToHost(this HttpRequestBase request, string url) { return !url.IsEmpty() && ((url[0] == '/' && (url.Length == 1 || (url[1] != '/' && url[1] != '\\'))) || (url.Length > 1 && url[0] == '~' && url[1] == '/')); }
以上就可以解決此 issue 囉!
參考:http://www.asp.net/mvc/overview/security/preventing-open-redirection-attacks
訂閱:
文章 (Atom)