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.

n<strong>on</strong>-tracking code with a simple string for its parameter.<br />

Instead, PHP Aspis requires additi<strong>on</strong>al transformati<strong>on</strong>s<br />

to intercept this call and automatically c<strong>on</strong>vert $p<br />

to an Aspis-protected value, which is marked as fully untainted.<br />

We refer to these additi<strong>on</strong>al transformati<strong>on</strong>s for<br />

partial taint tracking as compatibility transformati<strong>on</strong>s.<br />

Compatibility transformati<strong>on</strong>s make changes to both<br />

tracking and n<strong>on</strong>-tracking code. These changes alter the<br />

data that are exchanged between a tracking c<strong>on</strong>text and a<br />

n<strong>on</strong>-tracking c<strong>on</strong>text, i.e. data exchanged between functi<strong>on</strong>s,<br />

classes and code in the global scope. They strip<br />

Aspis-protected values when passed to n<strong>on</strong>-tracking c<strong>on</strong>texts<br />

and restore Aspis protecti<strong>on</strong> for tracking c<strong>on</strong>texts.<br />

Functi<strong>on</strong> calls. A functi<strong>on</strong> call is the most comm<strong>on</strong><br />

way of passing data across c<strong>on</strong>texts. PHP Aspis transforms<br />

all cross-c<strong>on</strong>text functi<strong>on</strong> calls: a call from a<br />

tracking to a n<strong>on</strong>-tracking c<strong>on</strong>text has its taint removed<br />

from parameters and the return value Aspis-protected<br />

again. The opposite happens for calls from n<strong>on</strong>-tracking<br />

to tracking c<strong>on</strong>texts. This also applies to method calls.<br />

Adapting parameters and return values is similar to using<br />

the default interceptor functi<strong>on</strong> from §3.2. User code,<br />

however, can share objects of user-defined classes. Instead<br />

of adapting every internal object property, PHP Aspis<br />

uses proxy objects that decorate passed values. C<strong>on</strong>sider<br />

an object $o of class c and assume that c is a tracking<br />

c<strong>on</strong>text. When $o is passed to the n<strong>on</strong>-tracking c<strong>on</strong>text<br />

of functi<strong>on</strong> f, f is unable to access $o’s state directly<br />

or call its methods. Instead, it receives the decorator $do<br />

that points to $o internally. $do is then resp<strong>on</strong>sible for<br />

adapting the parameters and the return values of method<br />

calls when such calls occur. It also handles reads and<br />

writes of public object properties.<br />

PHP also supports call-by-reference semantics for<br />

functi<strong>on</strong> parameters. Since changes to reference parameters<br />

by the callee are visible to the caller, these parameters<br />

effectively resemble return values. Compatibility<br />

transformati<strong>on</strong>s handle reference parameters similarly to<br />

return values—they are adapted to the calling c<strong>on</strong>text after<br />

the functi<strong>on</strong> call returns.<br />

This behaviour can lead to problems if references to a<br />

single variable are stored in c<strong>on</strong>texts of different types,<br />

i.e. if a tracking class internally has a reference to a variable<br />

also stored in a n<strong>on</strong>-tracking class. In such cases,<br />

PHP Aspis can no l<strong>on</strong>ger track these variables effectively<br />

across c<strong>on</strong>texts, forcing the administrator to mark both<br />

c<strong>on</strong>texts as tracking or n<strong>on</strong>-tracking. Since shared references<br />

to internal state make it hard to maintain class invariants,<br />

they are c<strong>on</strong>sidered bad practice [5] and a manual<br />

audit did not reveal any occurrences in Wordpress.<br />

Accessing global variables. PHP functi<strong>on</strong>s can access<br />

references to variables in the global scope using<br />

9<br />

the global keyword. These variables may be Aspisprotected<br />

or not, dependent <strong>on</strong> the type of the current<br />

global c<strong>on</strong>text and previous functi<strong>on</strong> calls. The compatibility<br />

transformati<strong>on</strong>s rewrite global statements: when<br />

the imported variable does not match the c<strong>on</strong>text of the<br />

functi<strong>on</strong>, the variable is altered so that it can be used<br />

by the functi<strong>on</strong>. After the functi<strong>on</strong> returns, all imported<br />

global variables must be reverted to their previous<br />

forms—return statements are preceded with the necessary<br />

reverse transformati<strong>on</strong>s. When functi<strong>on</strong>s do not return<br />

values, reverse transformati<strong>on</strong>s are added as the last<br />

functi<strong>on</strong> statement.<br />

Accessing superglobal variables. PHP also supports<br />

the noti<strong>on</strong> of superglobals: arrays that include the HTTP<br />

request data and can be accessed from any scope without<br />

a global declarati<strong>on</strong>. Data in these arrays are always<br />

kept tainted; removing their taint would effectively<br />

stop taint tracking everywhere in the applicati<strong>on</strong>. As a<br />

result, <strong>on</strong>ly tracking c<strong>on</strong>texts should directly access superglobals.<br />

In additi<strong>on</strong>, compatibility transformati<strong>on</strong>s enable<br />

limited access from n<strong>on</strong>-tracking c<strong>on</strong>texts when access<br />

can be statically detected (i.e. a direct read to $ GET<br />

but not an indirect access through an aliasing variable).<br />

This is because PHP Aspis does not perform static alias<br />

analysis to detect such indirect accesses [11].<br />

Include statements. PHP’s global scope includes code<br />

outside of functi<strong>on</strong> and class definiti<strong>on</strong>s and spans across<br />

all included scripts. Compatibility transformati<strong>on</strong>s can<br />

handle different c<strong>on</strong>text types for different scripts. This<br />

introduces a problem for variables in the global scope:<br />

they are Aspis-protected when they are created by a tracking<br />

c<strong>on</strong>text but have their original value when they are<br />

created by a n<strong>on</strong>-tracking c<strong>on</strong>text.<br />

To address this issue, PHP Aspis alters temporarily all<br />

variables in the global scope to be compatible with the<br />

current c<strong>on</strong>text of an included script, before an include<br />

statement is executed. After the include, all global<br />

variables are altered again to match the previous c<strong>on</strong>text<br />

type. To mitigate the performance overhead of this,<br />

global scope code placed in different files but used to handle<br />

the same request should be in the same c<strong>on</strong>text type.<br />

Dynamic features. Compatibility transformati<strong>on</strong>s intercept<br />

calls to create functi<strong>on</strong> and eval at runtime.<br />

PHP Aspis then rewrites the provided code according to<br />

the c<strong>on</strong>text type of the caller: when n<strong>on</strong>-tracking code<br />

calls eval, <strong>on</strong>ly the compatibility transformati<strong>on</strong>s are<br />

applied and n<strong>on</strong>-tracking code is generated. Moreover,<br />

create functi<strong>on</strong> uses a global array to store the c<strong>on</strong>text<br />

type of the resulting functi<strong>on</strong>. This informati<strong>on</strong> is<br />

then used to adapt the functi<strong>on</strong>’s parameters and return<br />

value in subsequent calls.<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> 21

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

Saved successfully!

Ooh no, something went wrong!