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

    The JSON specification is now wrong

    By Gareth Heyes (@hackvertor)

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

    ← Back to articles

    ES5 has decided for whatever reason to treat \u2028 and \u2029 (line/paragraph separators) as a new line in JavaScript this makes it in-line with regex "\s" character class. The JSON specification (to my knowledge) wasn't changed. So although it mentions escaping characters within strings it isn't a requirement. This means we're left with \u2028 and \u2029 characters that can break entire JSON feeds since the string will contain a new line and the JavaScript parser will bail out.

    Another interesting fact is that Crockford's regex in the JSON specification is also wrong, correct at the time but now wrong =)

    
    text='{"abc":"abc\u2029aa"}';
    var my_JSON_object = !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                 text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
             eval('(' + text + ')');
    
    

    This will eval since the test doesn't account for line/paragraph separators and will raise a syntax error since a new line is encountered.

    This is also true of most native JSON parsers in various browsers, for example the following: eval("("+JSON.stringify({a:'a\u2029a'})+")")

    Will bail out because the paragraph separator isn't escaped.

    ← Back to articles