Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent security scanner from killing wrapper with ECONNRESET #277

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,23 @@ if (typeof argv.m === 'string'){
argv.f = p.resolve(argv.f);

// Hack to force the wrapper process to stay open by launching a ghost socket server
var server = net.createServer().listen();
// Some security penetration tests create numerous daily socket errors that restart the wrapper.
// Handling errors here is preferable to restarting the service for no real reason.
function createKeepAliveServer() {
var sv = net.createServer((c) => {
c.on('error', (err) => {
log.warn(`Socket error (${err.code}) in wrapper keep-alive. Ignoring...`);
});
});
sv.listen();
return sv;
}
var server = createKeepAliveServer();

server.on('error', function (err) {
launch('warn', err.message);
server = net.createServer().listen();
server.close(); // don't leak a trail of unclosed servers

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ChrisMiami,
I have a question. Does the subsequent servers also close?

The first server will close the socket because we are listening the event, but after the first error, we are not listening the error events for the new created servers.

Thank you very much for your contribution

launch('warn', err.message);
server = createKeepAliveServer();
});

/**
Expand Down