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

Order of fields on a type matter for @authorization validation #4054

Open
afreakk opened this issue Oct 2, 2023 · 5 comments
Open

Order of fields on a type matter for @authorization validation #4054

afreakk opened this issue Oct 2, 2023 · 5 comments
Labels
bug Something isn't working confirmed Confirmed bug

Comments

@afreakk
Copy link

afreakk commented Oct 2, 2023

Describe the bug
In certain scenarios, the order of fields on a type matter for @authorization validation.

To Reproduce

  1. Clone the following repo https://github.com/afreakk/n4j-issue

  2. yarn install

  3. ./test.sh watch-test

  4. Test should now fail with:

    ...snipped...
    -               "id": Any<String>,
    +           "extensions": Object {
    +             "code": "INTERNAL_SERVER_ERROR",
    +             "stacktrace": Array [
    +               "Neo4jGraphQLForbiddenError: Forbidden",
    ...snipped...
    
  5. Now if you change the following type in schema.graphql:

    type VehicleCard
        @authorization(
            validate: [{ where: { node: { tenant: { admins: { userId: "$jwt.id" } } } } }]
        ) {
        id: ID! @id
        garages: [Garage!]! @relationship(type: "VALID_GARAGES", direction: OUT)
        tenant: Tenant! @relationship(type: "VEHICLECARD_OWNER", direction: OUT) # <---  this line
    }
    

    By moving the pointed to line up so the type will look like this:

    type VehicleCard
        @authorization(
            validate: [{ where: { node: { tenant: { admins: { userId: "$jwt.id" } } } } }]
        ) {
        id: ID! @id
        tenant: Tenant! @relationship(type: "VEHICLECARD_OWNER", direction: OUT) # <---  this line
        garages: [Garage!]! @relationship(type: "VALID_GARAGES", direction: OUT)
    }
    
  6. Tests will now pass...
    (you can force save index.test.js to force rerun of tests)

Expected behavior
Order of fields should not have an impact on @authorization.

System (please complete the following information):

@afreakk afreakk added the bug Something isn't working label Oct 2, 2023
@neo4j-team-graphql
Copy link
Collaborator

Many thanks for raising this bug report @afreakk. 🐛 We will now attempt to reproduce the bug based on the steps you have provided.

Please ensure that you've provided the necessary information for a minimal reproduction, including but not limited to:

  • Type definitions
  • Resolvers
  • Query and/or Mutation (or multiple) needed to reproduce

If you have a support agreement with Neo4j, please link this GitHub issue to a new or existing Zendesk ticket.

Thanks again! 🙏

1 similar comment
@neo4j-team-graphql
Copy link
Collaborator

Many thanks for raising this bug report @afreakk. 🐛 We will now attempt to reproduce the bug based on the steps you have provided.

Please ensure that you've provided the necessary information for a minimal reproduction, including but not limited to:

  • Type definitions
  • Resolvers
  • Query and/or Mutation (or multiple) needed to reproduce

If you have a support agreement with Neo4j, please link this GitHub issue to a new or existing Zendesk ticket.

Thanks again! 🙏

@neo4j-team-graphql neo4j-team-graphql added the confirmed Confirmed bug label Oct 2, 2023
@neo4j-team-graphql
Copy link
Collaborator

We've been able to confirm this bug using the steps to reproduce that you provided - many thanks @afreakk! 🙏 We will now prioritise the bug and address it appropriately.

@neo4j-team-graphql
Copy link
Collaborator

This bug report has been assigned high priority to fix. If you wish to contribute a fix, please branch from master and submit your PR with the base set to master. Thanks!

@darrellwarde
Copy link
Contributor

Hey @afreakk, I've been taking a look at this the past days. This is primarily down to the nature of authorization rules are checked directly before and after each operation, rather than before and after the entire query or mutation. The fix here is to change this architecture to the latter, which as you can maybe guess, is a very large bug fix!

We don't consider there to be a security issue here, so we are going to take this to the drawing board to think about how to achieve this over the coming weeks and months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working confirmed Confirmed bug
Projects
Status: Low priority
Development

No branches or pull requests

3 participants