While I was working on the port of Menu Admin per Menu to Drupal 7, I found this bug:

How to reproduce the bug?

1. Create a content type called Page (for instance) and check only Main menu as Available menus.
2. Add a new Page content and provide a menu link. You will notice that Parent item only list Main menu items as options, which is the expected behavior.
3. Navigate to admin/structure/menu/manage/main-menu to list Main menu items and edit the link you just added at 2.
4. Look at the Parent item select box: it allows all the existing menu items as parent when it should only allow Main menu items.

I mark this as critical as it is a security issue.

Comments

anrikun’s picture

I just noticed that where is a @todo about this in menu.module

<?php
// @todo This will fail with the new selective menus per content type.
?>

Is someone already working on it?

montesq’s picture

Status: Active » Closed (works as designed)

Hello anrikun,
This is the normal behaviour.
In the content-type form, if you select the option "provide a menu link", it just means that when you create a new content (for instance page), you are able to add a link in the selected menu.
It doesn't mean that nobody can put a link in another menu to this content.

Moreover, when you use the administrator account, you don't see this, but to proceed the first step you need the "create Page content" permission, whereas to accomplish the step 3, you need the permission "Administer menus and menu items"

tim.plunkett’s picture

Title: Security issue: "Edit menu link" form does not filter parent options according to content type menu settings. » "Edit menu link" form does not filter parent options according to content type menu settings.
Priority: Critical » Normal
anrikun’s picture

Title: "Edit menu link" form does not filter parent options according to content type menu settings. » Security issue: "Edit menu link" form does not filter parent options according to content type menu settings.
Priority: Normal » Critical

After reading your explanation, I think you are right.
Actually, this check has to be performed by Menu Admin per Menu and not by Core.
Thank you for your answer!

anrikun’s picture

Title: "Edit menu link" form does not filter parent options according to content type menu settings. » Security issue: "Edit menu link" form does not filter parent options according to content type menu settings.
Priority: Normal » Critical

Reopening this as I really think there is something strange here.
After the steps written in my first post, do the following:
5. From the Parent item select box, choose a parent item of a menu different from Main menu, let's say Management for instance.
6. Edit again the Page content added at 2.
7. Look at the Parent item select box: the selected parent item is now <Main Menu>!
Imagine that you just wanted to change the title of the page and you that you save. The menu item pointing to the page will be moved from Management to Main Menu and you might not even have noticed it!
This kind of conflict can definitely not be considered as a normal behaviour.

A possible solution is to disable the Parent item field in the node edit form when the existing menu link belongs to a unallowed menu for the content type.
I think that it is what the @todo at #1 refers to.

anrikun’s picture

Title: Security issue: "Edit menu link" form does not filter parent options according to content type menu settings. » "Edit menu link" form does not filter parent options according to content type menu settings.
Priority: Critical » Normal
Status: Closed (works as designed) » Active
anrikun’s picture

Project: Menu Admin per Menu » Drupal core
Version: 6.x-1.4 » 7.x-dev
Component: Code » menu system

Another (preferred) possible solution would be to add an extra validation to the menu_edit_item form:
if the Path points to a node which content type does not allow the selected Parent item, display an error about the selectedParent item.

tim.plunkett’s picture

Title: Security issue: "Edit menu link" form does not filter parent options according to content type menu settings. » In "node edit form" menu settings, when editing an existing node, the selected "Parent item" might be wrong.
Project: Drupal core » Menu Admin per Menu
Version: 7.x-dev » 6.x-1.4
Component: menu system » Code
Priority: Critical » Normal

Not reproducible in Core. The steps to reproduce aren't even possible without the Menu Admin per Menu module.

anrikun’s picture

StatusFileSize
new29.16 KB

Are you kidding?
Why are you moving this to the Menu Admin per Menu module which is not even ported to Drupal 7 yet?
The issue I'm talking about is in Drupal 7, not Drupal 6.
Please follow the steps again or at least let someone else do it and give his option too, before deciding to close or move this issue this way.
By the way, there is another bug here:
#955848: When editing an existing node with a link, the link itself is listed in "Parent item": menu_parent_options needs some rewriting

