(Unneccessarily) restricted execution in scripted expression drivers (using e.g. "self", "bpy.data") #106372

Open
opened 2023-03-31 12:15:42 +02:00 by John Sinyard · 11 comments

System Information
Operating system: Linux-5.15.0-69-generic-x86_64-with-glibc2.35 64 Bits
Graphics card: Mesa Intel(R) HD Graphics 4600 (HSW GT2) Intel 4.6 (Core Profile) Mesa 22.2.5

Blender Version
Broken: version: 3.5.0, branch: blender-v3.5-release, commit date: 2023-03-29 02:56, hash: 1be25cfff18b
Worked: (newest version of Blender that worked as expected)

Short description of error
self causes error in scripted expression drivers

Exact steps for others to reproduce the error
In scripted expression drivers using expression "self.location.x" from Blenders manual and "self.location[0]" from online examples both fail with "ERROR: Invalid Pythpn expression".
I have enabled "Use Self" in driver and "Auto Run Python Scripts" in preferences

**System Information** Operating system: Linux-5.15.0-69-generic-x86_64-with-glibc2.35 64 Bits Graphics card: Mesa Intel(R) HD Graphics 4600 (HSW GT2) Intel 4.6 (Core Profile) Mesa 22.2.5 **Blender Version** Broken: version: 3.5.0, branch: blender-v3.5-release, commit date: 2023-03-29 02:56, hash: `1be25cfff18b` Worked: (newest version of Blender that worked as expected) **Short description of error** self causes error in scripted expression drivers **Exact steps for others to reproduce the error** In scripted expression drivers using expression "self.location.x" from Blenders manual and "self.location[0]" from online examples both fail with "ERROR: Invalid Pythpn expression". I have enabled "Use Self" in driver and "Auto Run Python Scripts" in preferences
John Sinyard added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2023-03-31 12:15:42 +02:00
Iliya Katushenock added the
Interest
Animation & Rigging
Interest
Python API
labels 2023-03-31 12:41:33 +02:00
Member

Hi, thanks for the report. Enabling "auto execution" does fix the problem.
This error shows up because PyObject name is not found in the dictionary.
Not sure whether this is a bug or expected behavior. Forwarding to devs

Hi, thanks for the report. Enabling "auto execution" does fix the problem. This error shows up because PyObject name is not found in the dictionary. Not sure whether this is a bug or expected behavior. Forwarding to devs
Author

Do you mean "auto execution" is the same as "Auto Run Python Scripts" in "Save & Load" in Preferences?

If so then it does not fix the problem for me

Do you mean "auto execution" is the same as "Auto Run Python Scripts" in "Save & Load" in Preferences? If so then it does not fix the problem for me

I cannot reproduce this issue. Please attach an example blend file.

Counter-example: here's a bone that has a driver to make it rotate when you move it in the X-direction. It uses self.location.x as the Python expression: 106372-self-in-drivers.blend

image

I cannot reproduce this issue. Please attach an example blend file. Counter-example: here's a bone that has a driver to make it rotate when you move it in the X-direction. It uses `self.location.x` as the Python expression: [106372-self-in-drivers.blend](/attachments/5c66d356-064b-495d-bccb-2e0fee7cc8ba) ![image](/attachments/910c8b4a-3789-405b-85af-eefbc78d8cfe)
Sybren A. Stüvel added
Status
Needs Information from User
and removed
Status
Needs Info from Developers
labels 2023-05-19 15:01:33 +02:00
Member

@dr.sybren , same error in your file too.
Guess "auto run python script" is enabled in your case (disable it and see if that reports the error)
Also uploaded a new test file.
image

@dr.sybren , same error in your file too. Guess "auto run python script" is enabled in your case (disable it and see if that reports the error) Also uploaded a new test file. ![image](/attachments/4eadd069-9f54-4d7d-9ae9-771e44ae0c50)
Member

resetting the status until @dr.sybren confirm this ;)

