Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
84cd552f
Commit
84cd552f
authored
Nov 29, 2019
by
Adam Hegyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent API access for unconfirmed users
- Add feature flag to disable `unconfirmed` condition.
parent
17fc902d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
9 deletions
+99
-9
app/policies/base_policy.rb
app/policies/base_policy.rb
+8
-0
app/policies/global_policy.rb
app/policies/global_policy.rb
+7
-0
changelogs/unreleased/security-email-confirmation-bypass-via-api-ee.yml
...eleased/security-email-confirmation-bypass-via-api-ee.yml
+5
-0
spec/policies/global_policy_spec.rb
spec/policies/global_policy_spec.rb
+56
-0
spec/requests/api/oauth_tokens_spec.rb
spec/requests/api/oauth_tokens_spec.rb
+23
-9
No files found.
app/policies/base_policy.rb
View file @
84cd552f
...
...
@@ -21,6 +21,14 @@ class BasePolicy < DeclarativePolicy::Base
with_options
scope: :user
,
score:
0
condition
(
:deactivated
)
{
@user
&
.
deactivated?
}
desc
"User email is unconfirmed or user account is locked"
with_options
scope: :user
,
score:
0
condition
(
:inactive
)
do
Feature
.
enabled?
(
:inactive_policy_condition
,
default_enabled:
true
)
&&
@user
&&
!
@user
&
.
active_for_authentication?
end
with_options
scope: :user
,
score:
0
condition
(
:external_user
)
{
@user
.
nil?
||
@user
.
external?
}
...
...
app/policies/global_policy.rb
View file @
84cd552f
...
...
@@ -36,6 +36,13 @@ class GlobalPolicy < BasePolicy
enable
:use_slash_commands
end
rule
{
inactive
}.
policy
do
prevent
:log_in
prevent
:access_api
prevent
:access_git
prevent
:use_slash_commands
end
rule
{
blocked
|
internal
}.
policy
do
prevent
:log_in
prevent
:access_api
...
...
changelogs/unreleased/security-email-confirmation-bypass-via-api-ee.yml
0 → 100644
View file @
84cd552f
---
title
:
Prevent API access for unconfirmed users
merge_request
:
author
:
type
:
security
spec/policies/global_policy_spec.rb
View file @
84cd552f
...
...
@@ -141,6 +141,34 @@ describe GlobalPolicy do
it
{
is_expected
.
to
be_allowed
(
:access_api
)
}
end
end
context
'inactive user'
do
before
do
current_user
.
update!
(
confirmed_at:
nil
,
confirmation_sent_at:
5
.
days
.
ago
)
end
context
'when within the confirmation grace period'
do
before
do
allow
(
User
).
to
receive
(
:allow_unconfirmed_access_for
).
and_return
(
10
.
days
)
end
it
{
is_expected
.
to
be_allowed
(
:access_api
)
}
end
context
'when confirmation grace period is expired'
do
before
do
allow
(
User
).
to
receive
(
:allow_unconfirmed_access_for
).
and_return
(
2
.
days
)
end
it
{
is_expected
.
not_to
be_allowed
(
:access_api
)
}
end
it
'when `inactive_policy_condition` feature flag is turned off'
do
stub_feature_flags
(
inactive_policy_condition:
false
)
is_expected
.
to
be_allowed
(
:access_api
)
end
end
end
describe
'receive notifications'
do
...
...
@@ -202,6 +230,20 @@ describe GlobalPolicy do
it
{
is_expected
.
not_to
be_allowed
(
:access_git
)
}
end
describe
'inactive user'
do
before
do
current_user
.
update!
(
confirmed_at:
nil
)
end
it
{
is_expected
.
not_to
be_allowed
(
:access_git
)
}
it
'when `inactive_policy_condition` feature flag is turned off'
do
stub_feature_flags
(
inactive_policy_condition:
false
)
is_expected
.
to
be_allowed
(
:access_git
)
end
end
context
'when terms are enforced'
do
before
do
enforce_terms
...
...
@@ -298,6 +340,20 @@ describe GlobalPolicy do
it
{
is_expected
.
not_to
be_allowed
(
:use_slash_commands
)
}
end
describe
'inactive user'
do
before
do
current_user
.
update!
(
confirmed_at:
nil
)
end
it
{
is_expected
.
not_to
be_allowed
(
:use_slash_commands
)
}
it
'when `inactive_policy_condition` feature flag is turned off'
do
stub_feature_flags
(
inactive_policy_condition:
false
)
is_expected
.
to
be_allowed
(
:use_slash_commands
)
end
end
context
'when access locked'
do
before
do
current_user
.
lock_access!
...
...
spec/requests/api/oauth_tokens_spec.rb
View file @
84cd552f
...
...
@@ -30,26 +30,40 @@ describe 'OAuth tokens' do
end
end
context
"when user is blocked"
do
it
"does not create an access token"
do
user
=
create
(
:user
)
shared_examples
'does not create an access token'
do
let
(
:user
)
{
create
(
:user
)
}
it
{
expect
(
response
).
to
have_gitlab_http_status
(
401
)
}
end
context
'when user is blocked'
do
before
do
user
.
block
request_oauth_token
(
user
)
expect
(
response
).
to
have_gitlab_http_status
(
401
)
end
include_examples
'does not create an access token'
end
context
"when user is ldap_blocked"
do
it
"does not create an access token"
do
user
=
create
(
:user
)
context
'when user is ldap_blocked'
do
before
do
user
.
ldap_block
request_oauth_token
(
user
)
end
expect
(
response
).
to
have_gitlab_http_status
(
401
)
include_examples
'does not create an access token'
end
context
'when user account is not confirmed'
do
before
do
user
.
update!
(
confirmed_at:
nil
)
request_oauth_token
(
user
)
end
include_examples
'does not create an access token'
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment