mirror of
https://github.com/stronk-dev/RandomChad.git
synced 2025-07-05 10:35:08 +02:00
API abuse protection
This commit is contained in:
parent
41c806dc29
commit
a5c8a060d7
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user