resetting the status until @dr.sybren confirm this ;)
Pratik Borhade added
Status
Needs Triage
and removed
Status
Needs Information from User
labels 2023-05-25 07:05:24 +02:00

Nope, this is with auto-execute disabled. I'm simply not seeing that error. At least not on current main, 35ca8bd80f352de4a8169756d4481c5765b1b91a

Nope, this is with auto-execute disabled. I'm simply not seeing that error. At least not on current `main`, `35ca8bd80f352de4a8169756d4481c5765b1b91a`
Iliya Katushenock removed the
Module
Animation & Rigging
label 2023-06-21 15:14:26 +02:00
Member

I can see that warning as well as well opening the files

image

If I choose Ignore instead of Allow Execution, the mentioned error ("Invalid python expression") stays.

Also seeing this in the console:
BPY_driver_exec: restricted access disallows name 'location', enable auto-execution to support

This is true btw. not only when using self, you could also use something like bpy.data.objects["Light"].location[0] and get the same security mechanism kick in [the system to whitelist only a couple of terms was set up in 2ceff8bd63 btw.]
Isnt this all expected behavior then?

Now the question is : should we add a whole lot more to the whitelist?
Why would something in bpy.data for example be a security issue? I dont know.
(and same for self, yes).

Codewise, this is working as intended (so not neccessarily a bug), would still be nice to hear opinions from @dr.sybren , @ideasman42 .

I can see that warning as well as well opening the files ![image](/attachments/294316e5-462e-4bf6-8424-8c7a81976c47) If I choose `Ignore` instead of `Allow Execution`, the mentioned error ("Invalid python expression") stays. Also seeing this in the console: `BPY_driver_exec: restricted access disallows name 'location', enable auto-execution to support` This is true btw. not only when using `self`, you could also use something like `bpy.data.objects["Light"].location[0]` and get the same security mechanism kick in [the system to whitelist only a couple of terms was set up in 2ceff8bd6325 btw.] Isnt this all expected behavior then? Now the question is : should we add a whole lot more to the whitelist? Why would something in `bpy.data` for example be a security issue? I dont know. (and same for `self`, yes). Codewise, this is working as intended (so not neccessarily a bug), would still be nice to hear opinions from @dr.sybren , @ideasman42 .
Philipp Oeser changed title from self causes error in scripted expression drivers to (Unneccessarily) restricted execution in scripted expression drivers (using e.g. "self", "bpy.data") 2023-06-23 12:48:36 +02:00

I can see that warning as well as well opening the files

image

So this doesn't say "Invalid python expression".

If I choose Ignore instead of Allow Execution, the mentioned error ("Invalid python expression") stays.

I still have never seen that "Invalid python expression" message. Also it makes sense that the Python expression is not working properly when Python execution has been denied.

Also seeing this in the console:
BPY_driver_exec: restricted access disallows name 'location', enable auto-execution to support

That is still expected, when there are drivers that require Python but the user did not allow Python.

Now the question is : should we add a whole lot more to the whitelist?
Why would something in bpy.data for example be a security issue? I dont know.

That would allow things like D.texts['Text'].as_module(), i.e. running arbitrary text blocks in the same blend file.

(and same for self, yes).

I think self might be better suited to be allowed, but then again most properties of self can already be put into a variable. Just because it's possible to use self.location.x in a driver expression doesn't mean that you should. Using proper driver variables makes the depsgraph understand which properties are being accessed & influenced; without that, it's very simple to create buggy blend files.

