Skip to content
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

Merged
merged 4 commits into from
Apr 7, 2019
Merged

Cleaned permission checks for API -> site admin can now do anything #6483

merged 4 commits into from
Apr 7, 2019

Conversation

vakabus
Copy link
Contributor

@vakabus vakabus commented Apr 1, 2019

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() and reqOrgMembership() function.

@codecov-io
Copy link

codecov-io commented Apr 1, 2019

Codecov Report

Merging #6483 into master will decrease coverage by <.01%.
The diff coverage is 44.68%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
routers/api/v1/api.go 72.29% <19.35%> (-1.61%) ⬇️
modules/context/context.go 53.76% <93.75%> (+3.76%) ⬆️
modules/log/file.go 75.52% <0%> (-2.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 592e6c3...7319a39. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 1, 2019
@lunny lunny added the type/enhancement An improvement of existing functionality label Apr 2, 2019
@@ -189,84 +189,119 @@ func reqBasicAuth() macaron.Handler {
}
}

func isSiteAdmin(ctx *context.Context) bool {
Copy link
Member

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?

Copy link
Contributor Author

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.

routers/api/v1/api.go Show resolved Hide resolved
@vakabus
Copy link
Contributor Author

vakabus commented Apr 7, 2019

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?

Copy link
Contributor

@zeripath zeripath left a 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.~~

Copy link
Contributor

@zeripath zeripath left a 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

@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 7, 2019
@vakabus
Copy link
Contributor Author

vakabus commented Apr 7, 2019

@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.

@zeripath
Copy link
Contributor

zeripath commented Apr 7, 2019

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.

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 7, 2019
@lafriks lafriks merged commit 49b2f45 into go-gitea:master Apr 7, 2019
@lafriks lafriks added this to the 1.9.0 milestone Apr 7, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants