Code Monkey home page Code Monkey logo

graphql-authz's People

Contributors

davidtkachenkoastrumu avatar defond0 avatar dependabot[bot] avatar dimatill avatar github-actions[bot] avatar hayes avatar kerimcharfi avatar vtereshyn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

graphql-authz's Issues

Check if rules used in authSchema even exists

export const authZRules = {
    IsAdmin
} as const;

const authSchema = {
  User: {
    email: { __authz: { rules: ['isAdmin'] } }
  }
};

Did you spot the typo? I think its necessary to check if a rule used in a schema even exists to prevent unindented data leakage.

I would make a simple checking inside this function:

export function completeConfig(

I can do it and make a PR if you want. Whats your opinion?

Queries with fields not in the schema cause an unhandled TypeError

When using the apollo-server plugin it looks like when an invalid query is passed to api, the plugin throws a type error.

TypeError: Cannot read properties of undefined (reading 'args')
    at getArgumentValues (/Users/jeffreydefond/projects/graphql-authz/node_modules/graphql/execution/values.js:183:28)
    at Object.Field (/Users/jeffreydefond/projects/graphql-authz/packages/core/src/rules-compiler.ts:290:27)
    at Object.enter (/Users/jeffreydefond/projects/graphql-authz/node_modules/graphql/utilities/TypeInfo.js:387:27)
    at visit (/Users/jeffreydefond/projects/graphql-authz/node_modules/graphql/language/visitor.js:200:21)
    at compileRules (/Users/jeffreydefond/projects/graphql-authz/packages/core/src/rules-compiler.ts:346:3)
    at Object.requestDidStart (/Users/jeffreydefond/projects/graphql-authz/packages/plugins/apollo-server/src/index.ts:26:29)
    at initializeRequestListenerDispatcher (/Users/jeffreydefond/projects/graphql-authz/node_modules/apollo-server-express/node_modules/apollo-server-core/src/requestPipeline.ts:598:39)
    at processGraphQLRequest (/Users/jeffreydefond/projects/graphql-authz/node_modules/apollo-server-express/node_modules/apollo-server-core/src/requestPipeline.ts:115:28)
    at ApolloServer.executeOperation (/Users/jeffreydefond/projects/graphql-authz/node_modules/apollo-server-express/node_modules/apollo-server-core/src/ApolloServer.ts:995:33)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

@graphql-authz/apollo-server-plugin should probably use @graphql-authz/core as peer dep

@graphql-authz/[email protected] declares @graphql-authz/[email protected] as dependency.

This can lead to a dangerous setup: this is what I had on my project:

@graphql-authz/[email protected]
@graphql-authz/[email protected]

Because my @graphql-authz/core was at version 1.2.1, my @graphql-authz/apollo-server-plugin was using an extra instance of @graphql-authz/core at version (1.3.0). This makes the two packages disconnected.
This setup result in all rules being silently ignored at all while running the graphql server.

A possible solution could be to declare @graphql-authz/[email protected] as peer dep, so yarn does not create an extra instance.
The runtime would crash, which would be desirable.

rules-compiler breaks esm build

After digging for quite a while I found the reason why the compiled version of my esm and esbuild based project contains the graphql dependency twice.
The culprit is line 14 of rules-compiler.ts in graphql-authz. graphql is marked as a peer dependency, but the deep import of getArgumentValues, still pulls in the complete graphql library a second time. graphql detects this and throws the "Ensure that there is only one instance of 'graphql' in node_modules" error, making 'graphql-authz' essentially incompatible with my setup.

The good news: there's no reason for the deep import, because getArgumentValues is also exported at the top level. If you could fix this, I would be very grateful.

GiraphQL compatibility

Hey,

Just wrote a tiny plugin for GiraphQL that makes applying rules to fields/types slightly simpler when building schemas with giraphql. https://giraphql.com/plugins/authz

Obviously not necessary to make things work, but gets you something with better type-checking and avoids needing to define a complicated extensions object for each field/type.

Migrate to pnpm

Most new repositories for the organization and the community use pnpm. We need to look ahead and use a modern approach too

Am I doing something wrong?

I have a code first schema using apollo v4 server. I have sometning like this

currentMarketUser: {
extensions: createAuthZExtensions({
rules: ["IsMarketUserOnly"],
}),
type: internalServices.IAMService.api.graph.types
.CurrentMarketUserType,
resolve: (_, args, context) =>
internalServices.IAMService.api.graph.queries.currentMarketUser(
_,
args,
context
),
},

but it seems the rule never runs. I read the libary code and it seems

const compiledRules = (0, core_1.compileRules)({
document: filteredDocument,
schema: requestContext.schema,
rules,
variables,
directiveName,
authSchemaKey,
authSchema
});

compiledRules rules is empty and i think it because its checking only entities but not the top level query function. Is it supposed to? I feel like i copied the examples pretty closely

thanks for the help!

Authorization checks not applied correctly for unions and interface

Was just skimming through some of the code when I fixed the __typename issue and it looks like authorization rules on objects are ignored when the query resolved them through a union or interface. This seems like a pretty important case to cover. This would make any nodes in a relay style graph accessible without auth checks through the node or nodes queries.

@graphql-authz/envelop-plugin has conflicting peer dependencies

Getting errors about @graphql-authz/envelop-plugin has conflicting peer dependencies

xxx in ~/xxx > npm install @graphql-authz/envelop-plugin
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: @anvara-project/[email protected]
npm error Found: @envelop/[email protected]
npm error node_modules/@envelop/core
npm error   @envelop/core@"^5.0.1" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @envelop/core@"^1.0.3" from @graphql-authz/[email protected]
npm error node_modules/@graphql-authz/envelop-plugin
npm error   @graphql-authz/envelop-plugin@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /xx/xx/.npm/_logs/2024-06-14T14_03_36_591Z-eresolve-report.txt
npm error A complete log of this run can be found in: /Users/xx/.npm/_logs/2024-06-14T14_03_36_591Z-debug-0.log

The apollo-server-plugin needs to be updated for Apollo Server v4

If using @apollo/server v4 the "context" value in rule execution is undefined.

This is because: (https://www.apollographql.com/docs/apollo-server/migration/#fields-on-graphqlrequestcontext)

The context field has been renamed contextValue for consistency with the graphql-js API and to help differentiate from the context option of integration functions (the function which returns a context value).

Adjusting the code for the plugin might not be too tricky, but new tests need to be written since @apollo/server v4 also changes mocks. (https://www.apollographql.com/docs/apollo-server/testing/mocking/)

๐Ÿ“ฃ New in Apollo Server 4: Apollo Server 4 removes both the mocks and mockEntireSchema constructor options

I am creating this issue as a placeholder, since my PR fails type-based tests. #92

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.