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

fix users being able bypass limits with repo transfers #34031

Merged
merged 12 commits into from
Mar 31, 2025

Conversation

TheFox0x7
Copy link
Contributor

prevent user from being able to transfer repo to user who cannot have more repositories


@techknowlogick

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Mar 26, 2025
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Mar 26, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Mar 26, 2025
@techknowlogick techknowlogick added backport/v1.23 This PR should be backported to Gitea 1.23 type/bug labels Mar 26, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 27, 2025

Is there still an edge case? Suppose the limit is 2, now OrgA has 1 repo. Then a user could create 100 repositories and just start the "transfer", then the checks all pass, then OrgA keep "accepting" the transfers, then OrgA will get 100 new repositories?

If it is a real case, it's better to document it if it's difficult to fix, and maybe also better to have some tests (well, if it is difficult to write tests .... maybe it's also fine to leave the test to the future until something gets broken)

@TheFox0x7
Copy link
Contributor Author

Is there still an edge case? Suppose the limit is 2, now OrgA has 1 repo. Then a user could create 100 repositories and just start the "transfer", then the checks all pass, then OrgA keep "accepting" the transfers, then OrgA will get 100 new repositories?

Completely forgot about that one, I'll take a look at it later. Of the top of my head there would be two potential solutions:

  1. Check limit before starting transfer (and include repos which are pending to be accepted/rejected)
  2. Check limit on accept and error out if the limit would be reached.
    Second version seems better to me on paper.

@wxiaoguang
Copy link
Contributor

Another choice is: just document it and leave it there.

I guess we do not need to make too many limits to end users ......... until somebody really really really needs to "fix" it.

@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 Mar 27, 2025
@TheFox0x7 TheFox0x7 force-pushed the patch-repo-transfer branch from 08d3cca to 1517217 Compare March 28, 2025 22:44
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 28, 2025
@TheFox0x7
Copy link
Contributor Author

I've added a test (which will fail right now) and I have few questions - most obvious one being what doesn't reset the state?
Is there a (simple) way to create users/repos on the fly, or is this more of an integration tests area?
Also can someone point me where in UI is the accept/reject option? I can't find it at all.

@TheFox0x7
Copy link
Contributor Author

It's TestTransferOwnership which modifies it... Is the database not reset between tests?

@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 29, 2025
@lunny
Copy link
Member

lunny commented Mar 29, 2025

The name of the setting is creating limitation not owned limitation. So that I don't know whether we should do like this.

@TheFox0x7
Copy link
Contributor Author

I'd argue that transferring is an implicit creation - what's the difference between user creating a repo and user creating an org/second user and transferring it to bypass creation limit?

Some users use this setting to prevent spam and I think this would be considered a bug by them, if even though a limit of one created repository is set, a user could create and transfer one after another with no limit.

On the other hand you do bring a good point - it's probably a misusage of the setting in the first place.

@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 Mar 30, 2025
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 31, 2025
@lunny lunny enabled auto-merge (squash) March 31, 2025 20:00
@lunny lunny merged commit 4d23231 into go-gitea:main Mar 31, 2025
26 checks passed
@GiteaBot GiteaBot added this to the 1.24.0 milestone Mar 31, 2025
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Mar 31, 2025
Comment on lines +111 to +122
switch {
case repo_model.IsErrRepoTransferInProgress(err):
ctx.APIError(http.StatusConflict, err)
return
}

if repo_model.IsErrRepoAlreadyExist(err) {
case repo_model.IsErrRepoAlreadyExist(err):
ctx.APIError(http.StatusUnprocessableEntity, err)
return
}

if errors.Is(err, user_model.ErrBlockedUser) {
case repo_service.IsRepositoryLimitReached(err):
ctx.APIError(http.StatusForbidden, err)
case errors.Is(err, user_model.ErrBlockedUser):
ctx.APIError(http.StatusForbidden, err)
} else {
default:
ctx.APIErrorInternal(err)
return
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These case branches lose return?

@GiteaBot

This comment was marked as outdated.

@GiteaBot GiteaBot added the backport/manual No power to the bots! Create your backport yourself! label Apr 1, 2025
@wxiaoguang wxiaoguang removed backport/manual No power to the bots! Create your backport yourself! backport/v1.23 This PR should be backported to Gitea 1.23 labels Apr 1, 2025
@wxiaoguang
Copy link
Contributor

Maybe not need to backport since there are too many conflicts

zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 1, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  fix users being able bypass limits with repo transfers (go-gitea#34031)
  Improve pull request list api (go-gitea#34052)
  fix(go-gitea#34076):replace assgniee translation key (go-gitea#34077)
  [Fix] Resolve the problem of commit_statuses not being loaded at the top - right when switching files from the file tree (go-gitea#34079)
  Enable testifylint rules (go-gitea#34075)
  Fix markup content overflow (go-gitea#34072)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants