Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uffd2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thies
uffd2
Commits
9bfd6f81
Commit
9bfd6f81
authored
3 years ago
by
Julian
Browse files
Options
Downloads
Patches
Plain Diff
Verify OAuth2 codes/tokens in constant-time
This change effectivly invalidates all existing grants/tokens.
parent
7d472944
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
uffd/oauth2/views.py
+15
-4
15 additions, 4 deletions
uffd/oauth2/views.py
with
15 additions
and
4 deletions
uffd/oauth2/views.py
+
15
−
4
View file @
9bfd6f81
...
@@ -58,10 +58,16 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
...
@@ -58,10 +58,16 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
redirect_uri
=
oauthreq
.
redirect_uri
,
expires
=
expires
,
_scopes
=
'
'
.
join
(
oauthreq
.
scopes
))
redirect_uri
=
oauthreq
.
redirect_uri
,
expires
=
expires
,
_scopes
=
'
'
.
join
(
oauthreq
.
scopes
))
db
.
session
.
add
(
grant
)
db
.
session
.
add
(
grant
)
db
.
session
.
commit
()
db
.
session
.
commit
()
code
[
'
code
'
]
=
f
"
{
grant
.
id
}
-
{
code
[
'
code
'
]
}
"
def
validate_code
(
self
,
client_id
,
code
,
client
,
oauthreq
,
*
args
,
**
kwargs
):
def
validate_code
(
self
,
client_id
,
code
,
client
,
oauthreq
,
*
args
,
**
kwargs
):
oauthreq
.
grant
=
OAuth2Grant
.
query
.
filter_by
(
client_id
=
client_id
,
code
=
code
).
first
()
if
'
-
'
not
in
code
:
if
not
oauthreq
.
grant
:
return
False
grant_id
,
grant_code
=
code
.
split
(
'
-
'
,
2
)
oauthreq
.
grant
=
OAuth2Grant
.
query
.
get
(
grant_id
)
if
not
oauthreq
.
grant
or
oauthreq
.
grant
.
client_id
!=
client_id
:
return
False
if
not
secrets
.
compare_digest
(
oauthreq
.
grant
.
code
,
grant_code
):
return
False
return
False
if
datetime
.
datetime
.
utcnow
()
>
oauthreq
.
grant
.
expires
:
if
datetime
.
datetime
.
utcnow
()
>
oauthreq
.
grant
.
expires
:
return
False
return
False
...
@@ -88,6 +94,8 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
...
@@ -88,6 +94,8 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
)
)
db
.
session
.
add
(
tok
)
db
.
session
.
add
(
tok
)
db
.
session
.
commit
()
db
.
session
.
commit
()
token_data
[
'
access_token
'
]
=
f
"
{
tok
.
id
}
-
{
token_data
[
'
access_token
'
]
}
"
token_data
[
'
refresh_token
'
]
=
f
"
{
tok
.
id
}
-
{
token_data
[
'
refresh_token
'
]
}
"
return
oauthreq
.
client
.
default_redirect_uri
return
oauthreq
.
client
.
default_redirect_uri
def
validate_grant_type
(
self
,
client_id
,
grant_type
,
client
,
oauthreq
,
*
args
,
**
kwargs
):
def
validate_grant_type
(
self
,
client_id
,
grant_type
,
client
,
oauthreq
,
*
args
,
**
kwargs
):
...
@@ -97,8 +105,11 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
...
@@ -97,8 +105,11 @@ class UffdRequestValidator(oauthlib.oauth2.RequestValidator):
return
redirect_uri
==
oauthreq
.
grant
.
redirect_uri
return
redirect_uri
==
oauthreq
.
grant
.
redirect_uri
def
validate_bearer_token
(
self
,
token_value
,
scopes
,
oauthreq
):
def
validate_bearer_token
(
self
,
token_value
,
scopes
,
oauthreq
):
tok
=
OAuth2Token
.
query
.
filter_by
(
access_token
=
token_value
).
first
()
if
'
-
'
not
in
token_value
:
if
not
tok
:
return
False
tok_id
,
tok_secret
=
token_value
.
split
(
'
-
'
,
2
)
tok
=
OAuth2Token
.
query
.
get
(
tok_id
)
if
not
tok
or
not
secrets
.
compare_digest
(
tok
.
access_token
,
tok_secret
):
return
False
return
False
if
datetime
.
datetime
.
utcnow
()
>
tok
.
expires
:
if
datetime
.
datetime
.
utcnow
()
>
tok
.
expires
:
oauthreq
.
error_message
=
'
Token expired
'
oauthreq
.
error_message
=
'
Token expired
'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment