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

Fixed vulnerabilities #392

Merged
merged 1 commit into from
Dec 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions models/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,14 @@ func UpdateAccessToken(t *AccessToken) error {
}

// DeleteAccessTokenByID deletes access token by given ID.
func DeleteAccessTokenByID(id int64) error {
_, err := x.Id(id).Delete(new(AccessToken))
return err
func DeleteAccessTokenByID(id, userID int64) error {
cnt, err := x.Id(id).Delete(&AccessToken{
UID: userID,
})
if err != nil {
return err
} else if cnt != 1 {
Copy link
Member

Choose a reason for hiding this comment

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

nitpicking, the else is not needed here

Copy link
Member Author

Choose a reason for hiding this comment

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

It will reduce one line code counting. :)

return ErrAccessTokenNotExist{}
}
return nil
}
25 changes: 21 additions & 4 deletions models/user_mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
package models

import (
"errors"
"fmt"
"strings"
)

var (
// ErrEmailAddressNotExist email address not exist
ErrEmailAddressNotExist = errors.New("Email address does not exist")
)

// EmailAddress is the list of all email addresses of a user. Can contain the
// primary email address, but is not obligatory.
type EmailAddress struct {
Expand Down Expand Up @@ -139,14 +145,25 @@ func (email *EmailAddress) Activate() error {

// DeleteEmailAddress deletes an email address of given user.
func DeleteEmailAddress(email *EmailAddress) (err error) {
var deleted int64
// ask to check UID
var address = EmailAddress{
UID: email.UID,
}
if email.ID > 0 {
_, err = x.Id(email.ID).Delete(new(EmailAddress))
deleted, err = x.Id(email.ID).Delete(&address)
} else {
_, err = x.
deleted, err = x.
Where("email=?", email.Email).
Delete(new(EmailAddress))
Delete(&address)
}
return err

if err != nil {
return err
} else if deleted != 1 {
return ErrEmailAddressNotExist
}
return nil
}

// DeleteEmailAddresses deletes multiple email addresses
Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/user/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func DeleteEmail(ctx *context.APIContext, form api.CreateEmailOption) {
for i := range form.Emails {
emails[i] = &models.EmailAddress{
Email: form.Emails[i],
UID: ctx.User.ID,
}
}

Expand Down
4 changes: 2 additions & 2 deletions routers/user/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func SettingsEmailPost(ctx *context.Context, form auth.AddEmailForm) {

// DeleteEmail response for delete user's email
func DeleteEmail(ctx *context.Context) {
if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id")}); err != nil {
if err := models.DeleteEmailAddress(&models.EmailAddress{ID: ctx.QueryInt64("id"), UID: ctx.User.ID}); err != nil {
ctx.Handle(500, "DeleteEmail", err)
return
}
Expand Down Expand Up @@ -422,7 +422,7 @@ func SettingsApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm

// SettingsDeleteApplication response for delete user access token
func SettingsDeleteApplication(ctx *context.Context) {
if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id")); err != nil {
if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id"), ctx.User.ID); err != nil {
ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
} else {
ctx.Flash.Success(ctx.Tr("settings.delete_token_success"))
Expand Down