Search results should not expose private information

hutch - June 25, 2006 - 13:29
Project:Drupal
Version:7.x-dev
Component:search.module
Category:bug report
Priority:normal
Assigned:David Lesieur
Status:patch (code needs review)
Description

The attached patch is on
search.module,v 1.176.2.2 2006/05/07 17:51:24 killes

It adds some checkboxes to the search settings page to control the display of Date, Author, Node type and Extras in the search results page.

HTH

AttachmentSize
search.module_display_results_settings.patch.txt5.34 KB

#1

sugree - July 14, 2006 - 14:46

search keywords module is not search.module.

#2

Tobias Maier - July 14, 2006 - 18:24
Project:Search Keywords» Drupal
Version:4.7.x-1.x-dev» x.y.z
Component:Code» search.module

we only accept new features against drupal CVS HEAD (the upcoming 4.8)

#3

Tobias Maier - July 14, 2006 - 18:29
Status:patch (code needs review)» patch (code needs work)

a lot of changes were made between drupal HEAD and 4.7
--> i guess it wont apply

#4

paranojik - August 2, 2006 - 12:03
Status:patch (code needs work)» patch (code needs review)

reapplied

AttachmentSize
search.module_display_result_settings.patch5.64 KB

#5

Dries - August 2, 2006 - 13:48
Status:patch (code needs review)» patch (code needs work)

Not sure how important this is. One some sites it is probably useful to hide the date and author. And on static sites, the content type might be confusing. We'll want to come up with a better description for "extras". Extra's is not exactly helpful for a user. If you mean 'result snippets', write 'result snippets' (or something equivalent). Otherwise I'm cool with this patch.

#6

Steven - August 2, 2006 - 15:37

Search results are already themable, do we really need explicit toggles?

The texts need work though. A description à la "Show the date in the results" is a bit redundant if you do it for every checkbox. How about naming the fieldset "Show in search results:" and removing the descriptions? "Node type" should be "Content type". And "extras" can be better too... perhaps "module-provided fields"?

Shouldn't we use #type => checkboxes for this as well?

#7

paranojik - August 2, 2006 - 22:56
Status:patch (code needs work)» patch (code needs review)

I agree this is a non-important feature, but for some people this kind of tweaks can be quite usefull... Anyway, I fixed the texts as you suggested, but I also moved the form to the theme settings page following the example of post information settings.

AttachmentSize
search.module_display_result_settings_0.patch3.22 KB

#8

Dries - August 3, 2006 - 07:14
Status:patch (code needs review)» patch (code needs work)

Tweaking your site using settings is always easier and accessible to non-developers / non-designers. It's a useful feature IMO, and the code looks fast and elegant.

At least, the first patch looked elegant. The second patch seems rather complex ... not sure this ought to be a theme setting.

#9

paranojik - August 3, 2006 - 07:53

It's back on the search settings page...

AttachmentSize
search.module_display_result_settings_1.patch3.08 KB

#10

paranojik - August 3, 2006 - 07:54
Status:patch (code needs work)» patch (code needs review)

...and ready for review...

#11

David Lesieur - August 20, 2006 - 19:23

This patch works well for me. I like it.

However, I'd like the search module to also care about the theme settings (as in theme_get_setting('toggle_node_info_' . $node->type)). If a node type requires not to display post information, I think the search results should not show such information. Maybe this is a separate issue though.

#12

David Lesieur - May 23, 2007 - 06:54
Version:x.y.z» 6.x-dev

A bit late to try to revive this issue, but who knows? ;-)

#13

David Lesieur - May 23, 2007 - 14:10
Title:Additional settings to search.module» Post information display setting for search results

#14

David Lesieur - May 23, 2007 - 15:20

