I think a hook_menu_alter to just set access to FALSE would be a good solution. That way there can be a hook that lists pages to disable.

Views is the most obvious example of this feature. What else exists?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

greggles’s picture

Status: Active » Needs review
FileSize
1.44 KB

OK, here's a proof of concept that works on the views form.

greggles’s picture

Title: block all "import foo" boxes that use php » block all "import foo" boxes that use php arrays as a data structure

Better title.

greggles’s picture

Title: block all "import foo" boxes that use php arrays as a data structure » block some "import foo" boxes that use php arrays as a data structure
Status: Needs review » Fixed

  • greggles committed 4ba0f2d on 7.x-1.x
    Issue #2313945 by greggles: block all "import foo" boxes that use php...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

John Bickar’s picture

What else exists?

  • auto_nodetitle
  • backup_migrate
  • bundle_copy
  • computed_field
  • context
  • css_injector
  • custom_breadcrumbs
  • delta
  • devel (natch)
  • draggableviews
  • feeds_ui
  • flag
  • js_injector
  • jw_player
  • openlayers
  • relation_ui
  • services
  • views_bulk_operations
  • Anything that implements ctools_export_ui_form can enter PHP

Note that many of these implement their own permissions and bypass the core PHP permission.

We will look into providing a patch for the specific form fields, but it will be a couple of weeks due to the holidays.

greggles’s picture

Thanks for documenting them and

We will look into providing a patch for the specific form fields

I hope you can make time for it - would be very much appreciated!

John Bickar’s picture

This patch hits a few of them. I can't change the issue status.

greggles’s picture

Status: Closed (fixed) » Needs review

@John Bickar - when the issue is closed for a while then only a project member can reopen it. Thanks for the patch! I'll try to review soon :)

The last submitted patch, 1: 2313945_avoid_import_php_forms.patch, failed testing. View results

John Bickar’s picture

Some of the modules identified use generic forms that can't be blocked (e.g., node_type_form). But this should get a few more forms and one PHP permission.

John Bickar’s picture

VBO's "chainsaw mode" can be disabled with this in a hook_form_alter():

  if ($form_id == "views_ui_config_item_form") {
    unset ($form['options']['vbo_operations']['action::views_bulk_operations_script_action']);
  }

I can add that to the patch as well.

greggles’s picture

The patch as is looks good to me. Adding #12 seems good - though I wonder what chainsaw mode is? Thanks.

John Bickar’s picture

FileSize
91.85 KB

"Execute arbitrary PHP script", AKA, "chainsaw mode" :)

greggles’s picture

Status: Needs review » Needs work

I like your nickname for it :) I have yet to hurt myself with a chainsaw, but the temptation to risk is strong!

Moving to needs work for that bit.

John Bickar’s picture

Status: Needs work » Needs review
FileSize
2.6 KB

Go testbot...

John Bickar’s picture

John Bickar’s picture

Oh, I see. In the current paranoia_form_views_ui_config_item_form_alter(), the conditional is too restrictive.

if ($form['#section'] == 'page-field-views_bulk_operations') doesn't evaluate to TRUE on every VBO (for example on admin_views_user). The approach that I took in the patch is a much bigger hammer.

John Bickar’s picture

Assigned: Unassigned » John Bickar
Status: Needs review » Needs work
John Bickar’s picture

Status: Needs work » Needs review
FileSize
3.77 KB

Posting WIP so it doesn't get lost.

John Bickar’s picture

John Bickar’s picture

OK, I think this is ready for review.

