Search code examples
phpapachewebserverweb-hosting

How to block free web hosting sites from forcefully injecting JavaScript in php files, like cookies


I am using free web hosting named 'infinityfree.net'. Whenever i try to access php web api for json response, web server returns html output. Same php script return pure json on localhost.

Is there any way to stop/block web hosting from injecting snippets/cookies in my script ?

TIA.

Response is like this :

<html><body><script type="text/javascript" src="/aes.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("70942155091315ea1cbab5f266da3492");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; location.href="http://xamdev.epizy.com/getData.php?i=2";</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>

Solution

  • You could try using strip_tags on the returned string if injected code is HTML. I would then use json_decode to parse cleaned output.