fix: handle 404s & catch errors more efficiently

This commit is contained in:
kittentm 2026-04-09 05:55:01 +02:00
commit dd1a6227dc
No known key found for this signature in database
GPG key ID: AC43DFDBC1F44A91

View file

@ -1,14 +1,31 @@
const crypto = require('crypto');
function validateBOSSDigestMiddleware(request, response, next) {
const calculatedHash = crypto.createHash('sha1').update(request.rawBody).digest('hex');
const expectedHash = request.headers['x-boss-digest'];
// prevents viewing it in a browser to fucking up the process lmfao
if (request.method === 'GET') {
return response.status(404).send('Not Found');
}
if (calculatedHash !== expectedHash) {
return next('Provided BOSS digest does not match the calculated hash');
}
try {
// try to catch undefined, previously was making everything die
if (!request.rawBody) {
throw new Error('rawBody is undefined');
}
next();
const calculatedHash = crypto.createHash('sha1').update(request.rawBody).digest('hex');
const expectedHash = request.headers['x-boss-digest'];
//catch all other errors
if (calculatedHash !== expectedHash) {
console.warn(`[Digest Mismatch] Expected: ${expectedHash}, Calculated: ${calculatedHash}`);
return response.status(403).send('Provided BOSS digest does not match the calculated hash');
}
next();
} catch (error) {
console.error('[Digest Middleware Error]:', error.message);
return response.status(500).send('Internal Server Error');
}
}
module.exports = validateBOSSDigestMiddleware;