Programming Tips πŸ’‘
51.6K subscribers
67 photos
10 videos
30 files
354 links
Programming & AI:
Tips πŸ’‘
Articles πŸ“•
Resources πŸ‘Ύ
Design Patterns πŸ’Ž
Software Principles βœ…

πŸ‡³πŸ‡± Contact: @MoienTajik

🎯 Buy ads: https://telega.io/c/ProgrammingTip
Download Telegram
Favor Privileges over Role Checks ⛔️

A very common practice in web applications, especially those written using the ASP.NET built-in Role provider, is to perform role checks throughout the code to determine whether a user should have access to a particular page or control or command. πŸ”

For instance, you might see something like this ♻️ :

if (User.IsInRole(Roles.Administrators))
{
SomeSpecialControl.Visible = true;
}


The problems with the maintainability of this approach become apparent after a short while.❗️

For one, any buttons or other controls on the SomeSpecialControl above that post back to the page should also do a role check to ensure the user submitting the postback is in an acceptable role, otherwise a security hole may be present and users outside of these roles may be able to perform privileged actions. ☠️

πŸ”ΈπŸ”ΉπŸ”ΈπŸ”Ή

Introducing Privileges βœ…

Wouldn't it be better to act like this❓

EditorPanel.Visibility = CurrentUser.CanEdit(CurrentArticle);


This is very clear and is at the appropriate level of abstraction. πŸ’Ž

CanEdit isn’t itself a privilege; we can look at it as a sort of helper method in this case that lets us write clear and concise code. ✨


https://t.me/pgimg/127

[ Full Article ] : bit.do/prauth

γ€°γ€°γ€°γ€°γ€°γ€°
#AspMvc #Authorization
@ProgrammingTip