Skip to content

Commit 0b7beaa

Browse files
authored
Prevent query prototype polution (#389)
1 parent e450d0b commit 0b7beaa

File tree

5 files changed

+16
-4
lines changed

5 files changed

+16
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# feathers-sequelize
22

33
[![CI](https://github.com/feathersjs-ecosystem/feathers-sequelize/workflows/CI/badge.svg)](https://github.com/feathersjs-ecosystem/feathers-sequelize/actions?query=workflow%3ACI)
4-
[![Dependency Status](https://img.shields.io/david/feathersjs-ecosystem/feathers-sequelize.svg?style=flat-square)](https://david-dm.org/feathersjs-ecosystem/feathers-sequelize)
54
[![Download Status](https://img.shields.io/npm/dm/feathers-sequelize.svg?style=flat-square)](https://www.npmjs.com/package/feathers-sequelize)
65

76
A [Feathers](https://feathersjs.com) database adapter for [Sequelize](http://sequelizejs.com), an ORM for Node.js. It supports PostgreSQL, MySQL, MariaDB, SQLite and MSSQL and features transaction support, relations, read replication and more.
@@ -21,6 +20,7 @@ A [Feathers](https://feathersjs.com) database adapter for [Sequelize](http://seq
2120
- [Embrace the ORM](#embrace-the-orm)
2221
- [Setting `params.sequelize.include`](#setting-paramssequelizeinclude)
2322
- [Querying](#querying)
23+
- [Querying a nested column](#querying-a-nested-column)
2424
- [Working with Sequelize Model instances](#working-with-sequelize-model-instances)
2525
- [Validation](#validation)
2626
- [Testing sequelize queries in isolation](#testing-sequelize-queries-in-isolation)

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Service extends AdapterService {
102102
return converted;
103103
};
104104

105-
filtered.query = convertOperators(filtered.query);
105+
filtered.query = Object.assign({}, convertOperators(filtered.query));
106106

107107
return filtered;
108108
}

lib/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ exports.errorHandler = error => {
3636
exports.getOrder = (sort = {}) => Object.keys(sort).reduce((order, name) => {
3737
let direction;
3838
if (Array.isArray(sort[name])) {
39-
direction = parseInt(sort[name][0], 10) === 1 ? 'ASC' : 'DESC';
40-
direction += parseInt(sort[name][1], 10) === 1 ? ' NULLS FIRST': ' NULLS LAST';
39+
direction = parseInt(sort[name][0], 10) === 1 ? 'ASC' : 'DESC';
40+
direction += parseInt(sort[name][1], 10) === 1 ? ' NULLS FIRST' : ' NULLS LAST';
4141
} else {
4242
direction = parseInt(sort[name], 10) === 1 ? 'ASC' : 'DESC';
4343
}

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/index.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ describe('Feathers Sequelize Service', () => {
252252
await people.remove(person.id);
253253
});
254254

255+
it('cleans up the query prototype', async () => {
256+
const page = await people.find({
257+
query: {
258+
name: 'Dave',
259+
__proto__: []
260+
}
261+
});
262+
263+
assert.strictEqual(page.data.length, 0);
264+
});
265+
255266
it('still allows querying with Sequelize operators', async () => {
256267
const name = 'Age test';
257268
const person = await people.create({ name, age: 10 });

0 commit comments

Comments
 (0)