Support » Plugin: Code Snippets » Safety of plugin?

  • The safety of this plugin has been called into question due to its use of eval(). As per http://php.net/manual/en/function.eval.php:

    The eval() language construct is very dangerous because it allows execution of arbitrary PHP code. Its use thus is discouraged. If you have carefully verified that there is no other option than to use this construct, pay special attention not to pass any user provided data into it without properly validating it beforehand.

    Could you weigh in on this?

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    Hi Andrew,

    My apologies for taking so long to get back to you.

    Essentially, from my understanding, eval() is considered dangerous because it allows the execution of non-file-based PHP code on a server, and this PHP code could contain errors which crash the site, or could do nasty things to the site that you don’t want to happen.

    The thing is, both of these factors are inescapable when you are adding custom code to a site, and are both present when you allow editing of the theme functions.php file, or the creation or modification of new plugins.

    The key thing in both situations is that you only allow people to write new code for your site that you trust – this is why access to the snippets interface is restricted to administrator users by default, and can be restricted further if necessary.

    I don’t think there is currently a better solution for executing snippet code on a site than using eval(). I have considered creating a feature that instead writes all snippet code to an external file for execution instead, but this poses its own issues, including the restrictive file writing permissions on many WordPress hosting servers, and still contains the dangers mentioned above.

    Still, I am always open for any suggestions on better ways to do the things that this plugin hopes to accomplish.

    Does this answer your question sufficiently?

    Thread Starter Andrew dela Serna

    (@druesome)

    Thank you for your thoughtful answer. That certainly helps clear things up! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Safety of plugin?’ is closed to new replies.