API abuse protection

This commit is contained in:
Mentor Palokaj 2021-11-22 10:51:46 +01:00
parent 41c806dc29
commit a5c8a060d7
3 changed files with 11 additions and 3 deletions

View File

@ -10,9 +10,13 @@ const { setAvatar, resetAvatar } = require( '../integrations/avatar' )
app.get( '/api/rocketeer/:id', async ( req, res ) => { app.get( '/api/rocketeer/:id', async ( req, res ) => {
// Parse the request // Parse the request
const { id } = req.params let { id } = req.params
if( !id ) return res.json( { error: `No ID specified in URL` } ) if( !id ) return res.json( { error: `No ID specified in URL` } )
// Protect against malformed input
id = Math.floor( Math.abs( id ) )
if( typeof id !== 'number' ) return res.json( { error: `Malformed request` } )
try { try {
// Get old rocketeer if it exists // Get old rocketeer if it exists

View File

@ -8,9 +8,13 @@ const { safelyReturnRocketeer, web2domain } = require( './rocketeer' )
app.get( '/testnetapi/rocketeer/:id', async ( req, res ) => { app.get( '/testnetapi/rocketeer/:id', async ( req, res ) => {
// Parse the request // Parse the request
const { id } = req.params let { id } = req.params
if( !id ) return res.json( { error: `No ID specified in URL` } ) if( !id ) return res.json( { error: `No ID specified in URL` } )
// Protect against malformed input
id = Math.floor( Math.abs( id ) )
if( typeof id !== 'number' ) return res.json( { error: `Malformed request` } )
try { try {
// Get old rocketeer if it exists // Get old rocketeer if it exists