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

Incorrect 500 on /file endpoint when not providing application id #6589

Closed
sunshineo opened this issue Apr 9, 2020 · 3 comments
Closed

Incorrect 500 on /file endpoint when not providing application id #6589

sunshineo opened this issue Apr 9, 2020 · 3 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@sunshineo
Copy link
Contributor

Issue Description

Try POST a file to the /file endpoint without providing x-parse-application-id will get a 500 internal server error. Here is the verbose log

error: Uncaught internal server error.Unexpected token � in JSON at position 0 {"stack":"SyntaxError: Unexpected token � in JSON at position 0\n    at JSON.parse (<anonymous>)\n    at handleParseHeaders (/Users/gordon/workspace/pipe17/parse/node_modules/parse-server/lib/middlewares.js:81:23)\n    at Layer.handle [as handle_request] (/Users/gordon/workspace/pipe17/parse/node_modules/express/lib/router/layer.js:95:5)\n    at next (/Users/gordon/workspace/pipe17/parse/node_modules/express/lib/router/route.js:137:13)\n    at /Users/gordon/workspace/pipe17/parse/node_modules/body-parser/lib/read.js:130:5\n    at invokeCallback (/Users/gordon/workspace/pipe17/parse/node_modules/raw-body/index.js:224:16)\n    at done (/Users/gordon/workspace/pipe17/parse/node_modules/raw-body/index.js:213:7)\n    at IncomingMessage.onEnd (/Users/gordon/workspace/pipe17/parse/node_modules/raw-body/index.js:273:7)\n    at IncomingMessage.emit (events.js:228:7)\n    at IncomingMessage.EventEmitter.emit (domain.js:475:20)"}
SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)
    at handleParseHeaders (/Users/gordon/workspace/pipe17/parse/node_modules/parse-server/lib/middlewares.js:81:23)
    at Layer.handle [as handle_request] (/Users/gordon/workspace/pipe17/parse/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/gordon/workspace/pipe17/parse/node_modules/express/lib/router/route.js:137:13)
    at /Users/gordon/workspace/pipe17/parse/node_modules/body-parser/lib/read.js:130:5
    at invokeCallback (/Users/gordon/workspace/pipe17/parse/node_modules/raw-body/index.js:224:16)
    at done (/Users/gordon/workspace/pipe17/parse/node_modules/raw-body/index.js:213:7)
    at IncomingMessage.onEnd (/Users/gordon/workspace/pipe17/parse/node_modules/raw-body/index.js:273:7)
    at IncomingMessage.emit (events.js:228:7)
    at IncomingMessage.EventEmitter.emit (domain.js:475:20)

Steps to reproduce

Setup a Parse server and config it to be able to take file upload. Then make the same file upload request without the x-parse-application-id header and you will get a 500

Expected Results

Should be a 401 or 403 with a message saying that you are missing the header. This cost us several hours to debug. I wish we can remove the application id completely. It provides no value and just causing trouble

Actual Outcome

500 error

Environment Setup

  • Server

    • parse-server version 3.10.0
    • Operating System: docker node:lts
    • Hardware: aws ec2
    • Localhost or remote server? aws ec2
  • Database

    • MongoDB version: 4.2.5
    • Storage engine: not sure
    • Hardware: not sure
    • Localhost or remote server? hosted by MongoDB Atlas

Logs/Trace

See above

@sunshineo
Copy link
Contributor Author

sunshineo commented Apr 9, 2020

Direct cause is here https://github.com/parse-community/parse-server/blob/master/src/middlewares.js#L62 . Trying to JSON parse on binary file

Code is doing this because it did not find x-parse-application-id on the headers and assumes that it will be in a JSON body. The dashboard and maybe the JS sdk calls the server this way

One of the reasons that allows this way of calling the server is to avoid preflight and make it faster discussed in this ticket parse-community/Parse-SDK-JS#630 (comment) .

Premature optimization is the root of all evil

@davimacedo davimacedo added the type:bug Impaired feature or lacking behavior that is likely assumed label Apr 14, 2020
@davimacedo
Copy link
Member

Good catch @sunshineo . Would you be willed to send a PR fixing this one?

@sunshineo
Copy link
Contributor Author

Submitted a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

2 participants