Skip to content

Commit bf385a1

Browse files
jackHay22GiteaBot
authored andcommitted
Prevent a user with a different email from accepting the team invite (go-gitea#24491)
## Changes - Fixes the case where a logged in user can accept an email invitation even if their email address does not match the address in the invitation
1 parent 8ceb78c commit bf385a1

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,6 +2490,7 @@ teams.all_repositories_admin_permission_desc = This team grants <strong>Admin</s
24902490
teams.invite.title = You've been invited to join team <strong>%s</strong> in organization <strong>%s</strong>.
24912491
teams.invite.by = Invited by %s
24922492
teams.invite.description = Please click the button below to join the team.
2493+
teams.invite.email_mismatch = Your email address does not match this invite.
24932494
24942495
[admin]
24952496
dashboard = Dashboard

routers/web/org/teams.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ func TeamInvite(ctx *context.Context) {
536536
ctx.Data["Organization"] = org
537537
ctx.Data["Team"] = team
538538
ctx.Data["Inviter"] = inviter
539+
ctx.Data["EmailMismatch"] = ctx.Doer.Email != invite.Email
539540

540541
ctx.HTML(http.StatusOK, tplTeamInvite)
541542
}
@@ -552,6 +553,13 @@ func TeamInvitePost(ctx *context.Context) {
552553
return
553554
}
554555

556+
// check that the Doer is the invitee
557+
if ctx.Doer.Email != invite.Email {
558+
log.Info("invite %d does not apply to the current user %d", invite.ID, ctx.Doer.ID)
559+
ctx.NotFound("ErrTeamInviteNotFound", err)
560+
return
561+
}
562+
555563
if err := models.AddTeamMember(team, ctx.Doer.ID); err != nil {
556564
ctx.ServerError("AddTeamMember", err)
557565
return

templates/org/team/invite.tmpl

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
<div class="image">
77
{{avatar $.Context .Organization 140}}
88
</div>
9-
<div class="content">
10-
<div class="header">{{.locale.Tr "org.teams.invite.title" .Team.Name .Organization.Name | Str2html}}</div>
11-
<div class="meta">{{.locale.Tr "org.teams.invite.by" .Inviter.Name}}</div>
12-
<div class="description">{{.locale.Tr "org.teams.invite.description"}}</div>
13-
</div>
14-
<div class="extra content">
15-
<form class="ui form" action="" method="post">
16-
{{.CsrfTokenHtml}}
17-
<button class="fluid ui green button">{{.locale.Tr "org.teams.join"}}</button>
18-
</form>
19-
</div>
9+
{{if .EmailMismatch}}
10+
<div class="content">
11+
<div class="header">{{.locale.Tr "org.teams.invite.email_mismatch"}}</div>
12+
</div>
13+
{{else}}
14+
<div class="content">
15+
<div class="header">{{.locale.Tr "org.teams.invite.title" .Team.Name .Organization.Name | Str2html}}</div>
16+
<div class="meta">{{.locale.Tr "org.teams.invite.by" .Inviter.Name}}</div>
17+
<div class="description">{{.locale.Tr "org.teams.invite.description"}}</div>
18+
</div>
19+
<div class="extra content">
20+
<form class="ui form" action="" method="post">
21+
{{.CsrfTokenHtml}}
22+
<button class="fluid ui green button">{{.locale.Tr "org.teams.join"}}</button>
23+
</form>
24+
</div>
25+
{{end}}
2026
</div>
2127
</div>
2228
</div>

0 commit comments

Comments
 (0)