P
Per Salmi
Hi,
I was just looking over a few samples of role based security in combination
with forms based authentication. The samples I find seem to store an encrypted
list of roles in a cookie like this:
(Code snippet taken from Code Project article by Heath Stewart)
// Create a new ticket used for authentication
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Ticket version
Username.Value, // Username associated with ticket
DateTime.Now, // Date/time issued
DateTime.Now.AddMinutes(30), // Date/time to expire
true, // "true" for a persistent user cookie
reader.GetString(0), // User-data, in this case the roles
FormsAuthentication.FormsCookiePath);// Path cookie valid for
// Encrypt the cookie using the machine key for secure transport
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
// Add the cookie to the list for outgoing response
Response.Cookies.Add(cookie);
Is this really av safe way to store the current users available roles? I
am thinking about a scenario where a user could elevate his/hers privileges
by brute force decryption of the cookie and then create new contents for
the cookie, adding a role like "Admin" which probably could be valid in many
sites using this technique.
To me it would feel better if the list of the current users roles was not
stored on the client.
Anyone got comments on this?
Best regards,
Per Salmi
I was just looking over a few samples of role based security in combination
with forms based authentication. The samples I find seem to store an encrypted
list of roles in a cookie like this:
(Code snippet taken from Code Project article by Heath Stewart)
// Create a new ticket used for authentication
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Ticket version
Username.Value, // Username associated with ticket
DateTime.Now, // Date/time issued
DateTime.Now.AddMinutes(30), // Date/time to expire
true, // "true" for a persistent user cookie
reader.GetString(0), // User-data, in this case the roles
FormsAuthentication.FormsCookiePath);// Path cookie valid for
// Encrypt the cookie using the machine key for secure transport
string hash = FormsAuthentication.Encrypt(ticket);
HttpCookie cookie = new HttpCookie(
FormsAuthentication.FormsCookieName, // Name of auth cookie
hash); // Hashed ticket
// Set the cookie's expiration time to the tickets expiration time
if (ticket.IsPersistent) cookie.Expires = ticket.Expiration;
// Add the cookie to the list for outgoing response
Response.Cookies.Add(cookie);
Is this really av safe way to store the current users available roles? I
am thinking about a scenario where a user could elevate his/hers privileges
by brute force decryption of the cookie and then create new contents for
the cookie, adding a role like "Admin" which probably could be valid in many
sites using this technique.
To me it would feel better if the list of the current users roles was not
stored on the client.
Anyone got comments on this?
Best regards,
Per Salmi