Skip to content

Invalid date iso with beforeSave make server unhandled promise rejection and request hanging  #7192

Open
@sunshineo

Description

@sunshineo
Contributor
  • I am not disclosing a vulnerability.
    I am not just asking a question.
    I have searched through existing issues.
    I can reproduce the issue with the latest version of Parse Server.

Issue Description

Have a class with a column type Date. Try post with empty string as iso. Get proper error back

{
    "code": 111,
    "error": "This is not a valid Date"
}

Add beforeSave to the class and post again. Request will hang there forever. Server will fail with the following errors

(node:63110) UnhandledPromiseRejectionWarning: Error: Tried to encode an invalid date.
    at encode (/Users/gordon/workspace/pipe17/pipe17-group/parse/node_modules/parse/lib/node/encode.js:85:13)
    at _default (/Users/gordon/workspace/pipe17/pipe17-group/parse/node_modules/parse/lib/node/encode.js:132:10)
    at SetOp.toJSON (/Users/gordon/workspace/pipe17/pipe17-group/parse/node_modules/parse/lib/node/ParseOp.js:155:32)
    at ParseObject._getSaveJSON (/Users/gordon/workspace/pipe17/pipe17-group/parse/node_modules/parse/lib/node/ParseObject.js:485:61)
    at success (/Users/gordon/workspace/pipe17/pipe17-group/parse/node_modules/parse-server/lib/triggers.js:385:45)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
  • 🤩 I will submit a PR with a fix (but probably need someone else do a proper fix)

Environment

Server

  • Parse Server version: 4.5.0

Activity

added a commit that references this issue on Feb 15, 2021

parse-community#7192 return validation error properly with beforeSave…

mtrezza

mtrezza commented on Feb 15, 2021

@mtrezza
Member

Thanks for reporting.

Can you please add a code example to demonstrate the issue you are referring to?

sunshineo

sunshineo commented on Feb 16, 2021

@sunshineo
ContributorAuthor

Not sure how to provide a code example to setup class with Date and beforeSave and post with invalid date. But anyone read my description should be able to reproduce on their server

dplewis

dplewis commented on Feb 20, 2021

@dplewis
Member

How did you save an empty iso date?

mtrezza

mtrezza commented on Feb 20, 2021

@mtrezza
Member

This may be related to (or be a duplicate of) #7087, but without a proper code example we'll have to close this issue due to lack of details. The PR is also missing the test case and I wasn't able to infer anything from the PR itself.

sunshineo

sunshineo commented on Feb 22, 2021

@sunshineo
ContributorAuthor

I still have no time to learn the test system. So I spent half an hour to setup a project to demo the bug
https://github.com/sunshineo/parse-bug-demo
I hope the README.md is enough, but I can answer any questions

mtrezza

mtrezza commented on Feb 22, 2021

@mtrezza
Member

@sunshineo Thanks, this is actually the "code example" that was needed:

# Valid iso works in both classes
curl --location --request POST 'http://localhost:1337/parse/classes/MyClass1' \
--header 'x-parse-application-id: myAppId' \
--header 'x-parse-master-key: masterKey' \
--header 'Content-Type: application/json' \
--data-raw '{"field":{"__type":"Date", "iso":"2021-02-19T01:18:45.062Z"}}'

curl --location --request POST 'http://localhost:1337/parse/classes/MyClass2' \
--header 'x-parse-application-id: myAppId' \
--header 'x-parse-master-key: masterKey' \
--header 'Content-Type: application/json' \
--data-raw '{"field":{"__type":"Date", "iso":"2021-02-19T01:18:45.062Z"}}'


# Empty iso not working in MyClass1 with proper error
curl --location --request POST 'http://localhost:1337/parse/classes/MyClass1' \
--header 'x-parse-application-id: myAppId' \
--header 'x-parse-master-key: masterKey' \
--header 'Content-Type: application/json' \
--data-raw '{"field":{"__type":"Date", "iso": ""}}'

# Empty iso will stuck forever for MyClass2
curl --location --request POST 'http://localhost:1337/parse/classes/MyClass2' \
--header 'x-parse-application-id: myAppId' \
--header 'x-parse-master-key: masterKey' \
--header 'Content-Type: application/json' \
--data-raw '{"field":{"__type":"Date", "iso": ""}}'

It's still unclear to me why you are referring to two classes. What is the difference between class 1 and class 2? Wouldn't an empty or invalid iso date produce the same result in both classes?

sunshineo

sunshineo commented on Feb 22, 2021

@sunshineo
ContributorAuthor

No, MyClass2 has a beforeSave trigger, and that makes it stuck

sunshineo

sunshineo commented on Feb 22, 2021

@sunshineo
ContributorAuthor
# Empty iso not working in MyClass1 (returns immediately) with proper error
# Empty iso will stuck forever (until curl client timeout) for MyClass2 (because it has a beforeSave)
linked a pull request that will close this issue on Feb 23, 2021
mtrezza

mtrezza commented on Feb 23, 2021

@mtrezza
Member

I was able to reproduce the error throwing instead of promise rejection in #7217.

@sunshineo The code example to describe this issue is as simple as this, no need to create a repo or learn the test system:

Parse.Cloud.beforeSave('TestObject', () => {});

const obj = new Parse.Object('TestObject');
obj.set('date', { __type: 'Date', iso: '' });
await obj.save(); // Throws instead of rejects

Feel free to take a look at the test case added in #7217, you will see it is not much more than the code above. The test system we use is jasmine, it is descriptive, easy to learn and there are many existing tests in Parse Server that usually make for a good blueprint.

Now that we have a failing test case, would you want to investigate the root cause and provide a fix?

sunshineo

sunshineo commented on Feb 23, 2021

@sunshineo
ContributorAuthor

@mtrezza I have a fix. I have a pull request #7193
It's submitted before your test case. So is there a way to re-run the test and see if this fix make the test pass?

mtrezza

mtrezza commented on Feb 23, 2021

@mtrezza
Member

You could simply add the test to your PR.

5 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sunshineo@mtrezza@dplewis

      Issue actions

        Invalid date iso with beforeSave make server unhandled promise rejection and request hanging · Issue #7192 · parse-community/parse-server