I'm currently working on this issue to provide a patch so please do not close it again.

montesq’s picture

@tim.plunkett
Yes that is reproducible in core...
Let me sum up the steps:
1. Create a content type called Page (for instance) and check only Main menu as Available menus.
2. Add a new Page content and provide a menu link. You will notice that Parent item only list Main menu items as options, which is the expected behavior.
3. Navigate to admin/structure/menu/manage/main-menu to list Main menu items and edit the link you just added at 2.
4. Change the parent link for "management"
=>you can check that the link has been removed from main menu and added in the menu management = normal behaviour for me
5. Edit the node and without changing anything click on "save"
=> the link in "main menu" appears again and disappears from the management menu: I agree with anrikun that this behaviour is quite surprising but I very embarrassed for the solution...

tim.plunkett’s picture

My apologies, I must have gotten lost between the OP and the steps in #5.

anrikun’s picture

Status: Active » Needs review
StatusFileSize
new1.05 KB

Here is a patch that implements the solution at #7.
Hope it passes validation.

Status: Needs review » Needs work

The last submitted patch, menu.admin_.inc_.patch, failed testing.

anrikun’s picture

Assigned: Unassigned » anrikun

Well, as I am new to SimpleTest, I need help to figure out why the patch failed testing.
AFAIK it seems to work in real testing.

anrikun’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB

Here is an updated patch: I have added a missing ^ in the preg_match.
This patch will not pass current test as menu.test itself should be updated to handle the extra validation added by the patch.
That is why I have added the .txt extension to the file name.
Please review it.

anrikun’s picture

StatusFileSize
new2.04 KB

Updated patch with test.menu

anrikun’s picture

Title: In "node edit form" menu settings, when editing an existing node, the selected "Parent item" might be wrong. » menu/menu.admin.inc lets users move node menu links to unavailable menus.
Priority: Normal » Critical

Imagine that you want to let a user administer menus and menu items but not content types.
You give this user the "Administer menus and menu items" permission, but not the "Administer content types" permission.
Doing so, you expect that this user will not be allowed to move a node menu link to a menu that is not set as available for this node's content type.
That is why I think this a security issue, thus marking this as critical again.

catch’s picture

Priority: Critical » Major

The menu drop-down restriction is an interface setting for usability, it's not a permission, so this isn't a security issue. It is however an annoying bug so leaving at 'major'. I have a feeling there's an older issue about this, couldn't find it, but while looking I found #949712: When Editing a Basic Page that has a Menu Item on a custom menu, it defaults to being on Main Menu - and deletes a menu item. which was duplicate.

It would be good to update the test so it actually fails without the patch.

anrikun’s picture

StatusFileSize
new3.71 KB

Here is a new patch with menu.test updated to fail without the patch.

anrikun’s picture

StatusFileSize
new2.58 KB

Now the patch for menu.test alone.
It should fail 4 times.

Status: Needs review » Needs work

The last submitted patch, menu.test.patch, failed testing.

anrikun’s picture

Status: Needs work » Needs review
StatusFileSize
new3.71 KB

The previous patch failed as expected.
Now let's put back the full patch.
Please review and commit it.

anrikun’s picture

Assigned: anrikun » Unassigned

Changing to "Unassign" as I have finished working on this issue.

anrikun’s picture

Title: menu/menu.admin.inc lets users move node menu links to unavailable menus. » menu/menu.admin.inc lets users add or move node menu links to unavailable menus.

Changing title to better describe the issue.

lyd’s picture

I love Drupal 7 so far but this problem is impossible to live with.
As main administrator, I last updated Drupal 7 core on Jan 29th (drupal-7.x-dev)
Every time I update a single word in the body and save, the page disappears from my menu and appears in the secondary links menu.
The only way to move it back is via admin/structure/menu.
This creates endless hassle.
Is there something I do not understand?

