2

I have my backend endpoint for registering and logging in the users delivered trough RestApi or GraphQL to be more specific.

I want to implement role based system for my users.

The admins and moderators can be created on the admin module for example:

{
 username: peter,
 passowrd: peter123,
 role: 'admin'
}

But the regular users that can be created on my application will send the same input but instead of the 'admin' the role 'user' would be send.

I was thinking about this approach and was wondering if it's secure ?

Can users change the request object and change the role to admin, and then have super user access ?

Is there some best practices about this, or is this completely safe ?

asked Oct 30, 2019 at 8:13

1 Answer 1

2

I would never give the user the chance to say what they can do (which is, after all, what a role defines). It's like saying "Hey, I'm David, and I'm a supersaiyan" while I might just be a regular human, and then everyone blindly accept that I'm a supersaiyan.

What your authorization service should do is only allow user to say who they are (e.g. hey, I'm David) and then the authorization service should say "ok David, you are a regular user" or "ok David, you are an admin". What this means is that the authorization service must know who you are and what you are (stored, for example, in a database), and then give you permissions based on that.

I recommend you to check RBAC and ABAC libraries, they usually implement well established practices.

answered Oct 30, 2019 at 8:37

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.