Greetings.
Here is problem that we have to face, when we started to use this module.
We have a quite bit complex project with OG. It is very important question for us that users only access those content and comment that they have access. OG modules serves this well, but Search API causes security breach. WHY?
We need a multi-index search our site with node and comment indexes. Node index works well, just need to check "Node access check" option on index and users only access those content that they have access. But at this time the comment index had no "Access check" feature, that's why every users can see every comments, didn't matter if s(he) member of those group where the comment was posted or not. For us this is a really huge bug!
That's why I've made a little patch for Search API which check user access for comments too. I'm not saying this is perfect, but at this time works well as we see. Please take a review on it and suggest improvements. (Maybe it is not necessary to be separated from original node access check...)
To test this doesn't need a multi-index. Only enough a comment index on an OG site.
Have nice day! mxr576
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | 2118589-22--follow_up_node_access_fix.patch | 831 bytes | drunken monkey |
| #13 | 2118589-13--comment_access.patch | 11.98 KB | drunken monkey |
| #12 | search-api-comment-access.patch | 8.03 KB | mxr576 |
| #10 | search-api-comment-access.patch | 8.13 KB | mxr576 |
| #5 | search-api-comment-access.patch | 10.08 KB | mxr576 |
Comments
Comment #2
mxr576Path in patch file updated.
Comment #3
mxr576Patch updated
Comment #5
mxr576meh line-ending.
Comment #7
drunken monkeyGood idea, thanks for the patch!
Aside from the test bot not succeeding in applying it, there are several things to still fix, though. But apart from those, if it works properly, I'd commit it to the project.
Wrong class name.
"nodes" in second line. Everything else should be replaced by "Overrides SearchApiAbstractAlterCallback::supportsIndex()." as the first line.
Comment lines shouldn't exceed 80 characters, plus same as before with "Overrides …" plus the thing that changed compared to parent class.
If you use the same field name as for nodes,
search_api_search_api_query_alter()becomes a lot easier to implement. Also, this should in any case be properly namespaced.This can just use
@{inheritdoc}.Since you always use
$items[$cid]to manipulate the items, don't define$itemas a reference.Comment line length again.
"… if any are enabled."
As said, use the same property name for both nodes and comments. I don't think the two branches are necessary in either case, though – 90% of the code is identical.
Comment #8
drunken monkeyComment #9
mxr576Thanks for review!
Yes, I have some problem with generating proper patch file on Windows, but I've some issues that day on my Linux system, so can't use it either.
I'll fix these issues that you've mentioned. But I have to mention that in some points (ex.: 6) I've just used the copy of "callback_node_access.inc" file, so please take review on that too.
I'm glad that this idea proved useful.
Regards, mxr576
Comment #10
mxr576Patch updated.
Comment #12
mxr576Comment #13
drunken monkeyAs said, you should really use the similarities between the two data alterations better, not just copy the whole code. Attached is a rewrite which uses as much common code as possible, thus significantly reducing the complexity. Please test/review whether it still works for you (best also node access).
Comment #14
mxr576It seems working fine! Thanks for perfecting this.
Comment #15
drunken monkeyGood to hear.
Committed.
Thanks again for your great work!
Comment #17
Paul B commentedThe patch removes the !empty($fields['search_api_access_node']) check in search_api_search_api_query_alter(). Is this deliberate?
After upgrading from 7.x-1.8 to 7.x-1.10, I get an error
Comment #18
Paul B commentedComment #19
drunken monkeyYes, I'd say that's deliberate. Silently failing to do node access sounds like a really, really, REALLY bad idea, don't you agree?
Either mark the field as indexed or disable the "Node access" data alteration. If you have the latter enabled, the module has to assume you want node access, and should not just ignore it if it can't add it.
Comment #20
Paul B commentedBut the "Node access" data alteration is already disabled. The $index->options['data_alter_callbacks'] for the default fuzzysearch index contains
which is not empty. If I enable node access data alteration, it says
On https://drupal.org/node/1254452 it says
So if it's not checked, I'd expect that node access checks are not enabled and so I should not get this error.
Comment #21
Paul B commentedComment #22
drunken monkeyOK, I'm definitely overworked. Another sloppy patch/review …
Thanks for spotting this! (You should have mentioned the disabled data alteration right away, though.)
The attached patch should fix this, it's a rather stupid mistake.
Comment #23
Paul B commentedThe patch seems to fix it. Thanks for the quick followup.
Comment #24
rjacobs commentedJust wanted to add a second confirming review for the patch in #22.
"Node Access" option is unchecked in:
admin/config/search/search_api/index/[index_name]/workflow
Without the patch we receive a barrage of "SearchApiException: Required field search_api_access_node not indexed..." errors. With the patch everything works happily again.
I'm not super familiar with all of the logic in the methods involved here, but from a look at the patch it appears pretty minor and just seems to address an oversight in a conditional check. Given this, and the fact that patch author is the maintainer, it seems safe to again mark this RTBC.
Comment #25
drunken monkeyThanks for the reviews, good to hear it works!
Committed.
Comment #29
drunken monkey