Skip to content

Fix SQL injection #18

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

Merged
merged 1 commit into from
Jan 9, 2015
Merged

Fix SQL injection #18

merged 1 commit into from
Jan 9, 2015

Conversation

raymondfeng
Copy link
Contributor

/to @bajtos or @ritch

@@ -476,6 +476,9 @@ MsSQL.prototype.toDatabase = function (prop, val, wrap) {
return val;
}
if (prop.type.name === 'Number') {
if (isNaN(Number(val))) {
val = "'" + val +"'"; // Convert to a string so that DB will reject it
Copy link

Choose a reason for hiding this comment

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

Need to escape val... This is still an issue.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps if (isNaN(Number(val))) { val = escape(''+val); } will do the trick?

On the other hand, I don't understand why we need to specifically handle this case, why can't we use escape(val) directly?

@bajtos
Copy link
Member

bajtos commented Jan 9, 2015

Related, though out of scope of this PR: Use parameterized queries in SQL connectors strongloop/loopback#983

@raymondfeng raymondfeng force-pushed the feature/fix-sql-injection branch from e4284b5 to a8eef61 Compare January 9, 2015 08:08
@raymondfeng
Copy link
Contributor Author

I added an escape() to handle embedded single quote.

raymondfeng added a commit that referenced this pull request Jan 9, 2015
@raymondfeng raymondfeng merged commit 1440f3d into master Jan 9, 2015
@raymondfeng raymondfeng deleted the feature/fix-sql-injection branch January 9, 2015 08:16
});
// return "q'#"+val+"#'";
return "'" + val + "'";
}
Copy link
Member

Choose a reason for hiding this comment

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

Until we ditch out string concatenation in favour of parameterized commands/queries: it would be nice to move this escape function to loopback-connector/lib/sql.js so that there is only one instance of this code shared by all SQL connectors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants