Skip to content

Commit

Permalink
add: limit faucet usage by ip
Browse files Browse the repository at this point in the history
  • Loading branch information
sirpy committed Sep 24, 2024
1 parent dbe8358 commit 67e9a74
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/server/verification/verificationAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ const clearMemoizedFaucetAbuse = async () => {
}
if (conf.env !== 'test') setInterval(clearMemoizedFaucetAbuse, 60 * 60 * 1000) // clear every 1 hour

let ipToAccounts = {}
const checkMultiIpAccounts = (account, ip, logger) => {
let accounts = ipToAccounts[ip] || []
if (!accounts.includes[account]) {
accounts.push(account)
}
ipToAccounts[ip] = accounts
logger.debug('checkMultiIpAccounts:', { ip, account, accounts })
if (accounts.length >= 10) {
return accounts
}
return false
}

if (conf.env !== 'test') setInterval(() => (ipToAccounts = {}), 48 * 60 * 60 * 1000) // clear every 2 days (48 hours)

const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
/**
* @api {delete} /verify/face/:enrollmentIdentifier Enqueue user's face snapshot for disposal since 24h
Expand Down Expand Up @@ -622,6 +638,15 @@ const setup = (app: Router, verifier: VerificationAPI, storage: StorageAPI) => {
log.warn('faucet abuse found:', foundAbuse)
return res.json({ ok: -1, error: 'faucet abuse: ' + foundAbuse.hash })
}

const foundMultiIpAccounts = checkMultiIpAccounts(user.gdAddress, clientIp, log)
if (foundMultiIpAccounts) {
log.error('faucet multiip abuse found:', foundMultiIpAccounts.length, new Error('faucet multiip abuse'), {
foundMultiIpAccounts
})
return res.json({ ok: -1, error: 'faucet multiip abuse' })
}

try {
let txPromise = AdminWallet.topWallet(user.gdAddress, chainId, log)
.then(tx => {
Expand Down

0 comments on commit 67e9a74

Please sign in to comment.