SplatNet-Backend/judd/middleware/validate-boss-digest.js

31 lines
1.1 KiB
JavaScript
Raw Normal View History

2026-02-22 19:48:25 +01:00
const crypto = require('crypto');
function validateBOSSDigestMiddleware(request, response, next) {
// prevents viewing it in a browser to fucking up the process lmfao
if (request.method === 'GET') {
return response.status(404).send('Not Found');
}
2026-02-22 19:48:25 +01:00
try {
// try to catch undefined, previously was making everything die
if (!request.rawBody) {
throw new Error('rawBody is undefined');
}
2026-02-22 19:48:25 +01:00
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');
}
2026-02-22 19:48:25 +01:00
}
module.exports = validateBOSSDigestMiddleware;