-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Pass query/mutation context into the field privacy detection for better access control #727
Conversation
Just a quick feedback:
=> will review later |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far I can already say: please add a test!
Also, a changelog entry as I think this is the way forward.
Are there any other arguments we might want to consider passing (like we do to the resolver)?
You are right, it breaks compatibility for the privacy policies defined in the class, this looks like a change for the major version then. |
Hi @mfn, I've added tests, changelog entries and marked this PR as the one with breaking changes. Thank you for the feedback, I was so occupied with closure-based privacy handlers, I've completely missed the class-based ones.
I currently don't see use cases where we need anything but query arguments and its context to decide whether a field is accessible in the context of the current operation. All the extra can be passed via the class privacy handler constructor and auto-wired here: graphql-laravel/src/Support/SelectFields.php Line 335 in 468e593
|
May I ask for your help with the code analysis checks?
But when the same action is performed via GitHub, it produces only 2 errors:
|
Ah yeah, super annoying: because of the difference of the PHP version I think. Github Action is using 8.0, see
But: don't worry, I'm not rejecting anyones work due to this ;) Once I've time for the review, I'll take care of it! |
# Conflicts: # CHANGELOG.md # tests/TestCase.php
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the PR!
I fixed the phpstan baseline and some other small things since I was already on it.
PS: that was really as solid PR for a first time contribution, thank you 🙏 |
Summary
Currently
privacy
in the field specification can access only the query/mutation arguments.This creates difficulties in the applications where access to the specific field is based on the current query/mutation context, and the context itself is the robust object which contains user, site area (back office / client area), etc.
This results in quirky workarounds like registering context globally in the app and accessing it via facades.
This PR is fixes this issue by passing query/mutation context to the privacy handlers, so this:
becomes this:
Type of change:
Checklist:
composer fix-style