Better handling of bots hitting bad Gopher selectors

This commit is contained in:
Bryan Ashby 2021-02-04 19:27:57 -07:00
parent 9d837cde4d
commit 31f94efdd8
No known key found for this signature in database
GPG Key ID: B49EB437951D2542
1 changed files with 9 additions and 2 deletions

View File

@ -27,7 +27,6 @@ const _ = require('lodash');
const fs = require('graceful-fs');
const paths = require('path');
const moment = require('moment');
const async = require('async');
const ModuleInfo = exports.moduleInfo = {
name : 'Gopher',
@ -89,7 +88,15 @@ exports.getModule = class GopherModule extends ServerModule {
socket.setEncoding('ascii');
socket.on('data', data => {
// sanitize a bit - bots like to inject garbage
data = data.replace(/[^ -~]/g, '');
if (data) {
this.routeRequest(data, socket);
} else {
this.notFoundGenerator('**invalid selector**', res => {
return socket.end(`${res}`);
});
}
});
socket.on('error', err => {