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

Server crash on POST request #1683

Closed
MaxSchlueter opened this issue Oct 25, 2018 · 3 comments
Closed

Server crash on POST request #1683

MaxSchlueter opened this issue Oct 25, 2018 · 3 comments

Comments

@MaxSchlueter
Copy link

On a high level, for requests made to certain endpoints as an authenticated user, if the format parameter in the payload is not one of two specific strings, the database cursor object will remain in the data that is sent back in the response, causing JSON.stringify to throw an error, as the database cursor object contains a circular reference.

Here are the steps to reproduce:

  1. Set up a barebones Apostrophe server (https://apostrophecms.org/docs/tutorials/getting-started/creating-your-first-project.html)

  2. Authenticate as a user. This doesn't necessarily need to be a user
    with admin rights, it can also be a user that is only granted guest
    rights (to add user to the guest group type: node app.js apostrophe-users:add user1 guest)

  3. Issue a POST request to a [..]/list endpoint with format not equals to "managePage" or "allIds", e.g. curl -d '{ "format": "HelloWorld", "page": 1, "trash": false }' -H 'Content-Type: application/json' -H /* AUTHENTICATION HEADERS HERE */ http://localhost:3000/modules/apostrophe-global/list

This request should have crashed the server. A simple fix would be to make sure that the results variable is overwritten in the list function in lib/modules/apostrophe-pieces/lib/routes.js:

if (req.body.format === 'managePage') {
     ...
} else if (req.body.format === 'allIds') {
     ...
}
// add this else branch
else {
     results = {};
}

Cheers,

Max

@boutell
Copy link
Member

boutell commented Oct 25, 2018 via email

@boutell
Copy link
Member

boutell commented Oct 25, 2018

Curious how you're using Apostrophe; please do drop a line at tom@punkave.com when you get a chance. Thanks!

@boutell
Copy link
Member

boutell commented Oct 30, 2018

Fix published, thanks again!

@boutell boutell closed this as completed Oct 30, 2018
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

No branches or pull requests

2 participants