# Cross-site scripting Lab5 這題為 DOM-based XSS using jQuery 操作 href 屬性,目標是讓使用者點擊 "back" 鏈接時觸發 `document.cookie`。 一樣先進入網站。  在表單隨便輸入個東西。  發現有個 `returnPath`,去原始碼看他要幹嘛。  `$(function() { ... })`: jQuery 簡寫,等同於 `document.addEventListener('DOMContentLoaded', ...)`,確保 DOM 載入後才執行裡面的程式碼。 `new URLSearchParams(window.location.search).get('returnPath')`: 從網址中的查詢字串抓出 `returnPath` 參數的值。 範例網址: ``` /feedback?returnPath=/somewhere ``` 就會得到 `/somewhere` 作為回傳值。 `$('#backLink').attr("href", value)`: 把 #backLink 的 `<a>` 元素的 href 屬性設定為剛才抓到的值。 這整段程式碼 沒任何過濾或驗證 returnPath 的內容,可以將 returnPath 設為一個惡意的值,例如: ``` javascript:alert(document.cookie) ``` 當使用者點擊「返回」按鈕(`<a id="backLink">`)時,就會執行這段 JavaScript,造成 XSS。 ```javascript javascript:alert(document.cookie) ```    ---
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up