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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Policy Annotati<strong>on</strong><br />

Only admins can delete User objects @delete, User, :admin, :to login<br />

Only admins can delete the inferred object @delete, :admin, :to login<br />

Users can <strong>on</strong>ly change their own password @edit, pswrd, self.id == user.id, :to login<br />

Log creati<strong>on</strong> of new User objects @create, User, log functi<strong>on</strong>; true, :nothing<br />

To address this problem, we propose a major change in<br />

the way access c<strong>on</strong>trol policies are implemented in web<br />

applicati<strong>on</strong>s. Instead of applying data policies to functi<strong>on</strong>s,<br />

developers define access c<strong>on</strong>trol policies as part of<br />

the data objects they protect. These data-centric policies<br />

are specified using annotati<strong>on</strong>s added to data model<br />

declarati<strong>on</strong>s. The code needed to enforce the policies is<br />

generated automatically throughout the applicati<strong>on</strong>. By<br />

putting policies close to data and automating enforcement,<br />

we reduce the burden <strong>on</strong> the developer and limit<br />

the opportunity for implementati<strong>on</strong> error.<br />

3.1 Annotati<strong>on</strong>s<br />

To specify access c<strong>on</strong>trol policies, developers add access<br />

c<strong>on</strong>trol annotati<strong>on</strong>s of the form:<br />

@, , , <br />

to ActiveRecord class definiti<strong>on</strong>s.<br />

The four parameters define: (1) which <strong>on</strong>e of the five<br />

data access operati<strong>on</strong>s the policy c<strong>on</strong>cerns (read, edit,<br />

append, create, destroy); (2) the object this annotati<strong>on</strong><br />

c<strong>on</strong>cerns (either instances of the annotated class or individual<br />

variables within the class); (3) the mediator functi<strong>on</strong><br />

that checks if the protected acti<strong>on</strong> is allowed; and<br />

(4) the handler functi<strong>on</strong> that is invoked when an unauthorized<br />

acti<strong>on</strong> is attempted. If the target field is omitted,<br />

GuardRails infers the annotati<strong>on</strong>’s target from the<br />

locati<strong>on</strong> of the annotati<strong>on</strong> (see the sec<strong>on</strong>d annotati<strong>on</strong> in<br />

Table 1).<br />

Keywords are defined for mediators and handlers to<br />

define comm<strong>on</strong> policies. For example, the :admin keyword<br />

indicates a mediator policy that checks whether the<br />

requesting user has administrator privileges (Secti<strong>on</strong> 3.2<br />

explains how developers c<strong>on</strong>figure GuardRails to identify<br />

the current user object and determine if that user is an<br />

administrator). In additi<strong>on</strong> to making it easy to translate<br />

policies from a design document into annotati<strong>on</strong>s, using<br />

keywords makes it easy to define and recognize comm<strong>on</strong><br />

policies.<br />

Some policies are applicati<strong>on</strong> and data-specific. To define<br />

these more specific policies, developers use a Ruby<br />

expressi<strong>on</strong> instead of a keyword. The expressi<strong>on</strong> is evaluated<br />

in the c<strong>on</strong>text of the object being accessed so it<br />

can access that object (as self) as well as any global ap-<br />

Table 1: Access policies and corresp<strong>on</strong>ding annotati<strong>on</strong>s<br />

plicati<strong>on</strong> state. The expressi<strong>on</strong>s also have access to the<br />

current user object, which is made visible to the entire<br />

applicati<strong>on</strong> at the beginning of each executi<strong>on</strong>.<br />

Some examples of data policies are shown in Figure 1.<br />

Each annotati<strong>on</strong> would be included as a comment in a<br />

data model file above the class definiti<strong>on</strong>.<br />

Privileged Functi<strong>on</strong>s. Our annotati<strong>on</strong> system is flexible<br />

enough to support nearly all policies found in web<br />

applicati<strong>on</strong>s. Policies that depend <strong>on</strong> the executi<strong>on</strong> path<br />

to the protected acti<strong>on</strong>, however, cannot be specified because<br />

the policy functi<strong>on</strong>s do not have access to the call<br />

stack. We argue that such policies should be avoided<br />

whenever possible—they provide less clear restricti<strong>on</strong>s<br />

than policies tied solely to the data and global state (e.g.,<br />

the logged in user) that can be defined using annotati<strong>on</strong>s.<br />

One excepti<strong>on</strong> is the comm<strong>on</strong> “forgot my password”<br />

feature that allows an unauthenticated user to reset their<br />

password. To a stateless data policy, however, there is<br />

no observable difference between a safe password modificati<strong>on</strong><br />

using the “forgot my password” routine and an<br />

unsafe password modificati<strong>on</strong>.<br />

To handle cases like this, we allow developers to mark<br />

functi<strong>on</strong>s as privileged against certain policies. To create<br />

this password edit policy, the developer annotates the<br />

password local variable in the User class with the general<br />

policy that a users cannot change a password other<br />

their own (see Table 1 for the actual annotati<strong>on</strong>) and adds<br />

an annotati<strong>on</strong> to the declarati<strong>on</strong> of the “forgot my password”<br />

functi<strong>on</strong> to indicate that it is privileged. Since we<br />

are assuming developers are not malicious, this simple<br />

soluti<strong>on</strong> seems preferable to the more complex alternative<br />

of providing access to the executi<strong>on</strong> stack in data<br />

policy annotati<strong>on</strong>s.<br />

3.2 Policy Enforcement<br />

GuardRails enforces access policies by transforming the<br />

applicati<strong>on</strong>. It creates policy mappings, objects that map<br />

data access operati<strong>on</strong>s to mediator and handler functi<strong>on</strong>s,<br />

for each class or variable. All objects in the generated<br />

web applicati<strong>on</strong> c<strong>on</strong>tain policy mappings. By default,<br />

policy objects map all accesses to True.<br />

To enforce policies correctly, policies must propagate<br />

to local variables. For example, if an ActiveRecord ob-<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> 3

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

Saved successfully!

Ooh no, something went wrong!