Skip to content
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

Improve security for queue settings #233

Merged
merged 8 commits into from
Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 45 additions & 56 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"redux": "^4.0.1",
"redux-thunk": "^2.3.0",
"reselect": "^4.0.0",
"sequelize": "^4.42.0",
"sequelize": "^5.1.0",
"sequelize-stream": "^1.0.2",
"socket.io": "^2.2.0",
"socket.io-client": "^2.2.0",
Expand Down
24 changes: 14 additions & 10 deletions src/api/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,21 @@ router.post(
}
}

const question = Question.build({
name: data.name,
// Questions in fixed-location queues should never have a location
location: res.locals.queue.fixedLocation ? '' : data.location,
topic: data.topic,
enqueueTime: new Date(),
queueId,
askedById: askerId,
})
const question = await Question.create(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify why there changes were necessary?

Copy link
Member Author

@james9909 james9909 Mar 18, 2019

Choose a reason for hiding this comment

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

We expect that the object returned from Question.build contains the appropriate askedBy model through association, but it doesn't do that anymore.
The docs suggest to use .create to create with association.

Copy link
Member Author

Choose a reason for hiding this comment

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

Looking through the docs some more, it's possible to use .build() to achieve the same effect, but since we're not doing anything special between .build() and .save(), I don't see a reason to use it over .create()

{
name: data.name,
// Questions in fixed-location queues should never have a location
location: res.locals.queue.fixedLocation ? '' : data.location,
topic: data.topic,
enqueueTime: new Date(),
queueId,
askedById: askerId,
},
{
include: [{ model: User, as: 'askedBy' }],
}
)

await question.save()
await question.reload()
res.status(201).send(question)
})
Expand Down
12 changes: 12 additions & 0 deletions src/api/queues.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,25 @@ router.get(
},
required: false,
include: [User],
attributes: ['startTime', 'endTime'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you clarify why the changes in this file were necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can't find the exact change from v5, but without attributes, sequelize will throw an error stating include.attributes.map is not a function.

},
{
model: Question,
required: false,
where: {
dequeueTime: null,
},
attributes: [
'id',
'name',
'topic',
'beingAnswered',
'answerStartTime',
'enqueueTime',
'dequeueTime',
'askedById',
],
include: [{ model: User, as: 'askedBy' }],
},
],
order: [[Question, 'id', 'ASC']],
Expand Down
7 changes: 2 additions & 5 deletions src/api/queues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ describe('Queues API', () => {
expect(res.body[1].id).toBe(2)

res.body.forEach(queue => {
if (user === 'admin') {
includesPrivateAttributes(queue)
} else {
excludesPrivateAttributes(queue)
}
// This endpoint shouldn't include private attributes
excludesPrivateAttributes(queue)
})
}
test('succeeds for admin', async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module.exports.initSequelize = sequelize => {
}

const sequelizeConfig = {
operatorsAliases: Sequelize.Op,
// See http://docs.sequelizejs.com/manual/querying.html#operators-security
operatorsAliases: false,
dialectOptions: {
multipleStatements: true,
},
Expand Down