Search code examples
javascriptnode.jsexpressjsonp

node.js express jsonp return typeof


don't know why but my Express app is returning something weird with res.jsonp, something llike this:

/**/ typeof jsonp1406719695757 === 'function' && jsonp1406719695757({"published":true,"can_add_to_cart":true,"updated_at":"2014-01-[...snip...]

instead only this:

jsonp1406719695757({"published":true,"can_add_to_cart":true,"updated_at":"2014-01-[...snip...]

I can't understand why. Any ideas?


Solution

  • If you look at the code for res.jsonp(), you'll find comments explaining the extra content at the beginning:

    // the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"
    // the typeof check is just to reduce client error noise
    body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';