Skip to content

Commit 529694d

Browse files
unknwonmpsonntag
authored andcommitted
email: check the owner when set as primary (#5988)
* email: check the owner when set as primary Fixes a security issue reported by muxishuihan. * Update CHANGELOG
1 parent e12a86d commit 529694d

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ All notable changes to Gogs are documented in this file.
3737

3838
- [Security] Potential open redirection with i18n.
3939
- [Security] Potential ability to delete files outside a repository.
40+
- [Security] Potential ability to set primary email on others' behalf from their verified emails.
4041
- [Security] Potential RCE on mirror repositories. [#5767](https://github.com/gogs/gogs/issues/5767)
4142
- [Security] Potential XSS attack with raw markdown API. [#5907](https://github.com/gogs/gogs/pull/5907)
4243
- Open/close milestone redirects to a 404 page. [#5677](https://github.com/gogs/gogs/issues/5677)

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pack:
4242

4343
release: build pack
4444

45-
generate: $(ASSETS_GENERATED)
45+
generate: clean $(ASSETS_GENERATED)
4646

4747
internal/assets/conf/conf_gen.go: $(CONF_FILES)
4848
-rm -f $@
@@ -59,7 +59,7 @@ internal/assets/public/public_gen.go: $(PUBLIC_FILES)
5959
go generate internal/assets/public/public.go
6060
gofmt -s -w $@
6161

62-
less: public/css/gogs.min.css
62+
less: clean public/css/gogs.min.css
6363

6464
public/css/gogs.min.css: $(LESS_FILES)
6565
@type lessc >/dev/null 2>&1 && lessc --clean-css --source-map "public/less/gogs.less" $@ || echo "lessc command not found or failed"

internal/db/user_mail.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,18 @@ func DeleteEmailAddresses(emails []*EmailAddress) (err error) {
160160
return nil
161161
}
162162

163-
func MakeEmailPrimary(email *EmailAddress) error {
163+
func MakeEmailPrimary(userID int64, email *EmailAddress) error {
164164
has, err := x.Get(email)
165165
if err != nil {
166166
return err
167167
} else if !has {
168168
return errors.EmailNotFound{Email: email.Email}
169169
}
170170

171+
if email.UID != userID {
172+
return errors.New("not the owner of the email")
173+
}
174+
171175
if !email.IsActivated {
172176
return errors.EmailNotVerified{Email: email.Email}
173177
}

internal/route/user/setting.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func SettingsEmailPost(c *context.Context, f form.AddEmail) {
237237

238238
// Make emailaddress primary.
239239
if c.Query("_method") == "PRIMARY" {
240-
if err := db.MakeEmailPrimary(&db.EmailAddress{ID: c.QueryInt64("id")}); err != nil {
240+
if err := db.MakeEmailPrimary(c.UserID(), &db.EmailAddress{ID: c.QueryInt64("id")}); err != nil {
241241
c.ServerError("MakeEmailPrimary", err)
242242
return
243243
}

0 commit comments

Comments
 (0)