ASP.NET AJAX Roles and Security

David Barkol writes on his blog about ASP.NET AJAX Role Application Service with Visual Studio 2008 (Orcas). Well, it is a new service that is working similar to the profile and authentication service. As it is very easy to call it from the client-side JavaScript code you should be a little bit more careful using these new methods.

When you read David's post you will find a very simple example (and exactly there you can already see what I mean with careful:

function pageLoad() {
    loadRoles();
}

function loadRoles() {
    Sys.Services.RoleService.load(onLoadRolesCompleted, 
onLoadRolesFailed, null); } function onLoadRolesCompleted(result, userContext, methodName) { if (Sys.Services.RoleService.isUserInRole("Administrator")) { $get("adminView").style.display = "block"; } } function onLoadRolesFailed(error, userContext, methodName) { alert(error.get_message()); }

In the asyncronous callback method onLoadRolesCompleted you see the if statement isUserInRole("Administrator"). If it is true the next line will simple display the HtmlElement with the ID adminView in the Web browsers window which is by default hidden. So, instead of running this method you could run following command at your own to enable the adminView display:

document.getElementById("adminView").style.display = "block";

This is not yet a security problem, but if you call there another AJAX request which will do any administrative tasks it could be a problem.

You have to test ALWAYS on the server-side code if the user has the needed user rights to execute your code. You can do that at your own or use the PrincipalPermissionAttribute where you can specify roles that are allowed to execute the whole AJAX method. I recommend using the attribute because there is no code from the method executed until the user is in the correct role.

One year ago I already wrote a simple demonstration how to use the PrincipalPermissionAttribute inside Ajax.NET Professional AjaxMethods.

Published Monday, July 30, 2007 1:44 PM by Michael Schwarz

Comments

# re: ASP.NET AJAX Roles and Security

Monday, July 30, 2007 9:15 AM by davidbarkol

Good point Michael.

# Visual Studio 2008中的ASP.NET AJAX Role Application Service

Wednesday, August 01, 2007 11:49 PM by Dflying Chen

ASP.NETAJAX在目前版本中已经内建了两种ApplicationService:用户身份认证(AuthenticationService)和用户个性化(Profile)(请参考:《在ASP...

# AJAX Security - Client Side Validation Is For Usability Only, Not For Security

Wednesday, October 03, 2007 8:32 AM by alik levin's

“As to methods there may be a million and then some, but principles are few. The man who grasps principles