I have the following code in my Fastify server hosted on Heroku:
this.server.addHook('preHandler', async(req, reply) => {
const isHttps = req.headers['x-forwarded-proto'] === 'https';
if (isHttps) {
return;
}
const {
method,
url
} = req;
if (method && ['GET', 'HEAD'].includes(method)) {
const host = req.headers.host || req.hostname;
reply.redirect(301, `https://${host}${url}`);
}
});
The idea is to prevent access to the server through HTTP
and force redirection to HTTPS
at the application-level, since it is not possible otherwise on Heroku.
My question is: if the first request to the server via HTTP
(before the redirection happens) contains sensitive information such as a username/password, wouldn't that still be "dangerous" or compromising somehow?