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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
444062d9
Commit
444062d9
authored
Nov 13, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not use cleartext approach for encrypted tokens
parent
2dbc4175
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
8 deletions
+8
-8
app/models/concerns/token_authenticatable_strategies/encrypted.rb
...ls/concerns/token_authenticatable_strategies/encrypted.rb
+8
-8
No files found.
app/models/concerns/token_authenticatable_strategies/encrypted.rb
View file @
444062d9
# frozen_string_literal: true
# frozen_string_literal: true
@parallelizable
.
with_indifferent_access
module
TokenAuthenticatableStrategies
module
TokenAuthenticatableStrategies
class
Encrypted
<
Base
class
Encrypted
<
Base
def
find_token_authenticatable
(
token
,
unscoped
=
false
)
def
find_token_authenticatable
(
token
,
unscoped
=
false
)
...
@@ -16,25 +18,23 @@ module TokenAuthenticatableStrategies
...
@@ -16,25 +18,23 @@ module TokenAuthenticatableStrategies
end
end
def
get_token
(
instance
)
def
get_token
(
instance
)
token
=
instance
.
cleartext_tokens
.
to_h
[
@token_field
]
raw_token
=
instance
.
read_attribute
(
token_field_name
)
token
=
Gitlab
::
CryptoHelper
.
aes256_gcm_decrypt
(
raw_token
)
token
||=
fallback_strategy
.
get_token
(
instance
)
if
@options
[
:fallback
]
token
||=
fallback_strategy
.
get_token
(
instance
)
if
@options
[
:fallback
]
token
end
end
def
set_token
(
instance
,
token
)
def
set_token
(
instance
,
token
)
r
eturn
unless
token
r
aise
ArgumentError
unless
token
instance
.
cleartext_tokens
||=
{}
instance
.
cleartext_tokens
[
@token_field
]
=
token
instance
[
token_field_name
]
=
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
token
)
instance
[
token_field_name
]
=
Gitlab
::
CryptoHelper
.
aes256_gcm_encrypt
(
token
)
instance
[
@token_field
]
=
nil
if
@options
[
:fallback
]
# TODO this seems wrong
#
instance[@token_field] = nil if @options[:fallback] # TODO this seems wrong
end
end
protected
protected
def
fallback_strategy
def
fallback_strategy
@fallback_strategy
||=
TokenAuthenticatableStrategies
::
Insecure
.
new
(
@klass
,
@token_field
,
@options
)
@fallback_strategy
||=
TokenAuthenticatableStrategies
::
Insecure
.
new
(
@klass
,
@token_field
,
@options
)
end
end
def
token_set?
(
instance
)
def
token_set?
(
instance
)
...
...
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