security - How can I better protect my php, jquery, ajax requests from malicious users -
i send lot of data through jquerys getjson method, example of function is
function dosomething(sid){ if(sid){ $.getjson("ajax/ajaxdosomething.php",{sid:""+sid+""}, function(data){ //alert(data); if(data.success == true){ $('#add_vote_div').html('vote received'); $('#list_data_div').html(data.html); } else{ $('#add_vote_div').html(data.message); } }); } }` the problem can @ source , see location of php file sending data to, therefore point browser there , append data url. checks on data make sure right data type, dont want users able go url @ all.
i thought maybe put ajax files behind main document root work jquery can't link absolute paths like
$.getjson("var/www/ajax/dosomething.php",{sid:""+sid+""} (main document root var/www/html/)
if made $.postjson work better, doesn't exist, ideas?
it raises bar hacking slightly, can post json via jquery.ajax (that's link) or jquery.post (so's that). jquery.getjson wrapper ajax (as .post, , .get). getjson docs:
this shorthand ajax function, equivalent to:
$.ajax({ url: url, datatype: 'json', data: data, success: callback });
thus, postjson concept, you'd add type parameter it:
$.ajax({ url: url, type: 'post', // <== new bit datatype: 'json', data: data, success: callback }); if wanted to, add postjson jquery object, pre-processing arguments , calling $.ajax. copy-and-paste the jquery source, switching .get .post:
if (!jquery.postjson) { jquery.postjson = function( url, data, callback ) { return jquery.post(url, data, callback, "json"); }; } mind you, it's still pretty easy fake post. not easy get, still pretty easy.
Comments
Post a Comment