Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
galene
Commits
37ef768a
Commit
37ef768a
authored
Feb 20, 2022
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix token parsing when aud is an array.
parent
a9c95814
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
11 deletions
+26
-11
token/token.go
token/token.go
+26
-11
No files found.
token/token.go
View file @
37ef768a
...
...
@@ -37,7 +37,7 @@ func parseKey(key map[string]interface{}) (interface{}, error) {
switch
kty
{
case
"oct"
:
var
length
int
switch
(
alg
)
{
switch
alg
{
case
"HS256"
:
length
=
32
case
"HS384"
:
...
...
@@ -105,6 +105,18 @@ func getKey(header map[string]interface{}, keys []map[string]interface{}) (inter
return
nil
,
errors
.
New
(
"key not found"
)
}
func
toStringArray
(
a
[]
interface
{})
([]
string
,
bool
)
{
b
:=
make
([]
string
,
len
(
a
))
for
i
,
v
:=
range
a
{
w
,
ok
:=
v
.
(
string
)
if
!
ok
{
return
nil
,
false
}
b
[
i
]
=
w
}
return
b
,
true
}
func
Valid
(
username
,
token
string
,
keys
[]
map
[
string
]
interface
{})
([]
string
,
[]
string
,
error
)
{
tok
,
err
:=
jwt
.
Parse
(
token
,
func
(
t
*
jwt
.
Token
)
(
interface
{},
error
)
{
return
getKey
(
t
.
Header
,
keys
)
...
...
@@ -124,8 +136,15 @@ func Valid(username, token string, keys []map[string]interface{}) ([]string, []s
switch
a
:=
a
.
(
type
)
{
case
string
:
aud
=
[]
string
{
a
}
case
[]
string
:
aud
=
a
case
[]
interface
{}
:
aud
,
ok
=
toStringArray
(
a
)
if
!
ok
{
return
nil
,
nil
,
errors
.
New
(
"invalid 'aud' field"
)
}
default
:
return
nil
,
nil
,
errors
.
New
(
"invalid 'aud' field"
)
}
}
...
...
@@ -136,15 +155,11 @@ func Valid(username, token string, keys []map[string]interface{}) ([]string, []s
return
nil
,
nil
,
errors
.
New
(
"invalid 'permissions' field"
)
}
perms
=
make
([]
string
,
len
(
pp
))
for
i
,
v
:=
range
pp
{
w
,
ok
:=
v
.
(
string
)
perms
,
ok
=
toStringArray
(
pp
)
if
!
ok
{
return
nil
,
nil
,
errors
.
New
(
"invalid 'permissions' field"
)
}
perms
[
i
]
=
w
}
}
return
aud
,
perms
,
nil
}
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