6 Replies - 1177 Views - Last Post: 10 February 2011 - 07:05 PM

#1 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 745
  • View blog
  • Posts: 1,521
  • Joined: 30-January 09

How to prevent attacks via javascript?

Posted 07 February 2011 - 10:57 PM

I utilise jQuery as well as custom functions when designing my site. There is also a lot of AJAX usage throughout my site. Now, a user can simply find the names of my functions and execute them in the address bar by typing something like:
javascript:myFunction('hack');void(0);


Given that the Javascript functions I'm most concerned about are AJAX calls, is there any way to determine server-side whether the Javascript function call was made via the address bar (ie: possibly malicious) or legitimately by code? If not, are there any strategic workarounds?

Is This A Good Question/Topic? 0
  • +

Replies To: How to prevent attacks via javascript?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2887
  • View blog
  • Posts: 7,531
  • Joined: 08-June 10

Re: How to prevent attacks via javascript?

Posted 08 February 2011 - 12:11 AM

no. HTTP does not care about the origin of the request.
Was This Post Helpful? 1
  • +
  • -

#3 forest51690  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: How to prevent attacks via javascript?

Posted 08 February 2011 - 11:48 AM

Yes, your Javascript can be manipulated by UserScripts and even replicated to mimic your AJAX calls. So that means you shouldn't trust in it for site security.
Was This Post Helpful? 1
  • +
  • -

#4 init.d.httpd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 132
  • Joined: 02-February 11

Re: How to prevent attacks via javascript?

Posted 08 February 2011 - 12:27 PM

No you cant tell that...but make sure you are sanitizing any variables passed to your server side script via ajax also you can minify your completed javascript. This will at least keep the script kiddies away.

http://plugins.jquer..._and_Compressor

This post has been edited by init.d.httpd: 08 February 2011 - 12:27 PM

Was This Post Helpful? 1
  • +
  • -

#5 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 745
  • View blog
  • Posts: 1,521
  • Joined: 30-January 09

Re: How to prevent attacks via javascript?

Posted 08 February 2011 - 07:18 PM

Alright, thanks guys, as I suspected. I have been utilising <select> lists in various areas without sanitising those variables (as they are locked to selectable options) but given that even AJAX requests can be mimicked, then I'll whip up a validation function in PHP to cover it.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2887
  • View blog
  • Posts: 7,531
  • Joined: 08-June 10

Re: How to prevent attacks via javascript?

Posted 09 February 2011 - 12:14 AM

View Poste_i_pi, on 09 February 2011 - 03:18 AM, said:

then I'll whip up a validation function in PHP to cover it.

filter_var()
Was This Post Helpful? 1
  • +
  • -

#7 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 745
  • View blog
  • Posts: 1,521
  • Joined: 30-January 09

Re: How to prevent attacks via javascript?

Posted 10 February 2011 - 07:05 PM

View PostDormilich, on 09 February 2011 - 12:14 AM, said:

View Poste_i_pi, on 09 February 2011 - 03:18 AM, said:

then I'll whip up a validation function in PHP to cover it.

filter_var()

Hmm nice, I'll look into incorporating that. I've already written the custom validator function (which could be streamlined with that function), but some of the variables need to be validated using in_array(). Thanks for the follow-up
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1