146
non-tracking code with a simple string for its parame-
ter. Instead, PHP Aspis requires additional transforma-
tionsto intercept this call and automatically convert
$p
toanAspis-protectedvalue,whichismarkedasfullyun-
tainted. We referto these additionaltransformationsfor
partialtainttrackingascompatibilitytransformations.
Compatibility transformations make changes to both
trackingandnon-trackingcode. These changesalterthe
datathatareexchangedbetweenatrackingcontextanda
non-tracking context, i.e.data exchanged betweenfunc-
tions, classes and code in the global scope. They strip
Aspis-protectedvalueswhenpassedtonon-trackingcon-
textsandrestoreAspisprotectionfortrackingcontexts.
Function calls. A function call is the most common
way of passing data across contexts. PHP Aspis trans-
forms all cross-context function calls: a call from a
tracking to a non-tracking context hasitstaint removed
from parameters and the return value Aspis-protected
again. The oppositehappensforcallsfrom non-tracking
totrackingcontexts.Thisalsoappliestomethodcalls.
Adaptingparametersandreturnvaluesissimilartous-
ingthedefaultinterceptorfunctionfrom§3.2.Usercode,
however, can share objects of user-defined classes. In-
steadofadaptingeveryinternalobjectproperty,PHPAs-
pisusesproxy objectsthat decoratepassed values. Con-
sideranobject
$o
ofclass
c
andassume that
c
isatrack-
ing context. When
$o
ispassedtothenon-tracking con-
textoffunction
f
,
f
isunabletoaccess
$o
’sstatedirectly
orcallitsmethods. Instead,itreceivesthedecorator
$do
that pointsto
$o
internally.
$do
is then responsible for
adapting the parametersand the returnvaluesof method
calls when such calls occur. It also handles reads and
writesofpublic objectproperties.
PHP also supports call-by-reference semantics for
functionparameters. Since changestoreference param-
etersby the callee are visible tothe caller,these param-
eters effectively resemble return values. Compatibility
transformationshandlereferenceparameterssimilarlyto
returnvalues—theyare adaptedtothe callingcontextaf-
terthefunctioncallreturns.
Thisbehaviourcanleadtoproblemsifreferencesto a
single variable are stored in contexts of different types,
i.e.ifa tracking classinternallyhasa reference toa vari-
able also stored in a non-tracking class. In such cases,
PHPAspiscannolongertrackthesevariableseffectively
across contexts, forcing the administrator to mark both
contextsastrackingornon-tracking. Since sharedrefer-
ences to internal state make it hard tomaintain class in-
variants,theyare considered badpractice[5]andaman-
ualauditdidnotrevealanyoccurrencesinWordpress.
Accessing global variables. PHP functions can ac-
cess references to variables in the global scope using
the
global
keyword. These variables may be Aspis-
protected or not, dependent on the type of the current
global context and previousfunctioncalls. Thecompat-
ibilitytransformationsrewrite
global
statements: when
the imported variable doesnot match the context of the
function, the variable is altered so that it can be used
by the function. After the function returns, all im-
portedglobalvariablesmustberevertedtotheirprevious
forms—
return
statementsare precededwiththeneces-
sary reversetransformations. When functionsdonotre-
turn values,reverse transformationsare addedasthe last
functionstatement.
Accessing superglobal variables. PHP also supports
thenotionofsuperglobals: arraysthat includethe HTTP
request data and can be accessed from any scope with-
out a
global
declaration. Data in these arrays are al-
wayskept tainted;removingtheirtaintwouldeffectively
stop taint tracking everywhere in the application. As a
result, only tracking contexts should directly access su-
perglobals.Inaddition,compatibilitytransformationsen-
ablelimited accessfromnon-tracking contextswhen ac-
cesscanbestaticallydetected(i.e.adirectreadto
$
GET
but not an indirect access through an aliasing variable).
Thisisbecause PHP Aspisdoes not perform static alias
analysistodetectsuchindirectaccesses[11].
Includestatements. PHP’sglobalscopeincludescode
outsideoffunctionandclassdefinitionsandspansacross
all included scripts. Compatibility transformations can
handle different context typesfor different scripts. This
introduces a problem for variables in the global scope:
theyareAspis-protectedwhentheyarecreatedbyatrack-
ing context but have their original value when they are
createdbyanon-trackingcontext.
Toaddressthisissue,PHPAspisalterstemporarilyall
variables in the global scope to be compatible with the
currentcontextofanincludedscript,beforean
include
statement is executed. After the
include
, all global
variables are altered again to match the previous con-
texttype. Tomitigate the performance overheadofthis,
globalscopecodeplacedindifferentfilesbutusedtohan-
dlethe samerequestshouldbe inthesamecontexttype.
Dynamic features. Compatibility transformations in-
terceptcallsto
create
function
and
eval
atruntime.
PHPAspisthen rewritestheprovidedcodeaccording to
the context type of the caller: when non-tracking code
calls
eval
, only the compatibility transformations are
applied and non-tracking code is generated. Moreover,
create
function
usesa global array tostore the con-
text type of the resulting function. This information is
then used to adapt the function’sparametersand return
valueinsubsequentcalls.
9