> I can see that warning as well as well opening the files > > ![image](/attachments/294316e5-462e-4bf6-8424-8c7a81976c47) So this doesn't say "Invalid python expression". > If I choose `Ignore` instead of `Allow Execution`, the mentioned error ("Invalid python expression") stays. I still have never seen that "Invalid python expression" message. Also it makes sense that the Python expression is not working properly when Python execution has been denied. > Also seeing this in the console: > `BPY_driver_exec: restricted access disallows name 'location', enable auto-execution to support` That is still expected, when there are drivers that require Python but the user did not allow Python. > Now the question is : should we add a whole lot more to the whitelist? > Why would something in `bpy.data` for example be a security issue? I dont know. That would allow things like `D.texts['Text'].as_module()`, i.e. running arbitrary text blocks in the same blend file. > (and same for `self`, yes). I think `self` might be better suited to be allowed, but then again most properties of `self` can already be put into a variable. Just because it's possible to use `self.location.x` in a driver expression doesn't mean that you should. Using proper driver variables makes the depsgraph understand which properties are being accessed & influenced; without that, it's very simple to create buggy blend files.
Member

I can see that warning as well as well opening the files

image

So this doesn't say "Invalid python expression".

Yes, it does
image

> > I can see that warning as well as well opening the files > > > > ![image](/attachments/294316e5-462e-4bf6-8424-8c7a81976c47) > > So this doesn't say "Invalid python expression". Yes, it does ![image](/attachments/5a8eb800-d8e9-445f-bb68-29eb4869943e)
Member

we could simply do this (swap the order of error messages)



diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index 243b09583e6..3f90110dae7 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -1056,10 +1056,7 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
     col = uiLayoutColumn(layout, true);
     block = uiLayoutGetBlock(col);
 
-    if (driver->flag & DRIVER_FLAG_INVALID) {
-      uiItemL(col, TIP_("ERROR: Invalid Python expression"), ICON_CANCEL);
-    }
-    else if (!BKE_driver_has_simple_expression(driver)) {
+    if (!BKE_driver_has_simple_expression(driver)) {
       if ((G.f & G_FLAG_SCRIPT_AUTOEXEC) == 0) {
         /* TODO: Add button to enable? */
         uiItemL(col, TIP_("Python restricted for security"), ICON_ERROR);
@@ -1068,6 +1065,9 @@ static void graph_draw_driver_settings_panel(uiLayout *layout,
         uiItemL(col, TIP_("Slow Python expression"), ICON_INFO);
       }
     }
+    else if (driver->flag & DRIVER_FLAG_INVALID) {
+      uiItemL(col, TIP_("ERROR: Invalid Python expression"), ICON_CANCEL);
+    }
 
     /* Explicit bpy-references are evil. Warn about these to prevent errors */
     /* TODO: put these in a box? */

which would give us this [which is probably clearer?]:
image

we could simply do this (swap the order of error messages) ```Diff diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c index 243b09583e6..3f90110dae7 100644 --- a/source/blender/editors/space_graph/graph_buttons.c +++ b/source/blender/editors/space_graph/graph_buttons.c @@ -1056,10 +1056,7 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, col = uiLayoutColumn(layout, true); block = uiLayoutGetBlock(col); - if (driver->flag & DRIVER_FLAG_INVALID) { - uiItemL(col, TIP_("ERROR: Invalid Python expression"), ICON_CANCEL); - } - else if (!BKE_driver_has_simple_expression(driver)) { + if (!BKE_driver_has_simple_expression(driver)) { if ((G.f & G_FLAG_SCRIPT_AUTOEXEC) == 0) { /* TODO: Add button to enable? */ uiItemL(col, TIP_("Python restricted for security"), ICON_ERROR); @@ -1068,6 +1065,9 @@ static void graph_draw_driver_settings_panel(uiLayout *layout, uiItemL(col, TIP_("Slow Python expression"), ICON_INFO); } } + else if (driver->flag & DRIVER_FLAG_INVALID) { + uiItemL(col, TIP_("ERROR: Invalid Python expression"), ICON_CANCEL); + } /* Explicit bpy-references are evil. Warn about these to prevent errors */ /* TODO: put these in a box? */ ``` which would give us this [which is probably clearer?]: ![image](/attachments/dc7904a5-d0be-43d6-912a-13a833918b4c)

Ah, right. Yes, that looks like a rather sensible improvement to me!

Ah, right. Yes, that looks like a rather sensible improvement to me!
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#106372
No description provided.