Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
e81a7b71
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e81a7b71
编写于
5月 26, 2020
作者:
G
GitLab Bot
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add latest changes from gitlab-org/security/gitlab@12-10-stable-ee
上级
f7fd30fc
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
117 addition
and
3 deletion
+117
-3
app/models/user.rb
app/models/user.rb
+6
-3
changelogs/unreleased/security-fix-email-confirmation-bug.yml
...gelogs/unreleased/security-fix-email-confirmation-bug.yml
+5
-0
spec/factories/users.rb
spec/factories/users.rb
+4
-0
spec/models/user_spec.rb
spec/models/user_spec.rb
+102
-0
未找到文件。
app/models/user.rb
浏览文件 @
e81a7b71
...
...
@@ -228,9 +228,10 @@ class User < ApplicationRecord
if
previous_changes
.
key?
(
'email'
)
# Grab previous_email here since previous_changes changes after
# #update_emails_with_primary_email and #update_notification_email are called
previous_confirmed_at
=
previous_changes
.
key?
(
'confirmed_at'
)
?
previous_changes
[
'confirmed_at'
][
0
]
:
confirmed_at
previous_email
=
previous_changes
[
:email
][
0
]
update_emails_with_primary_email
(
previous_email
)
update_emails_with_primary_email
(
previous_
confirmed_at
,
previous_
email
)
update_invalid_gpg_signatures
if
previous_email
==
notification_email
...
...
@@ -830,13 +831,15 @@ class User < ApplicationRecord
# By using an `after_commit` instead of `after_update`, we avoid the recursive callback
# scenario, though it then requires us to use the `previous_changes` hash
# rubocop: disable CodeReuse/ServiceClass
def
update_emails_with_primary_email
(
previous_email
)
def
update_emails_with_primary_email
(
previous_
confirmed_at
,
previous_
email
)
primary_email_record
=
emails
.
find_by
(
email:
email
)
Emails
::
DestroyService
.
new
(
self
,
user:
self
).
execute
(
primary_email_record
)
if
primary_email_record
# the original primary email was confirmed, and we want that to carry over. We don't
# have access to the original confirmation values at this point, so just set confirmed_at
Emails
::
CreateService
.
new
(
self
,
user:
self
,
email:
previous_email
).
execute
(
confirmed_at:
confirmed_at
)
Emails
::
CreateService
.
new
(
self
,
user:
self
,
email:
previous_email
).
execute
(
confirmed_at:
previous_confirmed_at
)
update_columns
(
confirmed_at:
primary_email_record
.
confirmed_at
)
if
primary_email_record
&
.
confirmed_at
end
# rubocop: enable CodeReuse/ServiceClass
...
...
changelogs/unreleased/security-fix-email-confirmation-bug.yml
0 → 100644
浏览文件 @
e81a7b71
---
title
:
Fix confirming unverified emails with soft email confirmation flow enabled
merge_request
:
author
:
type
:
security
spec/factories/users.rb
浏览文件 @
e81a7b71
...
...
@@ -44,6 +44,10 @@ FactoryBot.define do
after
(
:build
)
{
|
user
,
_
|
user
.
block!
}
end
trait
:unconfirmed
do
confirmed_at
{
nil
}
end
trait
:with_avatar
do
avatar
{
fixture_file_upload
(
'spec/fixtures/dk.png'
)
}
end
...
...
spec/models/user_spec.rb
浏览文件 @
e81a7b71
...
...
@@ -914,6 +914,108 @@ describe User, :do_not_mock_admin_mode do
expect
(
@user
.
emails
.
count
).
to
eq
1
expect
(
@user
.
emails
.
first
.
confirmed_at
).
not_to
eq
nil
end
context
'when the first email was unconfirmed and the second email gets confirmed'
do
let_it_be
(
:user
)
{
create
(
:user
,
:unconfirmed
,
email:
'should-be-unconfirmed@test.com'
)
}
before
do
user
.
update!
(
email:
'should-be-confirmed@test.com'
)
user
.
confirm
end
it
'updates user.email'
do
expect
(
user
.
email
).
to
eq
(
'should-be-confirmed@test.com'
)
end
it
'confirms user.email'
do
expect
(
user
).
to
be_confirmed
end
it
'keeps the unconfirmed email unconfirmed'
do
email
=
user
.
emails
.
first
expect
(
email
.
email
).
to
eq
(
'should-be-unconfirmed@test.com'
)
expect
(
email
).
not_to
be_confirmed
end
it
'has only one email association'
do
expect
(
user
.
emails
.
size
).
to
be
(
1
)
end
end
end
context
'when an existing email record is set as primary'
do
let
(
:user
)
{
create
(
:user
,
email:
'confirmed@test.com'
)
}
context
'when it is unconfirmed'
do
let
(
:originally_unconfirmed_email
)
{
'should-stay-unconfirmed@test.com'
}
before
do
user
.
emails
<<
create
(
:email
,
email:
originally_unconfirmed_email
,
confirmed_at:
nil
)
user
.
update!
(
email:
originally_unconfirmed_email
)
end
it
'keeps the user confirmed'
do
expect
(
user
).
to
be_confirmed
end
it
'keeps the original email'
do
expect
(
user
.
email
).
to
eq
(
'confirmed@test.com'
)
end
context
'when the email gets confirmed'
do
before
do
user
.
confirm
end
it
'keeps the user confirmed'
do
expect
(
user
).
to
be_confirmed
end
it
'updates the email'
do
expect
(
user
.
email
).
to
eq
(
originally_unconfirmed_email
)
end
end
end
context
'when it is confirmed'
do
let!
(
:old_confirmed_email
)
{
user
.
email
}
let
(
:confirmed_email
)
{
'already-confirmed@test.com'
}
before
do
user
.
emails
<<
create
(
:email
,
:confirmed
,
email:
confirmed_email
)
user
.
update!
(
email:
confirmed_email
)
end
it
'keeps the user confirmed'
do
expect
(
user
).
to
be_confirmed
end
it
'updates the email'
do
expect
(
user
.
email
).
to
eq
(
confirmed_email
)
end
it
'moves the old email'
do
email
=
user
.
reload
.
emails
.
first
expect
(
email
.
email
).
to
eq
(
old_confirmed_email
)
expect
(
email
).
to
be_confirmed
end
end
end
context
'when unconfirmed user deletes a confirmed additional email'
do
let
(
:user
)
{
create
(
:user
,
:unconfirmed
)
}
before
do
user
.
emails
<<
create
(
:email
,
:confirmed
)
end
it
'does not affect the confirmed status'
do
expect
{
user
.
emails
.
confirmed
.
destroy_all
}.
not_to
change
{
user
.
confirmed?
}
# rubocop: disable Cop/DestroyAll
end
end
describe
'#update_notification_email'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录