Compare commits

...

2 Commits

Author SHA1 Message Date
Brian M. Carlson
d4aa616b21 Bump version 2017-08-12 16:32:30 -05:00
Brian M. Carlson
9bcf55dda9 Fix vulnerability 2017-08-12 16:31:32 -05:00
3 changed files with 20 additions and 8 deletions

View File

@ -7,6 +7,7 @@
*/
var types = require('pg-types');
var escape = require('js-string-escape');
//result object returned from query
//in the 'end' event and also
@ -75,13 +76,13 @@ Result.prototype.addRow = function(row) {
var inlineParser = function(fieldName, i) {
return "\nthis['" +
//fields containing single quotes will break
//the evaluated javascript unless they are escaped
//see https://github.com/brianc/node-postgres/issues/507
//Addendum: However, we need to make sure to replace all
//occurences of apostrophes, not just the first one.
//See https://github.com/brianc/node-postgres/issues/934
fieldName.replace(/'/g, "\\'") +
// fields containing single quotes will break
// the evaluated javascript unless they are escaped
// see https://github.com/brianc/node-postgres/issues/507
// Addendum: However, we need to make sure to replace all
// occurences of apostrophes, not just the first one.
// See https://github.com/brianc/node-postgres/issues/934
escape(fieldName) +
"'] = " +
"rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
};

View File

@ -1,6 +1,6 @@
{
"name": "pg",
"version": "6.4.1",
"version": "6.4.2",
"description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [
"postgres",
@ -20,6 +20,7 @@
"dependencies": {
"buffer-writer": "1.0.1",
"packet-reader": "0.3.1",
"js-string-escape": "1.0.1",
"pg-connection-string": "0.1.3",
"pg-pool": "1.*",
"pg-types": "1.*",

View File

@ -0,0 +1,10 @@
var pg = require('./test-helper').pg
var sql = 'SELECT 1 AS "\\\'/*", 2 AS "\\\'*/\n + process.exit(-1)] = null;\n//"'
var client = new pg.Client()
client.connect()
client.query(sql, function (err, res) {
if (err) throw err
client.end()
})