Comments (8)
Sandboxing coming to the web 😮 (safe eval
). Already at stage 3.
https://github.com/tc39/proposal-shadowrealm
from pixiebrix-extension.
I think you're suggesting to run that code in the sandbox
in Chrome and as a userScript
in Firefox. I'll look into how these two can be commanded through the same interface, but it's possible that we might need/want to stabilize our messaging API first.
Related: #430
There are a couple of things that will make a little awkward:
- userScripts need to be registered via background page, but they will run on the current page (thankfully there's an event that we receive in the content script, in which we can provide the messaging API)
- the sandbox needs to be loaded via iframe, it seems, hopefully that won't be a problem on sites with strict CSP. If it is, we might have to run it in the background page itself, adding an extra messaging step (and it isn't possible in MV3 #287)
from pixiebrix-extension.
I'm not yet familiar with the capabilities of bricks, but the sandbox won't have access to the webpage at all (unlike the user scripts), would that be a problem? Would it require bricks to run in 2 places at once?
Given that TamperMonkey is already able to inject user scripts, I wonder if I can make a browser.userScript.register
polyfill of sorts in order to avoid the wildly-different sandbox/userScript APIs.
Edit: From a quick look, it appears that TamperMonkey injects the user script with a plain script
, so that's not enough.
Related links with possibly more details/context:
Scripting in chrome, especially in MV3: https://groups.google.com/a/chromium.org/g/chromium-extensions/c/q9H8KwFLkMs
SO question with links related to communication between user scripts and content scripts:
https://stackoverflow.com/questions/63814566/can-my-tampermonkey-script-or-other-userscript-call-my-chrome-extension
from pixiebrix-extension.
Thanks for starting to look into this! This issue isn't urgent, as we're still in a world where people are creating for themselves or running bricks made by their company's development team.
I need to write up a wiki page on formally detailing the threat/security model so we can determine best way to leverage sandbox. The main potential attack vectors from a malicious brick creator would be:
- Prototype pollution
- XSS
- Data exfiltration
- Privilege escalation (e.g., by someone running methods on background page, or in the site's JS context)
For each, the surface area pretty well-defined because we don't support arbitrary JS in bricks. Therefore, each brick/class of brick can have its own mitigation mechanisms. For example, the markdown brick runs DOMPurify.sanitize
on the resulting html.
When I originally wrote this issue, the implementation sketch I had in mind for initial sandboxing was:
- Run all calls to
mapArgs
in the sandbox worker (because it can run Nunjucks/handlebars templates) - Modify the
@pixiebrix/jq
brick to run jq in the sandbox worker - Double-check whether mustache is actually logic-less, and if not, also make sure all calls the
Mustache.render
are run via the sandbox worker. If we're just worried about prototype pollution on this one, we might be able to get away withObject.freeze
These don't require access to the page or network connection, as they're just transforming data.
On iframe and MV3:
- The iframe issue we could get around the same way we do for other iframes, by doing two layers. (The sub-iframe is subject to the CSP we define.)
- The Google team will be providing some way to allow userscripts in the MV3 world, but the API hasn't been announced yet: Tampermonkey/tampermonkey#644 (comment)
from pixiebrix-extension.
You mentioned this in the other issue but I want to clarify here: Do you intend to use the sandbox only in Chrome for now? And then allow the code to run locally in Firefox?
from pixiebrix-extension.
And then allow the code to run locally in Firefox?
I think we have to, as I'm not sure Firefox has a sufficient analog. (It has a UserScripts API, but IIRC that isn't a good fit for this granular of call)
from pixiebrix-extension.
My understanding is that you want to only bring the execution of specific parts of the bricks to the sandbox, for example:
- Create sandbox
- Request "compute this nunjuck template"
- Sandbox responds with serializable result
- Sandbox is shut down
If so, we'll have to create a sandbox.js bundle with just the specific handlers, rather than moving the whole engine there.
Can you list these sandboxable bricks so we can move this ticket forward?
from pixiebrix-extension.
My understanding is that you want to only bring the execution of specific parts of the bricks to the sandbox
Correct, the things that need to be moved to sandbox are:
- Template evaluation as part of runtime argument passing
- Brick execution: JQ, and see below
- RJSF Form Validation
For a POC of this ticket, I think we should modify engineRenderer to use the sandbox under the hood. This will allow us to see what the impact on brick execution speed.
Can you list these sandboxable bricks so we can move this ticket forward?
Runtime:
- engineRenderer should return method that uses Sandbox under the hood
- Templates for service authentication currently use mustache, so we would not need to move it to the sandbox
Bricks:
from pixiebrix-extension.
Related Issues (20)
- Map to AA Copilot brick not working on AA homepage HOT 1
- Add edit and delete mod affordances to Mods Screen
- [Spike] Page Editor: affordance to add component directly to existing mod
- NPE in Page Editor when trying to edit starter brick
- NPE in sidebar activation code
- Include url prop in rum error detail telemetry
- Can't create a database from the Page Editor "Mod Input Options" form
- Buttons not appearing unless Page Editor is open
- Mod Input Form builder shows paragraph fields that are not applicable in mod options context
- Page Editor Save: Invariant check caught multiple mod components with the same extensionPointIds
- Rename document builder branch -> subtree
- Default availability to all sites for manually invoked starter bricks
- Include service worker logs / network requests in playwright trace.
- Rename remaining instances of "recipe" in the Page Editor HOT 2
- Unable to launch AA OAuth2 flow
- Add tests for `codeGrantFlow` and `implicitGrantFlow`
- Introduce `Kinds` constant
- Slice 1: Show create-mod modal on save of standalone mod components
- Slice 2: Change copy on the create mod modal
- Slice 3: Remove dead code for saving standalone mod components
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pixiebrix-extension.