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: throw if where receives an invalid value (v6) #15699

Merged
merged 1 commit into from Feb 21, 2023
Merged

Conversation

ephys
Copy link
Member

@ephys ephys commented Feb 21, 2023

Backport of #15375 to resolve CVE-2023-22579 and CVE-2023-22580

@sdepold
Copy link
Member

sdepold commented Feb 21, 2023

Quite a small change 👍 interesting that no other test failed.

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

Looks good! Why did we mark this as a breaking change, because it will throw errors on some queries now?

@ephys
Copy link
Member Author

ephys commented Feb 21, 2023

Yes, but I don't see a valid use case for them that would cause actual breakage

I hope I won't be proved wrong

@ephys ephys merged commit d9e0728 into v6 Feb 21, 2023
@ephys ephys deleted the ephys/backport-15375 branch February 21, 2023 21:23
@github-actions
Copy link
Contributor

🎉 This PR is included in version 6.28.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mat813
Copy link
Sponsor

mat813 commented Feb 22, 2023

With this, using { where: undefined } no longer works. If I put { where: null }, I get:

  Types of property 'where' are incompatible.
    Type 'WhereOptions<EspaceClientRolesAttributes> | null | undefined' is not assignable to type 'WhereOptions<EspaceClientRolesAttributes> | undefined'.
      Type 'null' is not assignable to type 'WhereOptions<EspaceClientRolesAttributes> | undefined'.

{ where: null as unknown as undefined } makes typescript happy, but...

@frostzt
Copy link
Contributor

frostzt commented Feb 22, 2023

I am sorry but why would you wanna do { where: undefined }? @mat813

@mat813
Copy link
Sponsor

mat813 commented Feb 22, 2023

Ah, I have a large graphql server that has helpers glueing the possible recursivity of graphql and sequelize, and in one place the code is easier to understand if returns an undefined instead of adding some more logic to to not set where. I changed the undefined with a {} so it now compiles again.

@mat813
Copy link
Sponsor

mat813 commented Feb 22, 2023

But my point was the typing tells me undefined is ok, and null is not, but reading the code, it is the opposite, undefined is not ok, and null is.

@ephys
Copy link
Member Author

ephys commented Feb 22, 2023

In my opinion we should treat undefined as being equivalent to "the property was not set" and I would consider undefined throwing an error to be a regression

@frostzt
Copy link
Contributor

frostzt commented Feb 22, 2023

I prefer { where: {} } this tbh I never knew that undefined itself can be used but yeah as ephys said, maybe I can look into the type definitions and make it explicit?

@ephys
Copy link
Member Author

ephys commented Feb 22, 2023

I don't think the type definition needs to change. where is optional so any TypeScript user that does not use the exactOptionalPropertyTypes TSC option will have where accept undefined

What we can do is update getWhereConditions to make it support undefined in its implementation (and look into what happens when you give it null)

@frostzt
Copy link
Contributor

frostzt commented Feb 22, 2023

Understood thanks ephys, will look into it!

@stellar-scottreed
Copy link

stellar-scottreed commented Feb 22, 2023

@frostzt This caused regressions for us all across across 10+ repos due to undefined previously being a supported value for where. This breaks backwards compatibility and in my opinion should not be a minor version update given the semver definition. I agree that getWhereConditions should support undefined in its implementation.

We do not explicitly pass undefined, but we have functions that accept filters as a parameter and it defaults to undefined, so if that function is called without any filters then undefined will be sent to sequelize. Yes, we could explicitly type-check for undefined before using them, but again given this is a breaking change I do not think it should have been a minor version release.

@frostzt
Copy link
Contributor

frostzt commented Feb 22, 2023

@ephys with the above when I see the initial implementation of the getWhereConditions we do have this sort of check, I do remember you previously pointed out about == and === for these null-ish conditions. I also see that this is being pointed as a no-op here.

Should we follow this and point undefined to be no-op since null and undefined in { where: undefined } or { where: null } look the same to me? 😅

@ephys
Copy link
Member Author

ephys commented Feb 22, 2023

That's the idea :)

I'll send a PR in a minute, I'd like to get this vuln behind us quickly

@Jeymz
Copy link

Jeymz commented Mar 15, 2023

Sorry to bother anybody, but to confirm these CVEs were resolved in 6.28.1 correct? I am assuming they are also no longer present in 6.29.3 or would I be wrong in assuming that?

@ephys
Copy link
Member Author

ephys commented Mar 15, 2023

That's correct :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants