-
Notifications
You must be signed in to change notification settings - Fork 0
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
Develop #13
Conversation
Remove ts-node and build the project to javascript
Add MailDev in docker-compose
The zod schema will ensure that the ENV config is valid thanks to a zod schema. It will also improve the DX thanks to the typed export `env` from `src/env.ts`.
This .env.example is also used to create the base .env, when the server does not find an existing .env file
[IMPROVE] Ensure the ENV variables are valid
[FEAT] use jose instead of jsonwebtoken
src/app.ts
Outdated
|
||
app.use(express.json({limit: '50mb'})); | ||
app.use(express.urlencoded({limit: '50mb' ,extended: false})); | ||
app.use(cookieParser()); |
Check failure
Code scanning / CodeQL
Missing CSRF middleware
src/app.ts
Outdated
app.all('*', function (req, res, next) { | ||
if (req.path === '/users/login' || req.path === '/users') { | ||
next(); | ||
} else { | ||
const { application_token} = req.headers; | ||
if(application_token && typeof application_token === "string") { | ||
jwt.verify(application_token, env.APPLICATION_TOKEN_SECRET) | ||
.then((decoded) => { | ||
ApplicationModel.findOne({ | ||
where: { | ||
token: req.headers.application_token, | ||
}, | ||
}) | ||
.then((application) => { | ||
// decoded cannot be a string since the | ||
// token is generated from an object | ||
if (application && typeof decoded !== "string") { | ||
req.user = new UserDto(decoded.user); | ||
next(); | ||
} else { | ||
res.status(401).send({ | ||
message: "Invalid application token", | ||
}); | ||
} | ||
}) | ||
.catch((err) => { | ||
res.status(500).send({ | ||
message: "Internal server error", | ||
}); | ||
}); | ||
}) | ||
.catch((err) => { | ||
console.log(err); | ||
res.status(401).send({ | ||
message: "Invalid application token", | ||
}); | ||
}); | ||
} else { | ||
jwt.verify(req.cookies.access_token, env.ACCESS_TOKEN_SECRET) | ||
.then(decoded => { | ||
req.user = new UserDto(decoded); | ||
next(); | ||
}) | ||
.catch((err) => { | ||
jwt.verify(req.cookies.refresh_token, env.REFRESH_TOKEN_SECRET) | ||
.then((user) => { | ||
UserModel.findByPk(user.id) | ||
.then(async function (user) { | ||
if (user) { | ||
res.cookie('access_token', await UserTokenUtil.generateAccessToken(new UserDto(user)), {maxAge: 1000 * 60 * 30}); | ||
res.cookie('refresh_token', req.cookies.refresh_token, {maxAge: 1000 * 60 * 60 * 24 * 30}); | ||
req.user = new UserDto(user); | ||
next(); | ||
} else { | ||
res.status(401).send(); | ||
} | ||
}) | ||
.catch(function (err) { | ||
res.status(401).send(); | ||
}); | ||
}) | ||
.catch((err) => { | ||
res.status(401).send(); | ||
}); | ||
|
||
}) | ||
} | ||
} | ||
}); |
Check failure
Code scanning / CodeQL
Missing rate limiting
[IMPROVEMENT] use typescript strict mode
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
Required :