Lion Cipher Lab

Implement role-based access control (RBAC) in a web app (hands-on)

Why it matters

Almost every real application has more than one kind of user -- an ordinary member and an administrator -- and the job of keeping the ordinary member out of the administrator's screens is called access control. When it is done wrong, a logged-in user can simply visit an admin URL and get in; OWASP ranks this 'broken access control' as the number-one web application security risk, because it is both extremely common and directly hands attackers data and powers that were never theirs. The fix is role-based access control (RBAC): you attach a role to each user and make every sensitive action…

What you'll learn

Steps in this lab

  1. Two words that get confused: authentication vs authorization
  2. Set up: confirm Python works and install Flask
  3. Build the app (with the access-control bug on purpose)
  4. Run it and confirm the intended behavior (log in as admin)
  5. See the flaw: a normal user walks into the admin page
  6. Fix it: add a role-check decorator and require the admin role
  7. Re-test BOTH roles: user blocked, admin still allowed
  8. The habits that make it stick: least privilege and deny-by-default
  9. What you did -- and the reflex to keep

Open the full interactive lab →