2017-06-15 246 views
1

我在checkmarx中收到代碼爲windw.location.toString()的錯誤什麼是最好的防止此錯誤?如何在使用window.location.toString()時防止XSS攻擊

錯誤:

method at line 74 gets user input for the toString() element. the elements value then flows thrugh client side code without being properly sanitized or validated and is eventually displayed to the user in line 80. this may enable t dom css attack.

+0

包括相關的代碼行,其中錯誤發生......和完整的錯誤信息。 –

回答

0

做這樣的:

encodeURIComponent(myUrl); 

然後可以分析它安全,做做的時候:

decodeURIComponent(myUrl); 
+0

var a = encodeURIComponent(window.location.toString()); a = decodeURIComponent(a); hi @maninak,它是否正確 –

+0

是的。嘗試打印它看看該字符串是什麼編碼。實際上,任何嵌入式代碼在編碼時都呈現惰性。 – maninak

+0

@CharanTej如果您的問題已被解答,請將其標記爲關閉它。 – maninak