The attached patch does the following:

  1. Disallows the "Computed Field" module
  2. Blocks the permission to use PHP in Custom Breadcrumbs
  3. Changes the message "This form is disabled for security reasons..." to pull from a variable in the DB (so that it's configurable)
  4. Blocks VBO's "chainsaw mode"
  5. Removes the earlier attempt to block VBO's "chainsaw mode" via hook_form_FORM_ID_alter()
  6. Blocks Automatic Nodetitles's "Evaluate PHP in pattern" setting.
  7. Removes the PHP field from the Custom Breadcrumbs form (belt and suspenders)
  8. Blocks the Backup and Migrate import form
  9. Blocks the Bundle Copy import form
  10. Blocks forms that implement ctools_export_ui_edit_item_wizard_form (e.g., Context, Delta, JS Injector, JW Player, OpenLayers, Services)
  11. Blocks the Feeds UI import form
  12. Blocks the Flag import form
  13. Blocks the Page Manager import form
  14. Blocks the Relation import form
  15. Blocks the Rules import form
  16. Blocks the Views import form
John Bickar’s picture

Status: Needs review » Needs work

Hm. The modules listed in paranoia_paranoia_disable_modules() also need to be added in paranoia_paranoia_hide_modules(), otherwise a user can enable them.

John Bickar’s picture

Assigned: John Bickar » Unassigned
Status: Needs work » Needs review
FileSize
5.91 KB

OK let's try this.

cashwilliams’s picture

I like the direction of this patch. I reviewed the list of modules suggested from #6 and see the few I couldn't confirm were executing PHP (such as openlayers) are not included in this patch.

Additionally I like the idea of disabling the field or form in a few places rather then just blacklisting the entire module from being enabled.

I've skimmed the patch but not had a chance to fully review or test.

John Bickar’s picture

Blocking ctools_export_ui_edit_item_wizard_form takes care of PHP entry in Context, Delta, JS Injector, JW Player, OpenLayers, Services (they all have Import forms).

This issue is conflated a bit with #2059963 but it does not hit everything listed in comment #12 in that issue.

John Bickar’s picture

@Cash, here is an install profile that contains all the modules. Run drush make Stanford-Drupal-Profile/make/group.make --force-complete to build it.

Here is a Behat Feature that verifies the changes proposed in this patch.

John Bickar’s picture

The new patch does everything stated in #22, plus it blocks the permission to "restore from backup" (Backup and Migrate).

John Bickar’s picture

The attached patch does the following:

  1. Disallows the "Computed Field" module
  2. Blocks the permission to use PHP in Custom Breadcrumbs
  3. Changes the message "This form is disabled for security reasons..." to pull from a variable in the DB (so that it's configurable)
  4. Blocks VBO's "chainsaw mode"
  5. Removes the earlier attempt to block VBO's "chainsaw mode" via hook_form_FORM_ID_alter()
  6. Blocks Automatic Nodetitles's "Evaluate PHP in pattern" setting.
  7. Removes the PHP field from the Custom Breadcrumbs form (belt and suspenders)
  8. Blocks the Backup and Migrate import form
  9. Blocks the Bundle Copy import form
  10. Blocks forms that implement ctools_export_ui_edit_item_wizard_form (e.g., Context, Delta, JS Injector, JW Player, OpenLayers, Services)
  11. Blocks the Feeds UI import form
  12. Blocks the Flag import form
  13. Blocks the Page Manager import form
  14. Blocks the Relation import form
  15. Blocks the Rules import form
  16. Blocks the Views import form
  17. NEW: Blocks the Backup and Migrate restore permission
  18. NEW: Blocks the Backup and Migrate restore form

Status: Needs review » Needs work

The last submitted patch, 30: paranoia-block_additional_forms-2313945-30.patch, failed testing. View results

John Bickar’s picture

Status: Needs work » Needs review
FileSize
6.57 KB

Reroll.

jmoreira’s picture

Tested the functionalities mentioned in the patch and almost everything works except the bit with auto_nodetitle: I can still "Evaluate PHP in pattern." with user 1 because auto_nodetitle weight is set to 5 so Paranoia’s form_alter is overridden. It works fine with any other users (even admins), because auto_nodetitle sets #access based on the permission to use php which is hidden by paranoia but user 1 has all permissions by default. I'm not sure what the best fix would be here (just changing Paranoia's weight seem a bit hacky and dangerous?).

I'm also re-submitting the patch without the use of t with variable_get (see documentation here and here for more details).

John Bickar’s picture

@jmoreira, thanks! (I always get the usage of t() wrong in variable_get().

I think the question of setting Paranoia's weight is a decision for the module maintainers. I would argue in favor of it, as the entire premise of the module is to be "heavy-handed".

John Bickar’s picture

Status: Needs review » Reviewed & tested by the community

I have tested @jmoreira's patch with this suite of Behat tests. It's not a complete suite for the entire functionality of the Paranoia module, but it covers most of the functionality introduced in the patch.

greggles’s picture

Thanks for all the work and reviews on this!

Regarding weights and a solution for auto_nodetitle - I wonder if paranaoia could just set that whole form to #access = FALSE for uid = 1? That's a bit of a blunt solution, but it would get the point across not to use uid 1 :) Something like that seems like it could/should be a followup, though.

  • greggles committed bf32bea on 7.x-1.x authored by John Bickar
    Issue #2313945 by John Bickar, greggles, jmoreira: block some "import...
greggles’s picture

Status: Reviewed & tested by the community » Fixed

I think the module space has changed enough that this shouldn't be "ported" to the Drupal 8 version of the module, so I'm going to mark it as fixed. Thanks!

John Bickar’s picture

Thanks @greggles!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.