-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Prevent addition of labels from outside the repository or organisation in issues #14912
Prevent addition of labels from outside the repository or organisation in issues #14912
Conversation
756e98e
to
bc891c0
Compare
Excuse me for sounding dumb, but what is the point of this doctor check? Neither API nor web interface endpoints gate the label added to belong to repo or org. I can send API request or change Sounds to me like we need to add the appropriate check in code and solve this in single-time migration, rather than in Doctor check. |
Thanks @CirnoT I had presumed that the rest of the code would be doing the checks especially given the issue report which stated that all that was needed was a db consistency check. Clearly they were not. This is a much larger task than first thought. |
Lines 937 to 940 in 9b261f5
..and newly created issues had these foreign labels attached too. That's what confused me so much when I tried to investigate a couple days ago |
@noerw I think it depends on how these labels are being added - I suspect there is another issue here too. Hence the WIP. I think this one needs actual testing. Easiest way I've found to test any PR:
I have a little script:
|
Should we copy or delete the org labels when transfer a repository? It's a question. However, the transfer of repository should become a task running in background like migrations and there is a middle state Move the refactor of |
models/issue_label.go
Outdated
@@ -632,6 +632,8 @@ func HasIssueLabel(issueID, labelID int64) bool { | |||
return hasIssueLabel(x, issueID, labelID) | |||
} | |||
|
|||
// newIssueLabel this function creates a new label it does not check if the label is valid for the issue | |||
// YOU MUST CHECK THIS BEFORE THIS FUNCTION |
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.
diff --git a/models/issue_label.go b/models/issue_label.go
index 54b286fe7..2da0d2f20 100644
--- a/models/issue_label.go
+++ b/models/issue_label.go
@@ -632,7 +632,43 @@ func HasIssueLabel(issueID, labelID int64) bool {
return hasIssueLabel(x, issueID, labelID)
}
+// ErrAddIssueLabelNotAllowed represents the error adding the label to issue not allowed
+type ErrAddIssueLabelNotAllowed struct {
+ LabelID int64
+ LabelRepoID int64
+ LabelOrgID int64
+ IssueID int64
+ IssueRepoID int64
+ IssueOrgID int64
+}
+
+func (err ErrAddIssueLabelNotAllowed) Error() string {
+ return fmt.Sprintf("Add label %d[%d,%d] to issue/pr %d failed because it's not belong respository %d or orgnization %d",
+ err.LabelID, err.LabelRepoID, err.LabelOrgID,
+ err.IssueID,
+ err.IssueRepoID,
+ err.IssueOrgID,
+ )
+}
+
func newIssueLabel(e *xorm.Session, issue *Issue, label *Label, doer *User) (err error) {
+ if label.RepoID > 0 && label.RepoID != issue.RepoID {
+ return ErrAddIssueLabelNotAllowed{
+ LabelID: label.ID,
+ LabelRepoID: label.RepoID,
+ LabelOrgID: label.OrgID,
+ IssueID: issue.ID,
+ IssueRepoID: issue.RepoID,
+ }
+ } else if label.OrgID > 0 && label.OrgID != issue.Repo.OwnerID {
+ return ErrAddIssueLabelNotAllowed{
+ LabelID: label.ID,
+ LabelRepoID: label.RepoID,
+ LabelOrgID: label.OrgID,
+ IssueID: issue.ID,
+ IssueOrgID: issue.Repo.OwnerID,
+ }
+ }
if _, err = e.Insert(&IssueLabel{
IssueID: issue.ID,
LabelID: label.ID,
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.
That's gonna need to be added to a lot more places as there are lots of other places we silently drop these labels.
I think delete - at least for this PR. Copying and reassigning is really complex. The only issue is the migration - perhaps the migration should be dropped.
Not this PR.
Done. |
…org labels on transfer Prevent the addition of labels from outside of the repository or organisation and remove organisation labels on transfer. Related go-gitea#14908 Signed-off-by: Andrew Thornton <art27@cantab.net>
…t-in-repository-part-1
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
…m:zeripath/gitea into fix-14908-labels-not-in-repository-part-1
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
6b67724
to
ba378ec
Compare
Signed-off-by: Andrew Thornton <art27@cantab.net>
This PR adds another consistency check into doctor in order to detect labels that have been added from outside of repositories and organisations Fix go-gitea#14908 Signed-off-by: Andrew Thornton <art27@cantab.net>
ba378ec
to
0c8c90d
Compare
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
conflicts fixed. |
There is a serious issue with the v176 migration where there is a mistaken missing label_id selection. *introduced by #14912* Signed-off-by: Andrew Thornton <art27@cantab.net>
It has been possible to add labels to issues that do not belong to the repository or organisation as there were insufficient checks on this process.
This PRs enforces these checks and adds comments to the basic functions involved that ensure that future users will need to check.
It adds a migration to the system that simply deletes these issue_labels and comments - however, clearly this is not ideal as we should really attempt to match the labels with labels that are available. A perhaps better migration would also add the necessary labels to the repository.
On repository transfer all organization labels and comments related will be removed. I've decided this because: a) it's simpler and b) it prevents leaking of organization labels
It adds a consistency check to find these labels.
Fix #14908
Signed-off-by: Andrew Thornton art27@cantab.net