Notes
  • 👀About me
  • â„šī¸Good Reads
  • 🌐Web
    • Web Pentesting Checklist
    • Insecure Deserialization
    • Blind XPath Injection
    • GraphQL
    • Reverse Shells
      • IIS
    • Content-Security-Policy
      • XSS (Static Nonce in CSP)
    • LLM (Large Language Models)
  • 📘Windows API
    • C# - P/Invoke
  • ☕Miscellaneous Topics
    • Phishing with Gophish
    • Pentest Diaries
      • SQL Queries via Grafana
      • LDAP Pass Back Attack
      • Misconfigured File Upload to RCE
  • 🧃Hack The Box
    • Intelligence
    • Seal
    • Under Construction
    • Previse
    • Return
    • Sauna
    • Nest
  • 📕TryHackMe
    • Wordpress CVE-2021-29447
    • Attacktiv
    • Fortress
    • internal
  • đŸ› ī¸Cheatsheet
    • Anti-Forensic Techniques
    • JSON - jq
    • Docker
    • Hidden Secrets
    • Database Exploitation
      • PostgreSQL
        • Blind SQLi script
      • SQL Server
    • C Sharp
    • Reversing
      • Windows
    • SSH
    • Python
      • Miscellaneous Scripts
        • Credential Bruteforcing a CLI service
    • Privilege Escalation
      • Windows
    • socat
    • OSINT
      • Shodan
    • Installation
Powered by GitBook
On this page

Was this helpful?

  1. Web
  2. Content-Security-Policy

XSS (Static Nonce in CSP)

PreviousContent-Security-PolicyNextLLM (Large Language Models)

Last updated 1 year ago

Was this helpful?

Scenario: The application is using a Content-Security-Policy (CSP) that blocks from executing. There is a possibility of a Stored XSS as the application is not performing input validation or output encoding.

The following is the portion of CSP header:

Content-Security-Policy: ... script-src 'self' 'unsafe-eval' 'nonce-G3cdmbi5XK1gg-JadtzFMw' 'https://<trusted-url>' ...

From the above policy, we can note the following:

1. 'self': Can only load JavaScript from the same origin of app and scripts from external URL's will be blocked.

2. No 'unsafe-inline': we cannot execute inline scripts such as:

<script>
	doSomething();
</script>

OR

<button onClick="doSomething();">Do It</button>

Note: alert('XSS'); is also an example of a function call such as doSomething(); Both would be blocked.

3. 'nonce ...': Scripts with the specified nonce value can be executed.

Observation: After browsing the application for a while and observing the value of CSP header, we can conclude that the application does not rotate the nonce value with each HTTP request. This would increase the execution rate of our payload.

XSS Payload: The following payload successfully executed:

<script nonce="nonce-G3cdmbi5XK1gg-JadtzFMw">alert(document.domain);</script>

References:

🌐
inline scripts
CSP Nonce âŸļ Examples and Guide
Logo
unsafe-inline âŸļ CSP Guide
Logo