29.11.2012 Views

2nd USENIX Conference on Web Application Development ...

2nd USENIX Conference on Web Application Development ...

2nd USENIX Conference on Web Application Development ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

String Command Result<br />

"foobar".gsub("o","0") "f00bar"<br />

"medium".gsub(/(datu|mediu|agendu|bacteriu)m/,"\1a") "media"<br />

"utopia".gsub(/(a|e|i|o|u)/) {|x| x.swapcase } "UtOpIA"<br />

"football".squeeze "fotbal"<br />

"battle".squeeze "batle"<br />

Table 2: Example String Commands with Taint<br />

Underlined and bold text in these examples indicate different taint statuses. The sec<strong>on</strong>d gsub example is very similar to the matching<br />

used by Ruby <strong>on</strong> Rails in the pluralize functi<strong>on</strong>, which c<strong>on</strong>verts words to their plural form. The sec<strong>on</strong>d squeeze example dem<strong>on</strong>strates<br />

how taint must be merged in cases where the value of a chunk comes from multiple sources.<br />

of the order in which they are applied.<br />

String Interpolati<strong>on</strong>. One key advantage of taint tracking<br />

system employed by GuardRails is that modifies<br />

string operati<strong>on</strong>s dynamically, with no need to directly<br />

alter any Ruby libraries. String interpolati<strong>on</strong>, a means<br />

of evaluating Ruby code in the middle of a string, is<br />

managed by native Ruby C code, however, and cannot<br />

be changed dynamically. To resolve this problem,<br />

the source-to-source transformati<strong>on</strong> d<strong>on</strong>e by GuardRails<br />

transforms all instances in the web applicati<strong>on</strong> where interpolati<strong>on</strong><br />

is used with syntactically equivalent c<strong>on</strong>catenati<strong>on</strong>.<br />

Additi<strong>on</strong>ally, because Ruby <strong>on</strong> Rails itself also<br />

uses interpolati<strong>on</strong>, GuardRails runs the same source-tosource<br />

transformati<strong>on</strong> <strong>on</strong> the Ruby <strong>on</strong> Rails code, replacing<br />

all uses of interpolati<strong>on</strong> with c<strong>on</strong>catenati<strong>on</strong>.<br />

4.4 Examples<br />

We illustrate how <strong>on</strong>e taint-tracking system eliminates<br />

vulnerabilities and simplifies applicati<strong>on</strong> code by describing<br />

a few examples from our evaluati<strong>on</strong> applicati<strong>on</strong>s.<br />

SQL Injecti<strong>on</strong>. Substruct, an e-commerce applicati<strong>on</strong>,<br />

handles most forms safely but <strong>on</strong>e particular set of fields<br />

was left vulnerable to SQL injecti<strong>on</strong> [21]. The issue lay<br />

with the use of the functi<strong>on</strong> update all, which performs<br />

direct database updates and can easily be used unsafely,<br />

as in the following code written by the developers:<br />

update all(”value = '#{value}'”, ”name = '#{name}'”)<br />

This code directly includes the user-provided value string<br />

in the SQL command. A malicious user could exploit<br />

this to take c<strong>on</strong>trol of the command and potentially take<br />

c<strong>on</strong>trol of the database.<br />

GuardRails prevents this vulnerability from being exploited.<br />

Since update all is known to be a way of passing<br />

strings directly into SQL commands, GuardRails modifies<br />

the functi<strong>on</strong> to transform the provided strings for<br />

the SQL use c<strong>on</strong>text. As form data is marked automatically<br />

with the default Transformer, the potentially<br />

harmful strings will be sanitized to remove any dangerous<br />

text that might modify the SQL command. Note that<br />

for this example, the vulnerability is eliminated by using<br />

GuardRails even if no annotati<strong>on</strong>s are provided by the<br />

developer.<br />

Cross-Site Scripting. Onyx correctly sanitizes input that<br />

is used to post comments <strong>on</strong> images, but does not perform<br />

the same checks <strong>on</strong> input to certain administrator<br />

fields. This allows any administrator to inject code into<br />

the applicati<strong>on</strong> to attack applicati<strong>on</strong> users or other site<br />

administrators. In the case of the site descripti<strong>on</strong> field,<br />

simply putting in a double quote as part of the input<br />

is enough to break the HTML structure of the resulting<br />

pages. These are examples of simple persistent cross-site<br />

scripting issues, where the offending string is first saved<br />

in the database, then attacks users when later loaded from<br />

the database and placed into HTML resp<strong>on</strong>ses.<br />

Applying GuardRails fixes these cross-site scripting<br />

vulnerabilities. Recall that the default Transformer (Figure<br />

1) removes all tags when an unsafe string is used in<br />

an HTML c<strong>on</strong>text. Thus, when the attacker submits the<br />

malicious string in the web form, it is immediately assigned<br />

the default Transformer. When that string is later<br />

used in HTML, it is sanitized using the NoHTMLAllowed<br />

filter. The taint informati<strong>on</strong> is preserved when strings<br />

are saved and loaded from the database (Secti<strong>on</strong> 4.3.1),<br />

so the vulnerability is not exploitable even though it involves<br />

strings read from the database.<br />

5 Evaluati<strong>on</strong><br />

We c<strong>on</strong>ducted a preliminary evaluati<strong>on</strong> of GuardRails by<br />

testing it <strong>on</strong> a variety of Ruby <strong>on</strong> Rails applicati<strong>on</strong>s. Table<br />

3 summarizes the test applicati<strong>on</strong>s. These applicati<strong>on</strong>s<br />

are diverse in terms of complexity and cover a range<br />

of applicati<strong>on</strong> types and design styles. We were able to<br />

use GuardRails effectively <strong>on</strong> all the applicati<strong>on</strong>s without<br />

any modificati<strong>on</strong>s.<br />

As detailed in Secti<strong>on</strong> 3.3, we have had success at preventing<br />

known access c<strong>on</strong>trol issues with simple policy<br />

annotati<strong>on</strong>s. Our system of fine-grained taint tracking<br />

<str<strong>on</strong>g>USENIX</str<strong>on</strong>g> Associati<strong>on</strong> <strong>Web</strong>Apps ’11: <str<strong>on</strong>g>2nd</str<strong>on</strong>g> <str<strong>on</strong>g>USENIX</str<strong>on</strong>g> <str<strong>on</strong>g>C<strong>on</strong>ference</str<strong>on</strong>g> <strong>on</strong> <strong>Web</strong> Applicati<strong>on</strong> <strong>Development</strong> 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!