Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WIMMA Lab 2019
Overflow
ehasa-backend
Commits
9254070b
Commit
9254070b
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
added gameId to jwt to deny admin exploit
parent
211faef1
No related branches found
Branches containing commit
No related tags found
2 merge requests
!59
Development to master
,
!18
Join game
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/game/game.entity.ts
+2
-1
2 additions, 1 deletion
src/game/game.entity.ts
src/shared/roles.guard.ts
+4
-4
4 additions, 4 deletions
src/shared/roles.guard.ts
with
6 additions
and
5 deletions
src/game/game.entity.ts
+
2
−
1
View file @
9254070b
...
@@ -75,10 +75,11 @@ export class Game_PersonEntity {
...
@@ -75,10 +75,11 @@ export class Game_PersonEntity {
return
gametoken
;
return
gametoken
;
}
}
private
get
gametoken
()
{
private
get
gametoken
()
{
const
{
gamepersonId
,
role
}
=
this
;
const
{
gamepersonId
,
game
,
role
}
=
this
;
return
jwt
.
sign
(
return
jwt
.
sign
(
{
{
gamepersonId
,
gamepersonId
,
game
,
role
,
role
,
},
},
process
.
env
.
SECRET
,
process
.
env
.
SECRET
,
...
...
This diff is collapsed.
Click to expand it.
src/shared/roles.guard.ts
+
4
−
4
View file @
9254070b
...
@@ -5,9 +5,7 @@ import {
...
@@ -5,9 +5,7 @@ import {
HttpException
,
HttpException
,
HttpStatus
,
HttpStatus
,
}
from
'
@nestjs/common
'
;
}
from
'
@nestjs/common
'
;
import
{
Observable
}
from
'
rxjs
'
;
import
{
Reflector
}
from
'
@nestjs/core
'
;
import
{
Reflector
}
from
'
@nestjs/core
'
;
import
*
as
jwt
from
'
jsonwebtoken
'
;
import
*
as
jwt
from
'
jsonwebtoken
'
;
@
Injectable
()
@
Injectable
()
...
@@ -15,13 +13,16 @@ export class RolesGuard implements CanActivate {
...
@@ -15,13 +13,16 @@ export class RolesGuard implements CanActivate {
constructor
(
private
readonly
reflector
:
Reflector
)
{}
constructor
(
private
readonly
reflector
:
Reflector
)
{}
async
canActivate
(
context
:
ExecutionContext
):
Promise
<
boolean
>
{
async
canActivate
(
context
:
ExecutionContext
):
Promise
<
boolean
>
{
// get roles that are allowed access, identified by @Roles('role') decorators in controllers
const
roles
=
this
.
reflector
.
get
<
string
[]
>
(
'
roles
'
,
context
.
getHandler
());
const
roles
=
this
.
reflector
.
get
<
string
[]
>
(
'
roles
'
,
context
.
getHandler
());
if
(
!
roles
)
{
if
(
!
roles
)
{
return
true
;
return
true
;
}
}
const
request
=
context
.
switchToHttp
().
getRequest
();
const
request
=
context
.
switchToHttp
().
getRequest
();
const
gameId
=
request
.
params
.
id
const
role
=
await
this
.
checkRole
(
request
.
headers
.
authorization
);
const
role
=
await
this
.
checkRole
(
request
.
headers
.
authorization
);
return
roles
.
includes
(
role
[
'
role
'
])
// check that the role matches the criteria and that token is valid for this game
return
roles
.
includes
(
role
[
'
role
'
])
&&
role
[
'
game
'
][
'
id
'
]
===
gameId
;
}
}
async
checkRole
(
auth
:
string
)
{
async
checkRole
(
auth
:
string
)
{
...
@@ -32,7 +33,6 @@ export class RolesGuard implements CanActivate {
...
@@ -32,7 +33,6 @@ export class RolesGuard implements CanActivate {
// get the token
// get the token
const
token
=
auth
.
split
(
'
'
)[
1
];
const
token
=
auth
.
split
(
'
'
)[
1
];
try
{
try
{
console
.
log
(
jwt
.
verify
(
token
,
process
.
env
.
SECRET
))
return
await
jwt
.
verify
(
token
,
process
.
env
.
SECRET
)
return
await
jwt
.
verify
(
token
,
process
.
env
.
SECRET
)
}
catch
(
err
)
{
}
catch
(
err
)
{
const
message
=
`Token error:
${
err
.
message
||
err
.
name
}
`
;
const
message
=
`Token error:
${
err
.
message
||
err
.
name
}
`
;
...
...
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