lyd’s picture

Apologies. I found my answer here:

http://drupal.org/node/957784
#4 Posted by marcingy on November 12, 2010 at 10:46pm
Priority: major » normal
No it doesn't the issue is caused by the fact that you have created a new menu and then have not defined this menu as being available for the content type under admin/structure/types/manage/xxx. This results in the menu item being associated with main menu as that is the only menu option that has been available.

I simply had not made all relevant menus available in the content type.

jastraat’s picture

subscribe

zilverdistel’s picture

subscribe

anrikun’s picture

@jastraat, @zilverdistel:
Did you review the patch?

jastraat’s picture

@anrikun
Just tested the patch from #23 against latest -dev
When trying to change a page (only allowed in main menu) to have the management menu as its parent through the menu administration page, get a notice: "The Management menu cannot contain links to the path 'node/12'."

While this seems better than the original behavior, I still think it would be more user-friendly for non-options not to appear in the parent select in the first place.

anrikun’s picture

Unfortunately, this is not that easy: you cannot tell what parent option is allowed or not before the user actually submits a path.
We could imagine some Ajax feature that would dynamically rebuild the parent options based on the path the user has just entered, but that would be an extra feature.
Here the issue is just about fixing the missing validation bug that leads to unallowed modifications.
Reading that, do you think the patch does the job?

jastraat’s picture

The patch prevents a node from being put into a disallowed menu, so it fixes the validation problem.

anrikun’s picture

Status: Needs review » Reviewed & tested by the community

I suggest you mark this issue as RTBC then.

bfroehle’s picture

Status: Reviewed & tested by the community » Needs work
--- modules/menu/menu.admin.inc	2010-10-20 09:40:59.000000000 +0200
+++ modules/menu/menu.admin.inc	2011-01-21 16:41:08.000000000 +0100
@@ -385,6 +385,19 @@ function menu_edit_item_validate($form, 
   if (!trim($item['link_path']) || !drupal_valid_path($item['link_path'], TRUE)) {
     form_set_error('link_path', t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $item['link_path'])));
   }
+  elseif (preg_match('/^node\/(\d+)/', trim($item['link_path']), $matches)) {
+    $type = db_query("SELECT type FROM {node} WHERE nid = :nid", array(':nid' => $matches[1]))->fetchField();
+    if ($type) {
+      $type_menus = variable_get('menu_options_'. $type, array('main-menu' => 'main-menu'));
+      list($menu_name, $plid) = explode(':', $item['parent']);
+      if (!in_array($menu_name, $type_menus)) {
+        form_set_error('parent', t("The %menu_title menu cannot contain links to the path '@link_path'.", array(
+          '%menu_title' => substr($form['parent']['#options'][$menu_name .':0'], 1, -1),
+          '@link_path' => $item['link_path'],
+        )));
+      }
+    }
+  }

Let me reiterate webchick's comment from another issue (#955848-23: When editing an existing node with a link, the link itself is listed in "Parent item": menu_parent_options needs some rewriting) -- I'm not sure this level of coupling between menu and node is going to fly.

Also, the usability of the patch needs some work.

While this seems better than the original behavior, I still think it would be more user-friendly for non-options not to appear in the parent select in the first place.

Also, the error message is totally obscure. "The Development menu cannot contain links to the path 'node/9'."

It would at least be a little more transparent if it read something like

The @menu_title menu cannot contains nodes of type @type.

Lastly, is this even a bug? As an admin, I might want to manually move certain pages to certain menus, but then not make it easy for a generic user to do so on the node form.

Powered by Dreditor.

anrikun’s picture

Status: Needs work » Closed (works as designed)

This no longer applies as latest 7.x behavior is now OK:
When editing a node that has a menu link in an unallowed menu, the "Menu settings" fiedset displays "Provide a menu link" as unchecked, thus hiding the menu link because it is in an unallowed menu.