Re-rolled the patch (not taking into account my comment in #11).

AttachmentSize
search_result_node_info.patch3.13 KB

#15

Gurpartap Singh - May 23, 2007 - 15:33

Marking http://drupal.org/node/107506 as a duplicate.

Furthermore, per content type setting from theme configuration could be imposed, as pointed on above link?

#16

David Lesieur - May 23, 2007 - 15:47

Yes, I'll make a new patch to take the theme setting into account. I also need to rename the new 'search_result_node_info' variable; it is misnamed because this setting does not apply only to nodes. I should have kept the same name as the previous patch. ;-)

#17

David Lesieur - May 23, 2007 - 16:09

This new patch takes theme settings into account and uses a proper variable name.

AttachmentSize
search_result_node_info_0.patch3.48 KB

#18

David Lesieur - May 23, 2007 - 16:14

Removed an unwanted whitespace.

AttachmentSize
search_result_node_info_1.patch3.48 KB

#19

David Lesieur - May 28, 2007 - 20:47

If anyone is interested in getting this frequently requested feature in Drupal 6, please review and test the patch before the code freeze (June 1st). It's a small and easy patch! :-)

#20

Steven - June 6, 2007 - 22:23
Status:patch (code needs review)» patch (code needs work)

<?php
   
'#description' => t('Select which additional information, besides title and snippet, should be displayed for each search result. This setting will have no effect on content types whose post information is never displayed (as per your !theme).', array('!theme' => l(t('theme settings'), 'admin/build/themes/settings/global'))),
?>

This usage of t()/l() is incorrect.

#21

David Lesieur - June 13, 2007 - 00:15
Assigned to:hutch» David Lesieur
Status:patch (code needs work)» patch (code needs review)

Fixed!

AttachmentSize
search_result_node_info_2.patch3.48 KB

#22

David Lesieur - June 13, 2007 - 00:25

Umm, use this patch instead.

AttachmentSize
search_result_node_info_3.patch3.48 KB

#23

David Lesieur - July 16, 2007 - 20:21
Version:6.x-dev» 7.x-dev

Targetting D7, although the patch still works on D6 at the moment.

#24

Gurpartap Singh - July 25, 2007 - 11:43
Version:7.x-dev» 6.x-dev
Category:feature request» bug report

Would consider the 'post information' displayed on search result pages as a bug. It's really odd, because you don't want to show who created a content page; and if you have search module enabled, anyone can do a query and find the actual author and date of publishing. An example: Handbook pages on drupal.org.

If we can at least create a patch against search.module for Drupal 6.x-dev for respecting the "Display post information" settings in theme configuration, as a part of bug fix actually.

#25

David Lesieur - July 25, 2007 - 13:49

Good point! Here's the patch. ;-)

AttachmentSize
search_result_node_info_4.patch1.53 KB

#26

Gurpartap Singh - July 25, 2007 - 16:31

The patch is to the point for the actual bug fix!! If there's anything else demanded(except a comment?), that would be a feature request most probably. The patch attempts the minimal and best so far:

<?php
 
if ($type != 'node' || theme_get_setting('toggle_node_info_'. $item['node']->type)) {
   
// do the post info. stuff
 
}
?>

Hopefully, this is getting in soon. :)

#27

Gábor Hojtsy - July 25, 2007 - 17:49

Brilliant idea to apply the node toggles here, it is in fact a bugfix this way :) A line of comment would be good though.

#28

David Lesieur - July 25, 2007 - 19:25

Added a comment.

AttachmentSize
search_result_node_info_5.patch1.67 KB

#29

Gurpartap Singh - August 25, 2007 - 05:19

If the patch still applies, anyone going to commit? :)

#30

David Lesieur - August 25, 2007 - 21:25

It still applies. ;-)

#31

catch - October 26, 2007 - 22:09
Status:patch (code needs review)» patch (code needs work)

Not any more it doesn't.

#32

douggreen - November 27, 2007 - 13:15

I looked at a few of the patches in the comments above, and the latest patch now looks incomplete. Fixing the latest patch to use search-result.tpl.php is trivial (patch attached), but someone else should add the settings form back. Was this dropped intentionally?

AttachmentSize
70722.patch965 bytes

#33

David Lesieur - December 10, 2007 - 05:56
Status:patch (code needs work)» patch (code needs review)

As of today, the settings form is there (in admin/build/themes/settings). However, the above patch did not work because $info_split['type'] is a "search type", and the patch seemed to expect a node type instead.

It could be nice to keep the template simple, so I'm proposing this new (and tested) patch that does not affect the tpl file.

AttachmentSize
search_result_node_info_6.patch1.62 KB

#34

Pasqualle - December 21, 2007 - 21:27
Status:patch (code needs review)» patch (reviewed & tested by the community)

tested:
1. tried mixed search, result contains node types with and without post info
2. tried to write print $info_split['user'] into tpl file, to get php error

works without any problem and code looks good

changed patch to apply from drupal root

AttachmentSize
search_result_node_info_7.patch1.66 KB

#35

Pasqualle - December 21, 2007 - 21:43
Status:patch (reviewed & tested by the community)» patch (code needs work)

