-
Notifications
You must be signed in to change notification settings - Fork 61
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 server error if not authenticated #447
base: 3.8
Are you sure you want to change the base?
Conversation
For context : silverstripe/silverstripe-framework#9978 Here, my proposal is to return a consistent json response
I'd hesitate to just catch all Have you identified what is specifically causing the |
I can improve the pr to catch the specific message if needed |
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.
The exception being caught is from SilverStripe\GraphQL\Controller::getRequestUser()
:
silverstripe-graphql/src/Controller.php
Lines 439 to 447 in b51ce72
if (!$member) { | |
throw new Exception("Authentication required"); | |
} | |
// Check authorisation for this member | |
$allowed = Permission::checkMember($member, $permissions); | |
if (!$allowed) { | |
throw new Exception("Not authorised"); | |
} |
The exceptions were originally added to
index()
in #57.
We should probably also treat the "Not authorised" exception message in the same way.
In general I'm okay with this. If you're happy to make a change to check for the "Not authorised" message, and change the response code (401 for "Authentication required" and 403 for "Not authorised"), I'll be happy to approve it. I'll probably ask someone more familiar with GraphQL to review it before I'd be comfortable merging.
Note that while @unclecheese did say it shouldn't require authentication at all in the issue, I don't have enough background on why the authentication checks were added in the first place, so I'm more comfortable with this approach.
Co-authored-by: Guy Sartorelli <[email protected]>
I don't think that's strictly necessary. I don't mind having logged in users get that kind of error page. My issue is that public endpoints can be visited by anyone (bots for example) and trigger errors that get logged for instance. I think the current design works ok as long as the public use case is covered. I've changed the error code as you requested. |
Sorry it's taken me so long to get back to this. Once that's done I'll be happy to merge. Alternatively if you don't plan on continuing with this PR please close it. |
@GuySartorelli done |
Thanks for that. Unfortunately as mentioned in #447 (review) the two scenarios news to return differen HTTP code (specifically 401 for "Authentication required" and 403 for "Not authorised") Can you please make that change? |
sorry i missed that one |
For context : silverstripe/silverstripe-framework#9978
Here, my proposal is to return a consistent json response