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

Fix server crash on invalid LiveQuery socket event #4533

Merged
merged 5 commits into from
Feb 16, 2018

Conversation

fridays
Copy link
Contributor

@fridays fridays commented Jan 31, 2018

Sending an invalid event through the LiveQuery client socket crashes the server process.

Reproduce on the client:

Parse.CoreManager
.getLiveQueryController()
.getDefaultLiveQueryClient()
.then(client => client.socket.send(JSON.stringify({hello: 123})))

Server logs:

verbose: Create client bd1183f1-7d9b-4da8-824c-fc0c0d893db4 new subscription: 1
verbose: Current client number: 1
verbose: Request: {"hello":123}
/Users/.../node_modules/parse-server/lib/ParseServer.js:218
          throw err;
          ^

TypeError: Cannot read property '$ref' of undefined
    at ValidatorContext.resolveRefs (/Users/.../node_modules/tv4/tv4.js:399:12)
    at ValidatorContext.validateAll (/Users/.../node_modules/tv4/tv4.js:536:16)
    at Object.validate (/Users/.../node_modules/tv4/tv4.js:1573:24)
    at WebSocket.parseWebsocket.on.request [as internalOnMessage] (/Users/.../node_modules/parse-server/lib/LiveQuery/ParseLiveQueryServer.js:260:96)
    at onServerMessage (/Users/.../node_modules/uws/uws.js:19:15)

This PR fixes it by making the op property required in the general LiveQuery RequestSchema.

I added a test case and removed the tv4.validate mock to make the error visible, and updated the existing tests to pass when using the original module.

@codecov
Copy link

codecov bot commented Jan 31, 2018

Codecov Report

Merging #4533 into master will decrease coverage by 0.04%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4533      +/-   ##
==========================================
- Coverage   92.89%   92.84%   -0.05%     
==========================================
  Files         118      118              
  Lines        8445     8445              
==========================================
- Hits         7845     7841       -4     
- Misses        600      604       +4
Impacted Files Coverage Δ
src/LiveQuery/RequestSchema.js 100% <ø> (ø) ⬆️
src/Adapters/Cache/InMemoryCache.js 91.66% <0%> (-8.34%) ⬇️
src/RestWrite.js 93.46% <0%> (-0.37%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 97.12% <0%> (-0.1%) ⬇️
src/LiveQuery/ParseLiveQueryServer.js 86.55% <0%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 550b69e...686797e. Read the comment docs.

@flovilmart
Copy link
Contributor

Thanks for the PR!

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

Successfully merging this pull request may close these issues.

2 participants