Building a robust permissions system in TypeScript
xetera.dev·12h·
Flag this post

Have you ever tried to deal with permissions in your app and run into this issue?

function onSubmit() {
if (!user.hasPermission(Permission.WRITE_COMMENT)) {
sendMessage({
message: "Sorry you can't post comments!",
})
}
submitComment(user, form.comment)
}

AGH! You just forgot to return early from the permission check and ended up trying to write a comment anyways! If you made this mistake on the frontend, you probably got some annoying errors from a backend that hopefully didn’t make the same mistake you did. If you did it on the backend, you just introduced a pretty serious vulnerability in your app. Let’s hope this got caught in code review. Otherwise, you probably caught these hands instead.

How do we prevent this? A bug like this seems impossible to avoid other than…

Similar Posts

Loading similar posts...