Problem/Motivation
If the output of the code executed on what a user submits on the devel/php form is html, for example when making a curl request to a site, then the html is currently rendered by the browser, which is not only an inconvenience, but could result in malicious JS being executed, etc.
Example:
$curl = curl_init('https://google.com');
$result = curl_exec($curl);
print($result);
curl_close($curl);
Proposed resolution
Provide a checkbox to allow the user to optionally escape all output.
Remaining tasks
Do it.
User interface changes
New checkbox on the devel/php form.
API changes
None.
Data model changes
None.
Comments
Comment #2
manuel garcia commentedKindly review :)
Comment #3
salvisI see your point, but making such a change may make people unhappy who have been fine with the current behavior for many years. Personally, I can't remember ever outputting HTML, but you can do it if you try hard enough, of course.
I could see having a persistent "Escape HTML output" checkbox on the devel/php page that would let you choose which way to go. This would at the same time alert users to the potential risk. The initial state (default) should be OFF, as it is now.
Comment #4
manuel garcia commentedThanks @salvis for taking the time to have a look at this. I agree this would be better if it was optional, doing so in this patch.
You can check the difference that having the checkbox on or off makes using this example:
Checkbox off:

Checkbox on:

Another place where security isn’t a concern but it would still be useful is when using Drupal's HTTP client. If you execute this for example:
I've included a description on the checkbox but not very convinced about it, please let me know what you think :)
Comment #5
manuel garcia commentedComment #6
salvisVery nice, thank you for the good illustrations!
Maybe it would be easier to understand if we invert the checkbox, something like
Originally, I leaned towards making it completely persistent, in order to preserve the current behavior as much as possible, but now I start to think we could turn escaping on whenever we initially show the form, and just preserve the state across executions.
Producing and wanting to see interpreted HTML is probably quite rare, and it typically makes more sense to see the HTML. Getting it rendered would just be a matter of activating the checkbox and hitting [Execute] again, after you've seen what it produces. This would also make the behavior more predictable, especially if more than one person is using it.
Alternatively, we could just have a second button, like [Execute and render]...
What do you and others think?
Comment #7
manuel garcia commentedI am a bit puzzled by why when using curl the HTML is not escaped by
drupal_set_message()to be honest. This seems to be the only situation where this happens:1. If you do just
return '<bold>test</bold>';, what gets printed is only<pre>bold</pre>.2. If you do the following the output is actually empty, unless you use the checkbox:
3. However if you use the curl code in the description:
Then the output is actually rendered html, unless you use the checkbox.
So as it stands right now, having the checkbox say Allow interpreting HTML could be misleading. No matter if the checkbox is on or not, we're actually not interpreting HTML in nearly all situations (except when using curl apparently).
Therefore giving the option to display escaped html instead would make sense in my opinion. Say have the checkbox read Display escaped HTML output, or Escape HTML output?
Comment #8
moshe weitzman commented[#3005475: Remove Execute PHP feature]
Comment #9
geek-merlinCode moved due to #3005475-15: Remove Execute PHP feature.
Comment #10
grimreaperComment #11
grimreaperHi,
Closing as there was no activity on this issue for years.
If someone still needs it, feel free to re-open and use a fork and MR instead of patch.