Skip to content

Commit f5c6ea8

Browse files
committed
blacklisting ips
1 parent 172e1fd commit f5c6ea8

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import routes from './routes';
55
import cors from 'cors';
66
import compression from 'compression';
77
import AnalyticsService from "./services/AnalyticsService";
8+
import Blacklist from "./util/blacklist";
89

910
const app = express();
1011
app.disable('x-powered-by');
@@ -41,4 +42,10 @@ app.use((err, req, res, next) => { // eslint-disable-line no-unused-vars
4142
});
4243
});
4344

45+
const senderIp = req => req.headers['x-forwarded-for'] || req.connection.remoteAddress;
46+
app.use((req, res, next) => {
47+
if(Blacklist.get(senderIp(req)) < 20) next();
48+
else res.send(null);
49+
});
50+
4451
export default app;

src/routes.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import config from "./util/config";
2222
import * as ecc from "eosjs-ecc";
2323
import BitcoinService from "./services/BitcoinService";
2424
import WalletPackHelpers from "./services/WalletPackHelpers";
25+
import Blacklist from "./util/blacklist";
2526

2627
const bucket = couchbase('scatter');
2728

@@ -280,6 +281,9 @@ routes.post('/btc/pushtx', async (req, res) => {
280281

281282

282283

283-
routes.all('*', (req, res) => res.sendStatus(403));
284+
routes.all('*', (req, res) => {
285+
Blacklist.add(senderIp(req));
286+
res.sendStatus(403);
287+
});
284288

285289
export default routes;

src/util/blacklist.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const BLACKLIST = {};
2+
export default class Blacklist {
3+
4+
static add(ip){
5+
if(!BLACKLIST.hasOwnProperty(ip)) BLACKLIST[ip] = 0;
6+
BLACKLIST[ip]++;
7+
}
8+
9+
static get(ip){
10+
return BLACKLIST[ip] || 0;
11+
}
12+
13+
}

0 commit comments

Comments
 (0)