-
Notifications
You must be signed in to change notification settings - Fork 78
Add SqlString.fn
Function Call Proxy
#13
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there are two main issues:
- The automated system is marking that there are not enough tests to even get to full coverage.
- Change should support all the versions of Node.js this module supports (Node.js 0.6+ currently).
a.js: const SqlString = require('sqlstring');
SqlString.escape(Object.assign(Object.create(SqlString.fn.something.prototype), {
toSQL() {
return 'nope';
}
})); // 'nope';
SqlString.fn.something.prototype[Symbol.hasInstance] = () => true;
Object.prototype.toSQL = () => 'nopenope'; b.js: require('./a.js');
require('sqlstring').escape({}); // 'nopenope'
An alternative way to solve this might be
a.js: require('sqlstring').escape = () => 'screwed';
Array.prototype.map = () => ['screwed'];
⋮ b.js: require('./a.js');
require('sqlstring').escape('test'); // 'screwed'
[42].map(a => a ** 2).join(''); // 'screwed'
⋮
Shouldn't that be fine as long as every user of those functions sets the engine property of the package.json accordingly? I don't think that any of this is sensible: everyone who wants to harm you will still do so, and almost with the same effort; I also don't think that it is possible to completely remove this. Also, I would suggest the usage of a |
@kevinmartin I just landed your #9 , do you think that supersedes this PR or still something that should exist? |
Adds the ability to raw "escape" by calling any
SqlString.fn.*
property as a function.It takes the Proxy example from #9 and merges it in directly into the library.
It only works on Node.js v6+ (according to node.green), but there is a check so that users of lower versions can use the library (without
SqlString.fn.*
support), which is a con #9 didn't have..Examples:
Should be a lot more secure than #9, since the escape function checks if the value from the
SqlString.fn.*
call is in an instance of an internal function class (SqlFunction
) that doesn't get exported. It also escapes all arguments.Playing (security) devils advocate:
SqlString.fn
orSqlString.escape
, you're screwed.Array.prototype.map
, you're screwed.