I have this snippet to get a parameter from the url:
return isset($_GET[$field]) ? $_GET[$field] : '';
But this seems to allow for XSS injection.
I’m loading a page from ModX in an iFrame (within an application) using an URL like this: “https://a-modx-site.nl//nl/app-privacy/?ourhostname=https%3A%2F%2Fdev.ourapplication.nl&device-type=DESKTOP_APP”.
I’m being advised to sanitize the result from $_GET using a library (don’t do it yourself).
Then I found this ModX extra GetUrlParam but it doesn’t seem to return anything when I call it it like this:
<body class="[[!getParam? &field=`device-type`]]" data-test="[[getUrlParam? &field=`device-type`]]">
My own simple getParam
works fine and getUrlParam
does not. (cached or uncached doesn’t help)
What’s wrong? Any other suggestion on how to prevent XSS injection in ModX is welcome as well.