跳至內容

Active Server Pages/防止使用者輸入(XSS 攻擊)

來自華夏公益教科書,自由的教科書

為了保護您的使用者免受跨站指令碼 (XSS) 和類似攻擊,您應該對 URL 和使用者提交的文字進行轉義。在 ASP 中,這是透過兩個函式完成的Server.HTMLEncode,和Server.URLEncode.

Server.HTMLEncode

[編輯 | 編輯原始碼]

不要輸出未轉義的使用者資料

Response.write user_data 'not safe

相反,請執行以下操作

Response.write Server.HTMLEncode( user_data )

此方法也應用於來自 SQL 的所有資料。安全總比後悔好。

Server.URLEncode

[編輯 | 編輯原始碼]

要對插入到 A 標籤的 href 屬性中的 URL 進行編碼,請使用Server.URLEncode函式,例如

<a href="http://foobar.com?<%= Server.URLEncode( "foo=bar" + "&baz=quz" ) %>">
華夏公益教科書