Skip to content

Commit 3362b3a

Browse files
committed
fix possible disclosure
1 parent 5026420 commit 3362b3a

File tree

7 files changed

+61
-21
lines changed

7 files changed

+61
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
33

44
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
55

6-
##### Current version: 0.8.4
6+
##### Current version: 0.8.5
77

88
| Web | UI | Preview |
99
|:-------------:|:-------:|:-------:|

cmd/serve.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/codegangsta/cli"
1818

1919
"github.com/gogits/gogs/models"
20+
"github.com/gogits/gogs/modules/base"
2021
"github.com/gogits/gogs/modules/httplib"
2122
"github.com/gogits/gogs/modules/log"
2223
"github.com/gogits/gogs/modules/setting"
@@ -87,7 +88,7 @@ func fail(userMessage, logMessage string, args ...interface{}) {
8788
os.Exit(1)
8889
}
8990

90-
func handleUpdateTask(uuid string, user *models.User, username, reponame string, isWiki bool) {
91+
func handleUpdateTask(uuid string, user, repoUser *models.User, reponame string, isWiki bool) {
9192
task, err := models.GetUpdateTaskByUUID(uuid)
9293
if err != nil {
9394
if models.IsErrUpdateTaskNotExist(err) {
@@ -104,13 +105,13 @@ func handleUpdateTask(uuid string, user *models.User, username, reponame string,
104105
}
105106

106107
if err = models.Update(task.RefName, task.OldCommitID, task.NewCommitID,
107-
user.Name, username, reponame, user.Id); err != nil {
108+
user.Name, repoUser.Name, reponame, user.Id); err != nil {
108109
log.GitLogger.Error(2, "Update: %v", err)
109110
}
110111

111112
// Ask for running deliver hook and test pull request tasks.
112-
reqURL := setting.LocalUrl + username + "/" + reponame + "/tasks/trigger?branch=" +
113-
strings.TrimPrefix(task.RefName, "refs/heads/")
113+
reqURL := setting.LocalUrl + repoUser.Name + "/" + reponame + "/tasks/trigger?branch=" +
114+
strings.TrimPrefix(task.RefName, "refs/heads/") + "&secret=" + base.EncodeMD5(repoUser.Salt)
114115
log.GitLogger.Trace("Trigger task: %s", reqURL)
115116

116117
resp, err := httplib.Head(reqURL).SetTLSClientConfig(&tls.Config{
@@ -163,7 +164,7 @@ func runServ(c *cli.Context) {
163164
if models.IsErrUserNotExist(err) {
164165
fail("Repository owner does not exist", "Unregistered owner: %s", username)
165166
}
166-
fail("Internal error", "Failed to get repository owner(%s): %v", username, err)
167+
fail("Internal error", "Failed to get repository owner (%s): %v", username, err)
167168
}
168169

169170
repo, err := models.GetRepositoryByName(repoUser.Id, reponame)
@@ -266,7 +267,7 @@ func runServ(c *cli.Context) {
266267
}
267268

268269
if requestedMode == models.ACCESS_MODE_WRITE {
269-
handleUpdateTask(uuid, user, username, reponame, isWiki)
270+
handleUpdateTask(uuid, user, repoUser, reponame, isWiki)
270271
}
271272

272273
// Update user key activity.

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/gogits/gogs/modules/setting"
1919
)
2020

21-
const APP_VER = "0.8.4.1214"
21+
const APP_VER = "0.8.5.1214"
2222

2323
func init() {
2424
runtime.GOMAXPROCS(runtime.NumCPU())

models/migrations/migrations.go

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/go-xorm/xorm"
1919
"gopkg.in/ini.v1"
2020

21+
"github.com/gogits/gogs/modules/base"
2122
"github.com/gogits/gogs/modules/log"
2223
"github.com/gogits/gogs/modules/setting"
2324
gouuid "github.com/gogits/gogs/modules/uuid"
@@ -57,12 +58,13 @@ type Version struct {
5758
// If you want to "retire" a migration, remove it from the top of the list and
5859
// update _MIN_VER_DB accordingly
5960
var migrations = []Migration{
60-
NewMigration("fix locale file load panic", fixLocaleFileLoadPanic), // V4 -> V5:v0.6.0
61-
NewMigration("trim action compare URL prefix", trimCommitActionAppUrlPrefix), // V5 -> V6:v0.6.3
62-
NewMigration("generate issue-label from issue", issueToIssueLabel), // V6 -> V7:v0.6.4
63-
NewMigration("refactor attachment table", attachmentRefactor), // V7 -> V8:v0.6.4
64-
NewMigration("rename pull request fields", renamePullRequestFields), // V8 -> V9:v0.6.16
65-
NewMigration("clean up migrate repo info", cleanUpMigrateRepoInfo), // V9 -> V10:v0.6.20
61+
NewMigration("fix locale file load panic", fixLocaleFileLoadPanic), // V4 -> V5:v0.6.0
62+
NewMigration("trim action compare URL prefix", trimCommitActionAppUrlPrefix), // V5 -> V6:v0.6.3
63+
NewMigration("generate issue-label from issue", issueToIssueLabel), // V6 -> V7:v0.6.4
64+
NewMigration("refactor attachment table", attachmentRefactor), // V7 -> V8:v0.6.4
65+
NewMigration("rename pull request fields", renamePullRequestFields), // V8 -> V9:v0.6.16
66+
NewMigration("clean up migrate repo info", cleanUpMigrateRepoInfo), // V9 -> V10:v0.6.20
67+
NewMigration("generate rands and salt for organizations", generateOrgRandsAndSalt), // V10 -> V11:v0.8.5
6668
}
6769

6870
// Migrate database to current version
@@ -422,3 +424,32 @@ func cleanUpMigrateRepoInfo(x *xorm.Engine) (err error) {
422424

423425
return nil
424426
}
427+
428+
func generateOrgRandsAndSalt(x *xorm.Engine) (err error) {
429+
type User struct {
430+
ID int64 `xorm:"pk autoincr"`
431+
Rands string `xorm:"VARCHAR(10)"`
432+
Salt string `xorm:"VARCHAR(10)"`
433+
}
434+
435+
orgs := make([]*User, 0, 10)
436+
if err = x.Where("type=1").And("rands=''").Find(&orgs); err != nil {
437+
return fmt.Errorf("select all organizations: %v", err)
438+
}
439+
440+
sess := x.NewSession()
441+
defer sessionRelease(sess)
442+
if err = sess.Begin(); err != nil {
443+
return err
444+
}
445+
446+
for _, org := range orgs {
447+
org.Rands = base.GetRandomString(10)
448+
org.Salt = base.GetRandomString(10)
449+
if _, err = sess.Id(org.ID).Update(org); err != nil {
450+
return err
451+
}
452+
}
453+
454+
return sess.Commit()
455+
}

models/org.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ func CreateOrganization(org, owner *User) (err error) {
108108

109109
org.LowerName = strings.ToLower(org.Name)
110110
org.FullName = org.Name
111+
org.Rands = GetUserSalt()
112+
org.Salt = GetUserSalt()
111113
org.UseCustomAvatar = true
112114
org.MaxRepoCreation = -1
113115
org.NumTeams = 1

routers/repo/pull.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package repo
66

77
import (
88
"container/list"
9-
"errors"
109
"path"
1110
"strings"
1211

@@ -644,17 +643,24 @@ func CompareAndPullRequestPost(ctx *middleware.Context, form auth.CreateIssueFor
644643
}
645644

646645
func TriggerTask(ctx *middleware.Context) {
647-
_, repo := parseOwnerAndRepo(ctx)
646+
branch := ctx.Query("branch")
647+
secret := ctx.Query("secret")
648+
if len(branch) == 0 || len(secret) == 0 {
649+
ctx.Error(404)
650+
log.Trace("TriggerTask: branch or secret is empty")
651+
return
652+
}
653+
owner, repo := parseOwnerAndRepo(ctx)
648654
if ctx.Written() {
649655
return
650656
}
651-
branch := ctx.Query("branch")
652-
if len(branch) == 0 {
653-
ctx.Handle(422, "TriggerTask", errors.New("branch is empty"))
657+
if secret != base.EncodeMD5(owner.Salt) {
658+
ctx.Error(404)
659+
log.Trace("TriggerTask [%s/%s]: invalid secret", owner.Name, repo.Name)
654660
return
655661
}
656662

657-
log.Trace("TriggerTask[%d].(new request): %s", repo.ID, branch)
663+
log.Trace("TriggerTask [%d].(new request): %s", repo.ID, branch)
658664

659665
go models.HookQueue.Add(repo.ID)
660666
go models.AddTestPullRequestTask(repo.ID, branch)

templates/.VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.4.1214
1+
0.8.5.1214

0 commit comments

Comments
 (0)