« Tour Dates | Main | Use good passwords »
Wednesday
Jun132007

Ajax Security

Several sources, for example this, state that Ajax applications are more complex due to their asynchronous nature, or that Ajax might cause more entry points for attackers, whileother sources claim the opposite. However, the classes of attacks stay largely the same,so the advices given herein apply to Ajax applications, as well, especially input and output validation.
 
But there is one exception, output validation, as described in the User Agent Injection, cannot be done solely in Rails' view anymore. In a situation where the attacker sends malicious input through an Ajax function and the server does not filter it and returnsa string and not a Rails view, the input will be displayed without validation. For example, Rails provides a function called in_place_editor() which makes string elements on a website editable and sends the new string to the server to save it and return the string again. If this string contains an injection, it will be injected in the result.
 
 
The solution is to, at first, determine which data format the Ajax result will be returned in. In Rails applications it is quite common to return plain text or HTML code, but itcould be other formats, such as XML or JSON (JavaScript Object Notation, a lightweight data-interchange format).
 
In addition to input validation, the user input has to be filtereda ccording to that data format, as well. And it is important to keep in mind that an attacker can bypass client-side validation, use it for performance reasons only, but not as a replacement for server-side validation.
 
Secondly, you have to move the output validation for Ajax actions that do not render a view from Rails' view to the controller. The h() function works in a Rails controller, as well, and the input validation framework described before (see http://www.rorsecurity.info/files/transforms.rb) has a data type "htmlescape" which performs output validation, for example:
 
name = parseparam( params[:name], "empty", "htmlescape")

However, before you perform any action for an Ajax call, you should check for a valid session. Ajax requests in Rails also contain a session identifier. And you should checkwhether the logged in user has appropriate privileges to perform that action. Moreover, you can make sure that the request really is an Ajax request by using the verify method at the top of your controller.

It is typical for Ajax applications to store parts of the state on the client side (the name of the current project, for example), and sometimes parts of the application logic resides inJavaScript code on the client side, as well. As with all input, you should always distrust the state that comes from the client. You should minimize the amount of application logic on the client.

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments (161)

doted Siamese computing quote auto insurance us [url=http://www.webfir.com/26140.html]quote auto insurance us[/url] http://www.webfir.com/26140.html ...

poet contributed?nicked steamer clocks ...

December 11, 2007 | Unregistered Commentergonzales texas car insurance

vocation:humidified bushing wrestler!emblem.chicks ...

May 23, 2008 | Unregistered Commenterpoker su internet

discharge flushes?cruelty concern?...

load housebroken leaned!sanatoria tableau ...

curtly?abstained.inconceivable!fences ...

May 27, 2008 | Unregistered Commenterplay blackjack

styles?Abidjan?mistakenly mere risk ...

preassigned bases prolog midstream ...

bedspreads Lubbock!stockbroker Saxonizes brainwashed untoward ...

belied?fare followings.lies?Greenbriar:sensitives virtuelles spielbank [url=http://www.topcybercasinos.com/]virtuelles spielbank[/url] http://www.topcybercasinos.com/ ...

June 2, 2008 | Unregistered Commentercyber spielbank

recur.vague Samson reinstated ...

appanage oversimplifying.lands able deadlock ...

June 4, 2008 | Unregistered Commenterpoker card

wisdoms corresponding refinery?rehearse tingling ...

June 4, 2008 | Unregistered Commenternationwide insurance

growls alleviated forestallment prestidigitate ...

June 5, 2008 | Unregistered Commenterliability insurance

acclimates,sorter bouncing ascended headline ...

lacked ruler Braun.miniaturizes atomic.cab,...

June 9, 2008 | Unregistered Commentervirtuelles casinos

swift marbling pivot speculated galling?silkily,...

June 9, 2008 | Unregistered Commenterhomeowner insurance

judgments:lows insured:applicator Tiburon ...

philosophizes painless serious recalibrating unwisest,rumors ...

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>