Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express customSanitizer needs error catching and validity checks #653

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/controller/org.controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ router.post('/org',
body(['short_name']).isString().trim().escape().notEmpty(),
body(['name']).isString().trim().escape().notEmpty(),
body(['uuid']).optional().isString().trim().escape(),
body(['authority.active_roles']).optional().customSanitizer(val => { return val.map(x => { return x.toUpperCase() }) }).custom(val => { return isOrgRole(val) }),
body(['authority.active_roles']).optional().customSanitizer(val => { try { return val.map(x => { return x.toUpperCase() }) } catch(err) { return false } }).custom(val => { if (val) { return isOrgRole(val) } return Promise.reject('Value should be an array of valid roles')}),
body(['policies.id_quota']).optional().not().isArray().isInt({ min: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_min, max: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_max }).withMessage('The id_quota does not comply with CVE id quota limitations.'),
parseError,
parsePostParams,
Expand Down Expand Up @@ -307,9 +307,9 @@ router.put('/org/:shortname',
query(['id_quota']).optional().not().isArray().isInt({ min: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_min, max: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_max }).withMessage('The id_quota does not comply with CVE id quota limitations.'),
query(['name']).optional().isString().trim().escape().notEmpty(),
query(['active_roles.add']).optional().toArray(),
query(['active_roles.add']).optional().customSanitizer(val => { return val.map(x => { return x.toUpperCase() }) }).custom(val => { return isOrgRole(val) }),
query(['active_roles.add']).optional().customSanitizer(val => { try { return val.map(x => { return x.toUpperCase() }) } catch(err) { return false } }).custom(val => { if (val) { return isOrgRole(val) } return Promise.reject('Value should be an array of valid roles')}),
query(['active_roles.remove']).optional().toArray(),
query(['active_roles.remove']).optional().customSanitizer(val => { return val.map(x => { return x.toUpperCase() }) }).custom(val => { return isOrgRole(val) }),
query(['active_roles.remove']).optional().customSanitizer(val => { try { return val.map(x => { return x.toUpperCase() }) } catch(err) { return false } }).custom(val => { if (val) { return isOrgRole(val) } return Promise.reject('Value should be an array of valid roles')},)
parseError,
parsePostParams,
controller.ORG_UPDATE_SINGLE)
Expand Down Expand Up @@ -541,7 +541,7 @@ router.post('/org/:shortname/user',
body(['name.last']).optional().isString().trim().escape(),
body(['name.middle']).optional().isString().trim().escape(),
body(['name.suffix']).optional().isString().trim().escape(),
body(['authority.active_roles']).optional().customSanitizer(val => { return val.map(x => { return x.toUpperCase() }) }).custom(val => { return isUserRole(val) }),
body(['authority.active_roles']).optional().customSanitizer(val => { try { return val.map(x => { return x.toUpperCase() }) } catch(err) { return false } }).custom(val => { if (val) { return isUserRole(val) } return Promise.reject('Value should be an array of valid roles')}),
parseError,
parsePostParams,
controller.USER_CREATE_SINGLE)
Expand Down Expand Up @@ -706,9 +706,9 @@ router.put('/org/:shortname/user/:username',
query(['name.middle']).optional().isString().trim().escape(),
query(['name.suffix']).optional().isString().trim().escape(),
query(['active_roles.add']).optional().toArray(),
query(['active_roles.add']).optional().customSanitizer(val => { return val.map(x => { return x.toUpperCase() }) }).custom(val => { return isUserRole(val) }),
query(['active_roles.add']).optional().customSanitizer(val => { try { return val.map(x => { return x.toUpperCase() }) } catch(err) { return false } }).custom(val => { if (val) { return isUserRole(val) } return Promise.reject('Value should be an array of valid roles')}),
query(['active_roles.remove']).optional().toArray(),
query(['active_roles.remove']).optional().customSanitizer(val => { return val.map(x => { return x.toUpperCase() }) }).custom(val => { return isUserRole(val) }),
query(['active_roles.remove']).optional().customSanitizer(val => { try { return val.map(x => { return x.toUpperCase() }) } catch(err) { return false } }).custom(val => { if (val) { return isUserRole(val) } return Promise.reject('Value should be an array of valid roles')}),
parseError,
parsePostParams,
controller.USER_UPDATE_SINGLE)
Expand Down