-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaned permission checks for API -> site admin can now do anything #6483
Conversation
Signed-off-by: Vasek Sraier <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #6483 +/- ##
==========================================
- Coverage 40.42% 40.41% -0.01%
==========================================
Files 404 404
Lines 54094 54116 +22
==========================================
+ Hits 21865 21873 +8
- Misses 29217 29228 +11
- Partials 3012 3015 +3
Continue to review full report at Codecov.
|
routers/api/v1/api.go
Outdated
@@ -189,84 +189,119 @@ func reqBasicAuth() macaron.Handler { | |||
} | |||
} | |||
|
|||
func isSiteAdmin(ctx *context.Context) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could these methods be added to API context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I've moved it.
…eturn Signed-off-by: Vasek Sraier <[email protected]>
…text/context.go Signed-off-by: Vasek Sraier <[email protected]>
Sorry that it took me so long, but I finally got time to fix the reported issues. Hope it's better now. What do you think? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~~Why did you switch the order of reqOrgOwnership and reqOrgMembership?
Moving around code like that is the perfect way to introduce security holes.
Reviewers please check this very carefully.~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I'm satisfied that moving the functions around hasn't changed their semantics
@zeripath Thanks for the review. Do you think I should revert back the reordering? I did it, because it made more sense to me. Higher privilege first, lower second. As everything else in that file. But I agree, I could have broke something and it wouldn't be clear. That's a good point. |
No it's fine. It was just a caution to other reviewers and myself to double check what we're doing. Gitea use is growing and I could imagine that at some point someone might want to introduce a security hole. We need to be careful around permissions. |
Fixes and implements ideas from #6434 .
The main idea is, that permission checks should be hierarchical and users with higher privileges should not be denied access. Especially site-admins.
I extracted permission checks into separate functions and then modified the permission handlers to check more broadly. It's not a huge change in code, but it could have bad consequences if something is wrong.
I also reordered the functions, so that higher permissions are higher. It's not a big deal, but it explains the weird diff in
reqOrgOwnership()
andreqOrgMembership()
function.