Do I need to sanitize the callback parameter from a JSONP call?

Posted by christian studer on Stack Overflow See other posts from Stack Overflow or by christian studer
Published on 2010-05-05T21:46:08Z Indexed on 2010/05/06 7:18 UTC
Read the original article Hit count: 265

Filed under:
|
|

I would like to offer a webservice via JSONP and was wondering, if I need to sanitize the value from the callback parameter.

My current server side script looks like this currently (More or less. Code is in PHP, but could be anything really.):

header("Content-type: application/javascript");
echo $_GET['callback'] . '(' . json_encode($data) . ')';

This is a classic XSS-vulnerability.

If I need to sanitize it, then how? I was unable to find enough information about what might be allowed callback strings.

© Stack Overflow or respective owner

Related posts about jsonp

Related posts about xss-prevention