Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ const initGlobalConfig = async () => {
configHelper.initSecureMode(config);
// Print a warning if config.domain is not set
if (process.env.NODE_ENV !== 'test') configHelper.validateDomainIsSet(config);
if (process.env.NODE_ENV !== 'test') configHelper.validateJwtSecret(config);
// Expose configuration utilities
const conf = { ...config };
conf.utils = {
Expand Down
12 changes: 12 additions & 0 deletions lib/helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ const validateDomainIsSet = (config) => {
}
};

/**
* @desc Warn if JWT secret is still set to the default placeholder value.
* @param {object} config - application configuration object
* @returns {void}
*/
const validateJwtSecret = (config) => {
if (config.jwt && config.jwt.secret === 'WaosSecretKeyExampleToChnageAbsolutely') {
console.log(chalk.red('+ Important warning: JWT secret is set to the default value. It should be changed in production via DEVKIT_NODE_jwt_secret.'));
}
};
Comment thread
PierreBrisorgueil marked this conversation as resolved.
Comment thread
PierreBrisorgueil marked this conversation as resolved.

/**
* Validate secure parameters and create SSL credentials.
* @param {object} config - application configuration object
Expand Down Expand Up @@ -106,6 +117,7 @@ const initGlobalConfigFiles = async (assets) => {
export default {
getGlobbedPaths,
validateDomainIsSet,
validateJwtSecret,
initSecureMode,
initGlobalConfigFiles,
};
4 changes: 4 additions & 0 deletions modules/auth/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ const oauthCallback = async (req, res, next) => {
const strategy = req.params.strategy;
// app Auth with Strategy managed on client side
if (req.body.strategy === false && req.body.key) {
const allowedKeys = ['id', 'sub', 'email'];
if (!allowedKeys.includes(req.body.key)) {
return responses.error(res, 422, 'Unprocessable Entity', 'Invalid provider key')();
}
try {
let user = {
firstName: req.body.firstName,
Expand Down
8 changes: 5 additions & 3 deletions modules/auth/controllers/auth.password.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ const forgot = async (req, res) => {
let user;
// check input
if (!req.body.email) return responses.error(res, 422, 'Unprocessable Entity', 'Mail field must not be blank')();
const email = String(req.body.email);
// get user generate and add token
try {
user = await UserService.getBrut({ email: req.body.email });
user = await UserService.getBrut({ email });
if (!user) return responses.error(res, 400, 'Bad Request', 'No account with that email has been found')();
if (user.provider !== 'local')
return responses.error(res, 400, 'Bad Request', `It seems like you signed up using your ${user.provider} account`)();
Expand Down Expand Up @@ -68,7 +69,7 @@ const forgot = async (req, res) => {
*/
const validateResetToken = async (req, res) => {
try {
const user = await UserService.getBrut({ resetPasswordToken: req.params.token });
const user = await UserService.getBrut({ resetPasswordToken: String(req.params.token) });
if (!user || !user.email) return res.redirect('/api/password/reset/invalid');
res.redirect(`/api/password/reset/${req.params.token}`);
} catch (_err) {
Expand All @@ -86,9 +87,10 @@ const reset = async (req, res) => {
let user;
// check input
if (!req.body.token || !req.body.newPassword) return responses.error(res, 400, 'Bad Request', 'Password or Token fields must not be blank')();
const token = String(req.body.token);
// get user by token, update with new password, login again
try {
user = await UserService.getBrut({ resetPasswordToken: req.body.token });
user = await UserService.getBrut({ resetPasswordToken: token });
if (!user || !user.email) return responses.error(res, 400, 'Bad Request', 'Password reset token is invalid or has expired.')();
const edit = {
password: await AuthService.hashPassword(req.body.newPassword),
Expand Down
Loading