no, sorry it does show php notice for test #2

#36

Pasqualle - December 21, 2007 - 21:59

search-result.tpl.php

* Since $info_split is keyed, a direct print of the item is possible.
* This array does not apply to user searches so it is recommended to check
* for their existance before printing. The default keys of 'type', 'user' and
* 'date' always exist for node searches. Modules may provide other data.

#37

Pasqualle - December 21, 2007 - 22:55

this is the minimal set of keys required.

AttachmentSize
search_result_node_info_8.patch2.19 KB

#38

Pasqualle - December 21, 2007 - 23:04
Status:patch (code needs work)» patch (code needs review)

#39

David Lesieur - December 22, 2007 - 01:02

@Pasqualle: Thanks for the testing! However, the conditions you've added in your last patch are redundant, and I don't think they're of any use. As you have quoted above regarding $info_split:

This array does not apply to user searches so it is recommended to check for their existance before printing

Checking for existence means using isset() in the tpl file if it needs to use a value from $info_split. The default search-result.tpl.php as it stands now does not use $info_split, and there are no PHP warnings or notices.

My recommendation would be to go with the patch at #34.

#40

Pasqualle - December 22, 2007 - 01:33

read further please

The default keys of 'type', 'user' and 'date' always exist for node searches.

As I read it, the whole description, there are keys like comment and upload and other possible module generated keys which are not guaranteed to be set, but these 3 are always set.
Of course if you examine the code closely, it was not guaranteed even before the patch, but that is a bug, as I understand.

It is basic requirement for css only themes to set all variables used, otherwise you will get php notices.

If you want to go with patch #34, then comment in search-result.tpl.php must be modified also.

#41

David Lesieur - December 22, 2007 - 05:38

Ah, yes... Good catch!

Except for 'type', 'user' and 'date', any value in $info_split already has to be checked for existence, so it seems more consistent to do the same for 'type', 'user' and 'date' as well. At least that's what the patch at #34 implied. This new one changes the comments in search-result.tpl.php to reflect this logic.

AttachmentSize
search_result_node_info_9.patch3.26 KB

#42

robertDouglass - April 15, 2008 - 11:01
Version:6.x-dev» 7.x-dev

#43

robertDouglass - April 15, 2008 - 11:02

still applies.

#44

David Lesieur - May 9, 2008 - 16:26

LIVE FROM THE MINNESOTA SEARCH SPRINT: This patch still applies and works.

#45

puregin - May 9, 2008 - 16:50
Title:Post information display setting for search results» Search module may leak post information

LIVE FROM THE MINNESOTA SEARCH SPRINT

Changing the title to better reflect the issue.

Currently, search results reveal authorship and other 'post' information, even if a site admin has elected to hide this information in the theme settings. This could be construed as an information leak.

This patch fixes that issue, by checking whether the theme allows post information to be displayed before populating the search results.

#46

puregin - May 9, 2008 - 17:04
Status:patch (code needs review)» patch (reviewed & tested by the community)

LIVE FROM THE MINNESOTA SEARCH SPRINT

Reviewed code; variable setting code in template_preprocess_search_result() is now executed conditionally for non 'node' type results or node types for which 'toggle_node_info_' is set.

Tested as follows:

* Before the patch is applied, all post information is displayed for all node types in search results

* With patch applied, enabled 'display post information' for a given set of types. Typed a search term which displays results encompassing all node types. Only the types for which 'display post information' is enabled now have post information displayed in search results. Tried this for several different combinations of types.

#47

Dries - May 10, 2008 - 07:44

puregin: can you try writing a simpletest for this? It shouldn't be too hard.

#48

Dries - May 10, 2008 - 07:44
Status:patch (reviewed & tested by the community)» patch (code needs work)

puregin: can you try writing a simpletest for this? It shouldn't be too hard.

#49

douggreen - May 12, 2008 - 02:35
Title:Search module may leak post information » Search results should not expose private information

#50

pfournier - May 20, 2008 - 18:40

Hi,
This weekend PHP Quebec organized a Code Fest; I used this occasion to write a simpletest to test the presence of node info in the test result. Here is the new patch for the module.

AttachmentSize
search_result_node_info_10.patch5.87 KB

#51

pfournier - May 20, 2008 - 18:39
Status:patch (code needs work)» patch (code needs review)
 
 

Drupal is a registered trademark of Dries Buytaert.