-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add a better injectModule method to WASM #1744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
03df1ea
to
997927a
Compare
Hmm, just realized that it would be possible to access the globals by doing e.g. |
Alright, I added the concept of "incognito" mode (though it's not an actual |
677940a
to
fef3792
Compare
Because I didn't look into non-vm part of this project that much, I am confused about this a little. To make it clear, this is a extension feature (mostly) for wasm, right? Basically, I don't like the idea that non-standard python feature slow down the standard features.
Note: Here "standard Python" means documented or CPython compatible. |
I think that would be a better way of separating the concerns, but it might also be cumbersome to have to define |
Also, w.r.t. "only used from the |
a023acc
to
a651729
Compare
@coolreader18 can you give us some numbers on the performance impact this change has? |
Alright, I had some trouble getting the benchmarks to work, but here's what I got: On master:
On this branch:
Basically very little difference; the difference between 2 benchmarks are within both the standard deviations given by the bencher. |
I agree that this is a very small decrease in performance. What do you think @youknowone? |
To make things clear, I am not asking changes or trying to decline this PR by these comments. This is just my general preferences. Before talking about performance, the performance itself doesn't justify the design. So this is a kind of negotiation of trade-off between performance and the implementation cost of the new feature. It seems having multiple whether incognito mode is included in rustpython core or wasm is a subtle issue for me. I think the feature itself need to live out of the core language. How about this? wasm support is one of the major feature of RustPython but perfectly living out of rustpython core world. So no matter whatever things happen in there. I think any non-standard feature can be added in this way of extension. We just can keep the core for the best compatibility. About the benchmark, the measured performance doesn't look meaningful. The benchmark should measure the cost of Still, if you guys think adding this feature in this way is better than other way, I think it is acceptable. Because usually I was concentrating on core features, I don't have any perspective of the big plans of the project. So I don't want to disturb to decide things we do out of the core language. |
That makes a lot of sense; I think your idea of separate |
@youknowone would you be okay with this getting merged? |
if everybody think this is the best for now, yes, I am okay |
@palaviv what do you think of this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. We should document this
Hi all, I looked into this change a bit, and I cannot say I agree with it. Python is insecure by design, you can modify all kind of things. In my opinion, adding an incognito mode adds extra code which tries to protect global variables, but as you mentioned elsewhere, you could still circumvent this by accessing the globals in another obscure way. I think it would be best to stick to CPython behavior, which is insecure by design. Making python properly secure can probably be harder than you imagine at first. I like the Please do not be offended by this feedback, but this is my view on the project. |
Would you be opposed to any attempt to sandbox RustPython? What about a wasm-only builtin module that has a function to wrap a callable into an opaque object? @opaque_callable
def a(): pass I think we do need some solution for sandboxing, since a lot of use cases for embedding a scripting language into a program involves running arbitrary code, and I think RustPython's self-contained nature lends itself well to embedding. |
I'm not opposed to sandboxing rustpython as a whole. This is already possible by compiling rustpython as a wasm module, and by using the wasm import / export machinery to very tightly control what can be accessed by rustpython. In that sense, the sandboxing would take place by limiting the exposed modules, such as sys, os and the file and socket API's. Maybe we could add feature flags to choose which parts of the standard library you want to use? My rationale is that we do not require any specific sandboxing features inside rustpython itself. Just treat all python scripts executing in rustpython as one big interconnected mass. If you want to isolate some of your python code, since it is safety related, the I would propose to fire up two rustpython VM's and link them using queues, or another interface. In this sense, you would have two isolated rustpython VM's. One with a few privileges, and a limited API to the second VM. The second VM would than contain the secure code, and have more access. On top off that I think python is insecure by it's nature, which is also what makes it a great tinkering tool, so I think we should stick to that, and not try to build protection features in. Another reason for not wanting the protection features, is that it might sound like it's secure, but still there are loopholes to bypass this security. In this case it is better to have no security than apparent security. I agree that rustpython lends itself very well for embedding, and I would like to keep this feature. |
c065929
to
064187f
Compare
064187f
to
ba50927
Compare
ba50927
to
6afdfdc
Compare
6afdfdc
to
a8027ab
Compare
I'm merging this now, since it's basically just the |
This allows for strict privacy for WASM modules, which is important in an environment like the browser, where most of the time you're running code on someone else's computer. The idea for this method would be to write a wrapper module around some possibly security-sensitive functions that you pass from js, and then allow arbitrary code to access that module. For robot rumble (the successor to codingworkshops, the code learning platform), it might be used like:
We don't want user code arbitrarily calling the
runRobot
function, so we wrap it in a module that makes sure that it can't, and also (ideally) provides a nicer, more pythonic interface. Thestrict_private
parameter enables that; it runs the source code provided in one namespace with the JS imports, and copies only the items exported in__all__
to a new namespace that is injected intosys.modules
.