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 report Something isn't working confirmed Confirmed bug
Projects

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):

  • OS: NixOs
  • Version: @neo4j/graphql@4.2.0
  • Node.js version: v18.17.1
@afreakk afreakk added the bug report Something isn't working label Oct 2, 2023
@neo4j-team-graphql neo4j-team-graphql added this to Bug reports in Bug Triage 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! 🙏

@Liam-Doodson Liam-Doodson moved this from Bug reports to Confirmed in Bug Triage Oct 2, 2023
@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.

@Liam-Doodson Liam-Doodson moved this from Confirmed to High priority in Bug Triage Oct 3, 2023
@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.

@darrellwarde darrellwarde moved this from High priority to Confirmed in Bug Triage Oct 10, 2023
@a-alle a-alle moved this from Confirmed to In progress in Bug Triage Nov 1, 2023
@a-alle a-alle moved this from In progress to Confirmed in Bug Triage Nov 1, 2023
@Liam-Doodson Liam-Doodson moved this from Confirmed to Low priority in Bug Triage Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something isn't working confirmed Confirmed bug
Projects
Bug Triage
Low priority
Development

No branches or pull requests

3 participants