Skip to content

Instantly share code, notes, and snippets.

@kevincennis
Last active June 14, 2017 21:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kevincennis/7bbd2f3103d8eae8ad046be08665e6f4 to your computer and use it in GitHub Desktop.
Save kevincennis/7bbd2f3103d8eae8ad046be08665e6f4 to your computer and use it in GitHub Desktop.

What if a package did something like this, but instead of logging to the console, they sent it back to a server?

Have you actually reviewed every dependency and every child dependency in every app you deploy?

Why are people not more scared of this?

Analytics

// intercept and log every single http request on this server
const { IncomingMessage } = require('http');
const push = IncomingMessage.prototype.push;
IncomingMessage.prototype.push = function( chunk, encoding, done ) {
const result = push.call( this, chunk, encoding, done );
if ( chunk === null ) {
return;
}
const decoded = chunk instanceof Buffer ? chunk.toString( encoding ) : chunk;
console.log( `I spied on a user that sent: ${ decoded }` );
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment