body length
This commit is contained in:
parent
82d356ef5e
commit
5c21712344
@ -35,36 +35,34 @@ export function CheckPermissions(): RequestHandler {
|
|||||||
|
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
if (!req.session.user) {
|
if (!req.session.user) {
|
||||||
next({ status: 401, messsage: 'Unauthorized' });
|
return next({ status: 401, messsage: 'Unauthorized' });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.session.user.role === UserRoles.ADMIN) {
|
if (req.session.user.role === UserRoles.ADMIN) {
|
||||||
next();
|
return next();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ressourceId = getResourceId(req);
|
const ressourceId = getResourceId(req);
|
||||||
if (!ressourceId) {
|
if (!ressourceId) {
|
||||||
next({ status: 403, messsage: 'Forbidden' });
|
return next({ status: 403, messsage: 'Forbidden' });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canAccessRessource(req.session.user, ressourceId)) {
|
if (canAccessRessource(req.session.user, ressourceId)) {
|
||||||
next();
|
return next();
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
next({ status: 403, messsage: 'Forbidden' });
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should be unreachable
|
|
||||||
next({ status: 403, messsage: 'Forbidden' });
|
next({ status: 403, messsage: 'Forbidden' });
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SchemaValidator(): RequestHandler {
|
export function SchemaValidator(keys: number = 0): RequestHandler {
|
||||||
return (req, res, next) => {
|
return (req, res, next) => {
|
||||||
|
if (Object.keys(req.body).length > keys)
|
||||||
|
return next({
|
||||||
|
status: 400,
|
||||||
|
message: `Found ${Object.keys(req.body).length} keys expected ${keys}`,
|
||||||
|
});
|
||||||
|
|
||||||
const error = validationResult(req);
|
const error = validationResult(req);
|
||||||
error.isEmpty()
|
error.isEmpty()
|
||||||
? next()
|
? next()
|
||||||
|
@ -66,7 +66,7 @@ export function Routes(services: Services) {
|
|||||||
router.post(
|
router.post(
|
||||||
'/login',
|
'/login',
|
||||||
LoginUserSchema(),
|
LoginUserSchema(),
|
||||||
SchemaValidator(),
|
SchemaValidator(2),
|
||||||
LoginHandler(services),
|
LoginHandler(services),
|
||||||
);
|
);
|
||||||
router.post(
|
router.post(
|
||||||
@ -87,7 +87,7 @@ export function Routes(services: Services) {
|
|||||||
'/create',
|
'/create',
|
||||||
CheckPermissions(),
|
CheckPermissions(),
|
||||||
CreateUserSchema(),
|
CreateUserSchema(),
|
||||||
SchemaValidator(),
|
SchemaValidator(3),
|
||||||
CreateHandler(services),
|
CreateHandler(services),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
from os import chdir, system, path
|
from os import chdir, path
|
||||||
from sys import argv
|
from sys import argv
|
||||||
from subprocess import run, PIPE
|
from subprocess import run, PIPE
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
|
Loading…
x
Reference in New Issue
Block a user