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

[WIP] Refactor attachement security #7956

Closed
wants to merge 24 commits into from

Conversation

sapk
Copy link
Member

@sapk sapk commented Aug 23, 2019

First, keep in mind that this PR is not perfect to be backward compatible (at least for viewing) but improve the current situation.

To be readable an attachment:

  • Need to be linked to an Issue or a Release (will hide any previously uploaded anonymously since not linked later)
  • The user need to have read access to the repo linked to issue or release

To be uploaded and later attached to an Issue or Release:

  • The attachment need to not be linked by an other issue or release. (You can not rebound a uploaded attachment from an other repo to a repo you own to be able to read it later).
  • You need to have read issue access to the current repo to upload an attachment. (Disable previous anonymous upload)

Way this PR could be improved later:

  • Add and set at upload a repoid fields and check it when linking the attachment to an issue or release. This could improve the read access maybe
  • Move the GET attachment under repo to use the access rule of the repo
  • Add an admin action to clear old none linked attachement (file uploaded but not linked to an issue or attachment (not submitted).

TODO:

  • Test it thoroughly manually
  • Add tests

Related issue: #7908 #4721
Related PR: #7909 (on an other aspect but is compatible)

@codecov-io
Copy link

codecov-io commented Aug 23, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@8ff6067). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #7956   +/-   ##
=========================================
  Coverage          ?   41.49%           
=========================================
  Files             ?      479           
  Lines             ?    63998           
  Branches          ?        0           
=========================================
  Hits              ?    26553           
  Misses            ?    33988           
  Partials          ?     3457

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 8ff6067...c05178a. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Aug 23, 2019
Copy link
Member

@guillep2k guillep2k left a comment

Choose a reason for hiding this comment

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

I'm always in favor of better security.

models/issue.go Outdated Show resolved Hide resolved
routers/routes/routes.go Outdated Show resolved Hide resolved
@lafriks
Copy link
Member

lafriks commented Aug 24, 2019

How would you upload attachment/image when creating new issue?

@sapk
Copy link
Member Author

sapk commented Aug 24, 2019

@lafriks from userpoint, the same way. I just check that you can open an issue to the current repo to be able to upload. This is mostly to limit anonymous upload. Currently someone could use gitea as a storage to distribute file without even needing an account.

@lafriks
Copy link
Member

lafriks commented Aug 24, 2019

Yes but when uploading attachment you are uploading it not attached to anything (there is no issue yet) so you have no rights to check for

@sapk
Copy link
Member Author

sapk commented Aug 24, 2019

@lafriks the post request is under repo path (and verification) now. if not linked later it will return 404 when get. The link is done later like previously when submitting the issue or release. I hesitate to add a repo id set at upload and check it at linking. It will add a little more flow check but isn't rely needed since it is the linking that allow the attachement to be available. The main reason is to force someone malicious to create an account to upload an attachement. And also for download I check the acces to the repo linked to issue or release.

@guillep2k
Copy link
Member

@lafriks the post request is under repo path (and verification) now. if not linked later it will return 404 when get. The link is done later like previously when submitting the issue or release. I hesitate to add a repo id set at upload and check it at linking. It will add a little more flow check but isn't rely needed since it is the linking that allow the attachement to be available. The main reason is to force someone malicious to create an account to upload an attachement. And also for download I check the acces to the repo linked to issue or release.

I think that's a good start. If the admin limits the access by registration, they should be able to trust Gitea to cover their backs. But that leaves me thinking (outside the scope of this PR): for repositories with anonymous access, a DoS attack is a piece of cake. Flood attacks can be covered by fail2ban (if the proper logs are set), but uploading attachments can deplete the storage space while being invisible to fail2ban. Perhaps in the future some kind of throtling mechanism should be considered.

@sapk
Copy link
Member Author

sapk commented Aug 24, 2019

Yes, that why I indicate that this PR is definitively not the complete fix and that attachment would need more rewrite and breaking changes to be on best practice.

First, keep in mind that this PR is not perfect to be backward compatible (at least for viewing) but improve the current situation.

From my point of view, I see this PR as a frist step to learn how attachements works and lay down some bases (and tests) for next step. Also I try to keep this as non-beaking as possible to backport it.

@stale
Copy link

stale bot commented Dec 16, 2019

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions.

@stale stale bot added the issue/stale label Dec 16, 2019
@sapk
Copy link
Member Author

sapk commented Dec 16, 2019

@Stale There are still that changes needed to be breakdown from this PR.

@stale stale bot removed the issue/stale label Dec 16, 2019
@lunny
Copy link
Member

lunny commented Jan 5, 2020

@sapk Should be replaced by #9340?

@sapk
Copy link
Member Author

sapk commented Jan 5, 2020

@lunny it still have a part for the upload of file that need to be extracted/improved in a separate PR.

@stale
Copy link

stale bot commented May 2, 2020

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions.

@stale stale bot added the issue/stale label May 2, 2020
@stale
Copy link

stale bot commented Jul 1, 2020

This pull request has been automatically closed because of inactivity. You can re-open it if needed.

@stale stale bot closed this Jul 1, 2020
@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
issue/stale lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants