this is a major show stopper for decoupled drupal 8 developers.
The following endpoint;
* /entity/taxonomy_vocabulary/{taxonomy_vocabulary} produces a 403 and {"error":""}
Example to reproduce:
curl --request GET -k -s -i --user username:password --header 'X-CSRF-Token: YourTokenHash' 'https://example.com/entity/taxonomy_vocabulary/tags?_format=hal_json'
HTTP/1.1 403 Forbidden
...
...
{"error":""}
(...and yes, i checked permissions, and i have enabled both:
Access GET on Taxonomy term resource
Access GET on Taxonomy vocabulary resource
...)
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 2772413-9.patch | 658 bytes | jacov |
| #8 | 2772413-8.patch | 621 bytes | jacov |
| #6 | Screen Shot 2016-07-25 at 8.47.54 PM.png | 65.2 KB | jacov |
| #5 | Screen Shot 2016-07-25 at 8.44.58 PM.png | 130.46 KB | jacov |
| #4 | Screen Shot 2016-07-25 at 8.22.15 PM.png | 221.02 KB | jacov |
Comments
Comment #2
jacov commentedthe workaround for GET is to create a REST Export View for taxonomy terms || vocabs.
haven't found a solution to POST taxonomy terms yet though...
Comment #3
jacov commenteda quick hack to get around this is to comment out AccessDeniedHttpException on line 45 of core/modules/rest/src/Plugin/rest/resource/EntityResource.php
so looks like the $request is coming through and i see the values in the stack trace...but looks like isAllowed() is not being set for the taxonomy routes...
...still digging...
Comment #4
jacov commentedComment #5
jacov commentedComment #6
jacov commentedComment #7
jacov commentedok, found the issue...
the access control logic is incorrect.
the condition is to throw an AccessDeniedHttpException when $entity_access is anything other then isAllowed,
however the value returned from $entity_access = $entity->access('view', NULL, TRUE);
is "\Drupal\Core\Access\AccessResultNeutral"
which should be handled as isNeutral.
so the real fix hear, is to not run the logic on if (!$entity_access->isAllowed()) rather on isForbidden which is what a 403 Forbidden / AccessDeniedHttpException actually is.
actual code change would be on line 44 of core/modules/rest/src/Plugin/rest/resource/EntityResource.php
working on generating a patch...
Comment #8
jacov commentedComment #9
jacov commentedComment #10
jacov commentedadding patch for 8.2.x branch as well
Comment #11
jacov commentedadding patch for 8.2.x branch as well
Comment #12
jacov commentedComment #13
cilefen commentedComment #14
jacov commentedconfirmed patch #8 fixes the 403 Forbidden 'error' for requests to 'entity/taxonomy_vocabulary/{id}'
the 403 & null 'message' issue on endpoint '/taxonomy/term/{taxonomy_term}' still remains, working on debugging that one too...
Comment #15
jacov commentedgoing to edit this issue description to ensure patch makes it, and filed #2772537: REST Views override existing REST GET routes to be addressed seperately
Comment #16
jacov commentedComment #17
jacov commentedComment #18
jacov commentedComment #19
jacov commentedComment #20
cilefen commentedHi! Patches are peer-reviewed and this one lacks a test.
Comment #21
wim leersAccessResultInterfacevalues. Read the code and its docs. And perhaps read the relevant change record (https://www.drupal.org/node/2337377).Are you perhaps new to open source?
Comment #22
wim leersPlease post your
rest.settings.yml.Comment #23
wim leersAlso marked #2772537: REST Views override existing REST GET routes as a duplicate for now, because it's not yet clear that this issue is a bug, let alone that we need yet another, almost-duplicate issue.
Comment #24
dawehnerThank you for your patch
Note:
\Drupal\Core\Access\AccessManager::checkuses alsoisAllowedwhich is the canonical place for checking access on routes.Let me also quote
AccessResultInterface:. Given that I think the problem is rather the vocabulary access check.
If this is just about access checking on vocabularies, I also can't really believe this is critical, but feel free to disagree with it :)
Comment #25
jacov commentedthanks @dawehner && @wim-leers
if the access control logic is working as intended, then a neutral value should not be passed in the previous $entity_access line, as it will never work...
here is my settings...
rest.settings.yml
i marked this as critical because without the taxonomy endpoints working, the REST service is not ready for production.
Comment #26
wim leersThat may very well be, but it still doesn't meet the "critical" definition.
Okay, great. You have enabled the taxonomy vocabulary REST resource. Looking at
\Drupal\Core\Entity\EntityAccessControlHandler::checkAccess(), you need theadminister taxonomypermission to be allowed to GET Taxonomy Vocabulary config entities. So, does the user that's doing REST requests have that permission?Comment #27
wim leersNote that vocabularies are config entities. Config entity GET support was added in Drupal 8.2, in #2724823: EntityResource: read-only (GET) support for configuration entities. This is not supported in Drupal 8.1.
Comment #28
wim leersAlso note that you won't be able to PATCH/POST/DELETE vocabulary entities at all, for that we'll need #2300677: JSON:API POST/PATCH support for fully validatable config entities to happen first.
That being said, the error message you're seeing is extremely unhelpful. That's unacceptable. To fix that, we have #2681911: REST requests without X-CSRF-Token header: unhelpful response significantly hinders DX, should receive a 401 response and #2659070: REST requests without Content-Type header: unhelpful response significantly hinders DX, should receive a 415 response. But those only improve error messages for PATCH/POST/DELETE requests. I don't yet know what is causing this particular error. Investigating…
Comment #29
jacov commentedfyi...
after applying the patch, i can see the proper response & json as follows:
Comment #30
jacov commentedComment #31
wim leersCool, but the patch is definitely wrong. You'll need to debug this response, to figure out why it's getting a "neutral" access result and not an "allowed" one.
Enable xdebug and put a breakpoint in
\Drupal\Core\Entity\EntityAccessControlHandler::checkAccess(), that should lead you to the root cause.Comment #33
wim leersDoes this user have the
administer taxonomypermission?EDIT: to clarify: you say this in the IS:
But that's not enough. That's just the default 8.1.x way of allowing access to a REST resource in the first place (that's gone by default in 8.2). You then also need access to perform this operation on that entity: you need to be allowed to do this by
$entity->access($operation)too!Comment #34
jacov commentedno Wim, at the time the user did not have
administer taxonomy permissionsenabled.only RESTful Web Services:
* Access GET on Taxonomy term resource
* Access GET on Taxonomy vocabulary resource
i later went in and enabled
administer taxonomy permissions, so that i can GET and POST new terms, and that worked.so yes, it looks like
administer taxonomy permissionsis required for GET to work, which is technically "dangerous" if you are looking to only open READ ONLY / GET access.imho, the fix here should be to respect the RESTful Web Services permissions over the
administer taxonomy permissions, because we may not want to necessarily allow full admin access to the api user.Comment #35
wim leersYes it is. But the solution then is to add additional permissions for viewing/updating/…
Vocabulary. For now, there is not a separate "view vocabulary" permission.This would be at least equally dangerous, because it means the Entity Access API would need to be bypassed. Furthermore, in Drupal 8.2 and beyond, the
restful get <entity type>permission is no longer enabled by default (existing sites will continue to have that, and new sites can opt in to it). Precisely because it's very confusing that there's a separate permission on top of the Entity Access API that must already grant you access anyway.So, two follow-ups must be solved:
Vocabularyentities: #2808217: To be able to view Vocabulary config entities via REST, one should not have to grant the 'administer taxonomy' permission (patch posted!)