Skip to content

Commit

Permalink
Audit Bugs - 1148 , 1152 , 1153
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanvpacewisdom committed Mar 19, 2024
1 parent 3ebb56e commit be6f151
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/constants/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = {
'/user/v1/user-role/default',
],
notificationEmailType: 'email',
accessTokenExpiry: `${process.env.ACCESS_TOKEN_EXPIRY}d`,
accessTokenExpiry: process.env.ACCESS_TOKEN_EXPIRY,
refreshTokenExpiry: `${process.env.REFRESH_TOKEN_EXPIRY}d`,
refreshTokenExpiryInMs: Number(process.env.REFRESH_TOKEN_EXPIRY) * 24 * 60 * 60 * 1000,
refreshTokenLimit: 3,
Expand Down
4 changes: 2 additions & 2 deletions src/envVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ let enviromentVariables = {
optional: process.env.CLOUD_STORAGE === 'AZURE' ? false : true,
},
ACCESS_TOKEN_EXPIRY: {
message: 'Required access token expiry in days',
message: 'Required access token expiry',
optional: false,
},
REFRESH_TOKEN_EXPIRY: {
message: 'Required refresh token expiry in days',
message: 'Required refresh token expiry',
optional: false,
},
API_DOC_URL: {
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@
"ROLES_HAS_EMPTY_LIST": "Empty roles list",
"COLUMN_DOES_NOT_EXISTS": "Role column does not exists",
"PERMISSION_DENIED": "You do not have the required permissions to access this resource. Please contact your administrator for assistance.",
"RELATED_ORG_REMOVAL_FAILED": "Requested organization not related the organization. Please check the values."
"RELATED_ORG_REMOVAL_FAILED": "Requested organization not related the organization. Please check the values.",
"INAVLID_ORG_ROLE_REQ": "Invalid organisation request"
}
13 changes: 13 additions & 0 deletions src/services/org-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,19 @@ module.exports = class OrgAdminHelper {
const requestId = bodyData.request_id
delete bodyData.request_id

const requestDetail = await orgRoleReqQueries.requestDetails({
id: requestId,
organization_id: tokenInformation.organization_id,
})

if (requestDetail.status !== common.REQUESTED_STATUS) {
return responses.failureResponse({
message: 'INAVLID_ORG_ROLE_REQ',
statusCode: httpStatusCode.bad_request,
responseCode: 'CLIENT_ERROR',
})
}

bodyData.handled_by = tokenInformation.id
const rowsAffected = await orgRoleReqQueries.update(
{ id: requestId, organization_id: tokenInformation.organization_id },
Expand Down
20 changes: 18 additions & 2 deletions src/validators/v1/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ module.exports = {
.withMessage('email is invalid')
.normalizeEmail({ gmail_remove_dots: false })

req.checkBody('password').trim().notEmpty().withMessage('password field is empty')
req.checkBody('password')
.notEmpty()
.withMessage('Password field is empty')
.matches(/^(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+{}|:"<>?~`\-=[\];',.\/])[^ ]{10,}$/)
.withMessage(
'Password must have at least one uppercase letter, one number, one special character, and be at least 10 characters long'
)
.custom((value) => !/\s/.test(value))
.withMessage('Password cannot contain spaces')

if (req.body.role) {
req.checkBody('role').trim().not().isIn([common.ADMIN_ROLE]).withMessage("User does't have admin access")
Expand Down Expand Up @@ -64,7 +72,15 @@ module.exports = {

resetPassword: (req) => {
req.checkBody('email').notEmpty().withMessage('email field is empty').isEmail().withMessage('email is invalid')
req.checkBody('password').notEmpty().withMessage('password field is empty')
req.checkBody('password')
.notEmpty()
.withMessage('Password field is empty')
.matches(/^(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+{}|:"<>?~`\-=[\];',.\/])[^ ]{10,}$/)
.withMessage(
'Password must have at least one uppercase letter, one number, one special character, and be at least 10 characters long'
)
.custom((value) => !/\s/.test(value))
.withMessage('Password cannot contain spaces')

req.checkBody('otp')
.notEmpty()
Expand Down
10 changes: 9 additions & 1 deletion src/validators/v1/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ module.exports = {
.withMessage('email is invalid')
.normalizeEmail()

req.checkBody('password').trim().notEmpty().withMessage('password field is empty')
req.checkBody('password')
.notEmpty()
.withMessage('Password field is empty')
.matches(/^(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*()_+{}|:"<>?~`\-=[\];',.\/])[^ ]{10,}$/)
.withMessage(
'Password must have at least one uppercase letter, one number, one special character, and be at least 10 characters long'
)
.custom((value) => !/\s/.test(value))
.withMessage('Password cannot contain spaces')
},

login: (req) => {
Expand Down

0 comments on commit be6f151

Please sign in to comment.