Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(webview): keep mixed-content blocking for http in Linux webviews

rokartur7f28b74a232f
diff --git a/native/crates/app/src/webview/linux.rs b/native/crates/app/src/webview/linux.rs
index 40597882e89..031b72829d4 100644
--- a/native/crates/app/src/webview/linux.rs
+++ b/native/crates/app/src/webview/linux.rs
@@ -29,7 +29,7 @@ use raw_window_handle::{HasWindowHandle, RawWindowHandle};
use serde_json::{Value, json};
pub use std::rc::Rc as Retained;
use webkit2gtk::{
- NetworkProxyMode, NetworkProxySettings, SecurityManagerExt, SettingsExt, UserContentInjectedFrames, UserContentManager, UserContentManagerExt, UserScript, UserScriptInjectionTime, WebContext, WebContextExt, WebInspectorExt,
+ NetworkProxyMode, NetworkProxySettings, SettingsExt, UserContentInjectedFrames, UserContentManager, UserContentManagerExt, UserScript, UserScriptInjectionTime, WebContext, WebContextExt, WebInspectorExt,
WebViewExt, WebsiteDataManagerExt,
};
use x11::xlib;
@@ -96,9 +96,6 @@ impl Webview {
let mut settings = NetworkProxySettings::new(None, &[]);
settings.add_proxy_for_scheme("https", &format!("http://127.0.0.1:{port}"));
context.website_data_manager().expect("a context has a data manager").set_network_proxy_settings(NetworkProxyMode::Custom, Some(&mut settings));
- // WebKit blocks an http frame in the https host page as mixed content, loopback included, where Chromium lets
- // http://localhost load (the Simple Browser's dev servers).
- context.security_manager().expect("a context has a security manager").register_uri_scheme_as_secure("http");
let content = UserContentManager::new();
content.register_script_message_handler(MESSAGE_HANDLER);
diff --git a/port/fixtures/extensions/webview-tests/tests/index.js b/port/fixtures/extensions/webview-tests/tests/index.js
index 37a672b18be..b468d361c69 100644
--- a/port/fixtures/extensions/webview-tests/tests/index.js
+++ b/port/fixtures/extensions/webview-tests/tests/index.js
@@ -1,6 +1,7 @@
// Webview checks run in code-gpui by port/tools/webview-check. The panel tests are the ones upstream removed from
// extensions/vscode-api-tests/src/singlefolder-tests/webview.test.ts in c5f857f0cf0 (skipped there as flaky in CI).
const assert = require('assert');
+const http = require('http');
const vscode = require('vscode');
const disposables = [];
@@ -188,8 +189,41 @@ const checks = {
</script>`);
assert.deepStrictEqual(await response, { inside: 'inside', outside: 'denied' });
},
+ // Chromium lets an https page load http from loopback only (the Simple Browser's dev servers); any other http
+ // script is blocked mixed content.
+ async 'webviews should block http scripts from the network'() {
+ // An offline run would see the script blocked either way.
+ const online = await new Promise(resolve => http.get('http://example.com/', response => resolve(response.statusCode === 200)).on('error', () => resolve(false)));
+ assert.ok(online, 'http://example.com/ is reachable');
+ assert.strictEqual(await loadScript('http://example.com/'), 'blocked');
+ },
+ async 'webviews should load http scripts from loopback'() {
+ const server = http.createServer((request, response) => {
+ response.writeHead(200, { 'Content-Type': 'text/javascript' });
+ response.end('');
+ });
+ await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
+ register({ dispose: () => server.close() });
+ assert.strictEqual(await loadScript(`http://127.0.0.1:${server.address().port}/`), 'loaded');
+ },
};
+// Ledger rows `M23 Linux`: what the Linux build lacks, printed as `gap` and not counted as failed.
+const linuxGaps = ['webviews should load http scripts from loopback'];
+
+/** Whether a webview page's `<script src>` loaded, was blocked, or is still pending after 5 s. */
+async function loadScript(src) {
+ const webview = createPanel({ enableScripts: true });
+ const response = getMessage(webview);
+ webview.webview.html = html(`
+ <script>
+ const vscode = acquireVsCodeApi();
+ setTimeout(() => vscode.postMessage('pending'), 5000);
+ </script>
+ <script src="${src}" onload="vscode.postMessage('loaded')" onerror="vscode.postMessage('blocked')"></script>`);
+ return response;
+}
+
exports.run = async () => {
const only = process.env.PORT_WEBVIEW_GREP;
let failed = 0;
@@ -201,8 +235,9 @@ exports.run = async () => {
await Promise.race([check(), new Promise((_, reject) => setTimeout(() => reject(new Error('timed out after 10 s')), 10000))]);
console.log(`ok ${name}`);
} catch (error) {
- failed++;
- console.log(`FAILED ${name}: ${error.message}`);
+ const gap = process.platform === 'linux' && linuxGaps.includes(name);
+ failed += gap ? 0 : 1;
+ console.log(`${gap ? 'gap' : 'FAILED'} ${name}: ${error.message}`);
}
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
disposables.splice(0).forEach(disposable => disposable.dispose());
diff --git a/port/ledger.md b/port/ledger.md
index e5a8c539cfd..accb61d826d 100644
--- a/port/ledger.md
+++ b/port/ledger.md
@@ -41,8 +41,9 @@ Status: `open`, `in progress`, `waiting on Artur`, `later` (postponed), `done`,
| Milestones | M23 Linux build | in progress | Branch `port-linux` (a Linux build container on the Studio). The app is macOS-only today: 24 files of `native/crates` call AppKit, Foundation, WebKit, Security or Core Foundation directly (objc2, core-foundation, security-framework); GPUI (`native/vendor/wu`) already has its Linux platform (Wayland and X11). Every macOS call goes behind `cfg(target_os = "macos")` with the Linux counterpart VS Code uses there, in the same function where the two are a few lines, in a `platform/linux.rs` beside a `platform/macos.rs` where they are not: webview (WebKitGTK through wry), file dialogs (xdg-desktop-portal, rfd), the application menu (drawn in the window: `window.titleBarStyle`, `window.menuBarVisibility`), clipboard and the find pasteboard (GPUI's), proxy (`http.proxy` and the system proxy via reqwest instead of NSURLSession), secrets (Secret Service, keyring), `code` CLI install (`~/.local/bin`), file watching (inotify, notify), the updater (a download link, as `update.mode` on a tar.gz), and the settings import paths (`~/.config/Code`, `~/.config/Cursor`, `~/.config/VSCodium`). Packaging: `port/tools/package-linux` writes `VSRustium-<version>-linux-<arch>.tar.gz` and the `linux-<arch>.json` and `linux-<arch>-prerelease.json` feed entries (port/notes.md milestone 23); deb and AppImage after it. Builds in a Linux container on the Studio (`docker`, linux/arm64) for the build and the unit tests; linux-x64 on a GitHub Actions `ubuntu` runner once arm64 is green. | `cargo build --release -p app` and the area tests pass on Linux arm64 and x64; the app opens a folder, edits, saves, runs an extension (the exthost handshake, emmet and git activate) and shows a webview under Xvfb or Wayland in the container; `v1.147.0-insider` carries `VSRustium-1.147.0-insider-linux-arm64.tar.gz` and `VSRustium-1.147.0-insider-linux-x64.tar.gz`; the macOS build is unchanged (its area tests and api-tests as before). |
| Milestones | M24 Windows build | later | After milestone 23, on the same seams: WebView2 (wry), the Win32 file dialogs, the in-window menu bar and custom title bar, Credential Manager (keyring), the user-setup install path and `code` on PATH, `%APPDATA%\Code` settings import, ConPTY for the terminal (alacritty_terminal has it), an x64 and arm64 zip and a user installer, no Authenticode signing (the Windows signing decision). Builds on a GitHub Actions `windows` runner. | As milestone 23, for win32-x64 and win32-arm64. |
| Milestones | M25 virtual workspaces | later | Artur: its own milestone after M20, not part of the gap audits. A folder of a non-file scheme (`.code-workspace` `uri` folders, `--folder-uri`, `vscode.openFolder` with an extension file system provider scheme) kept as a URI; every reader of workspace folders (173 `.folders` uses in 70 files: explorer, search, quick open, terminal cwd, tasks, git, watcher, settings layers, trust) goes through the file system providers; the workspace marked virtual, `virtualWorkspaces: false` extensions disabled with the `notSupportedInWorkspace` message (config/workspace.rs:101, port/notes.md provider entries deferred until virtual workspaces). | not started |
-| M23 Linux | app/src/webview/linux.rs:66 | done | [linux L] webviews through WebKitGTK: webview panels and views, editor insets, notebook outputs, extension details, release notes. | `FIXTURE=webview-tests port/tools/linux/smoke` on X11 (Xvfb): 8/8 ok; `cargo gc test -p app webview` on Linux: 18 passed |
+| M23 Linux | app/src/webview/linux.rs:66 | done | [linux L] webviews through WebKitGTK: webview panels and views, editor insets, notebook outputs, extension details, release notes. | `FIXTURE=webview-tests port/tools/linux/smoke` on X11 (Xvfb): 9 ok and the loopback http gap (linux.rs:97 row); `cargo gc test -p app webview` on Linux: 19 passed |
| M23 Linux | app/src/webview/linux.rs:47 | open | [linux M] webviews in a Wayland session. Linux shows now: no webview under Wayland: GPUI has no X window there to hold the GTK window, so `supported()` is false and each webview surface stays empty. | |
+| M23 Linux | app/src/webview/linux.rs:97 | open | [linux S] http from loopback in a webview (the Simple Browser on a `http://localhost` dev server). Linux shows now: WebKitGTK blocks every http load in the https host page as mixed content, loopback included, and has no per-host setting; `register_uri_scheme_as_secure("http")` would let any http script in (port/notes.md M23). | |
| M23 Linux | exthost/src/main_thread_secret_state.rs:46 | done | [linux M] secrets in the Secret Service (libsecret). | `cargo test -p exthost secret` on Linux: `secrets_in_a_keyring` (oo7's file backend); a desktop Secret Service not run |
| M23 Linux | app/src/clipboard.rs:97 | open | [linux M] clipboard file lists, HTML and other custom formats, the find text. Linux shows now: text only; the other formats read empty. | |
| M23 Linux | app/src/workbench/themes.rs:47 | done | [linux S] host color scheme and high contrast from the xdg-desktop-portal Settings. | GPUI's `window_appearance()`, which gpui_linux reads from the portal's `color-scheme`; high contrast stays off, as Chromium on Linux |
diff --git a/port/notes.md b/port/notes.md
index 825074ee5bd..32d699ea58b 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -987,7 +987,7 @@ What to do (milestone 21, in order):
- Package (`port/tools/package-linux`, the app files from `port/tools/app-files.ts`): `VSRustium-linux-<arch>/` as VS Code's Linux archive lays it out, the release binary named `applicationName` (debug info stripped: `debug = "limited"` stays in the ELF on Linux, 571 MB with it) beside bun, `bin/vsrustium` from upstream's `resources/linux/bin/code.sh`, `com.rokartur.vsrustium.desktop` from upstream's `resources/linux/code.desktop` (Exec is `vsrustium` on PATH, as an archive does not know where it is unpacked; `StartupWMClass` is `product.linuxDesktopName`, which the windows set as their X11 WM_CLASS and Wayland app id) with `vsrustium.png` (`port/AppIcon.png`, ictool's 512 px render of `port/AppIcon.icon`), the app files in `resources/app` (`product::BUNDLED_APP`, which the binary takes as its root when it is there). Native modules built for another system or arch are rebuilt with node-gyp from their source; a binding.gyp that builds nothing on Linux (@vscode/fs-copyfile) leaves the module out, any other foreign binary fails the package. It writes `VSRustium-<version>-linux-<arch>.tar.gz` and the `linux-<arch>.json` and `linux-<arch>-prerelease.json` feed entries (`gallery::CURRENT_TARGET_PLATFORM` is `linux-<arch>` on Linux, for the gallery and the update feed). arm64 1.147.0: folder 412 MB, archive 131 MB; the extracted archive passes `port/tools/linux/smoke` with `APP=<folder>/vsrustium` in a container without the reference mounted. linux-x64 builds on GitHub Actions (`.github/workflows/linux.yml`, run by hand, the README's build steps with upstream's pnpm install building the native modules for Linux). The binary needs the glibc it links: GLIBC_2.39 for both (Debian 13's container, the ubuntu-24.04 runner; ubuntu-latest, 26.04, asked for 2.43 and the x64 package did not start on Debian 13).
- Desktop services over D-Bus (zbus 5, the one gpui_linux's ashpd and oo7 build; blocking proxies on their own threads, each service optional): power (`power/linux.rs`) takes idle time from Mutter's IdleMonitor, else the ScreenSaver service's `GetSessionIdleTime`; the lock state from logind's session `LockedHint`; the power source from UPower's `OnBattery`; `prevent-display-sleep` is a ScreenSaver `Inhibit` cookie and `prevent-app-suspension` a logind `sleep` inhibitor fd; the events are logind's `PrepareForSleep` and `PrepareForShutdown`, as Electron has no lock, battery, thermal or speed limit events on Linux. A blocker the bus refuses still counts as started, as Electron's map of ids. Metered is NetworkManager's `Metered` (`YES` or `GUESS_YES`), the screen reader AT-SPI's `org.a11y.Status` `ScreenReaderEnabled`, reduced motion the portal's `org.gnome.desktop.interface` `enable-animations` (Chromium follows GTK's `gtk-enable-animations`). None of these ran against a desktop session yet: the container has no session or system bus.
- Secrets (`exthost/src/main_thread_secret_state.rs`) are Secret Service items of the default collection through oo7 (gpui_linux's version and features), with keytar's `service` and `account` attributes; the test runs the flow on oo7's file keyring.
-- Webviews (`app/src/webview/linux.rs`, the host page and its answers shared with macOS in `webview.rs`) are WebKitGTK 4.1 views, each in an undecorated GTK popup window whose X window is reparented into GPUI's; a notebook's back layer webview sits in a clip window whose X input shape passes presses through to GPUI outside the outputs. GTK runs on GPUI's main thread, iterated every 8 ms (`pump_gtk`). Keyboard focus moves with `XSetInputFocus` (a reparented window gets none from the window manager); Cut, Copy and Paste run WebKitGTK's editing commands. WebKitGTK refuses a URI scheme handler on `https`, so each view's ephemeral context sets a loopback proxy as its https proxy: `CONNECT` to `*.vscode-webview.vscode-cdn.net` and `*.vscode-resource.vscode-cdn.net` is answered over TLS with a process-local self-signed certificate the context trusts for those hosts only (the host page's files, and resources as the macOS scheme handler reads them), every other host is tunneled. OpenSSL serves that TLS: GnuTLS, glib-networking's backend, refuses a resource host's SNI (`file+.vscode-resource...`, the `+` is no DNS character). The proxy answers only connections /proc/net/tcp shows as the app user's. Wayland sessions show no webview (GPUI has no X window there; the open M23 row).
+- Webviews (`app/src/webview/linux.rs`, the host page and its answers shared with macOS in `webview.rs`) are WebKitGTK 4.1 views, each in an undecorated GTK popup window whose X window is reparented into GPUI's; a notebook's back layer webview sits in a clip window whose X input shape passes presses through to GPUI outside the outputs. GTK runs on GPUI's main thread, iterated every 8 ms (`pump_gtk`). Keyboard focus moves with `XSetInputFocus` (a reparented window gets none from the window manager); Cut, Copy and Paste run WebKitGTK's editing commands. WebKitGTK refuses a URI scheme handler on `https`, so each view's ephemeral context sets a loopback proxy as its https proxy: `CONNECT` to `*.vscode-webview.vscode-cdn.net` and `*.vscode-resource.vscode-cdn.net` is answered over TLS with a process-local self-signed certificate the context trusts for those hosts only (the host page's files, and resources as the macOS scheme handler reads them), every other host is tunneled. OpenSSL serves that TLS: GnuTLS, glib-networking's backend, refuses a resource host's SNI (`file+.vscode-resource...`, the `+` is no DNS character). The proxy answers only connections /proc/net/tcp shows as the app user's. WebKitGTK 2.54 blocks every http load in the https host page as mixed content, loopback included, where Chromium lets loopback through (the Simple Browser's `http://localhost` dev servers): registering `http` as a secure scheme would let any http script in, and WebKitGTK has no per-host setting, so loopback http stays blocked (an open M23 row; webview-tests `webviews should load http scripts from loopback` prints `gap` on Linux). Wayland sessions show no webview (GPUI has no X window there; the open M23 row).
- Updates follow updateService.linux.ts: a found build waits in AvailableForDownload (no metered deferral, no Squirrel read-only check) and Download opens product.json `downloadUrl`, else the update's url, and goes back to Idle. The running build counts as installed when its executable sits beside `resources/app`.
- Accessibility signal sounds run `pw-play`, else `paplay` (both decode mp3 through libsndfile 1.1 or later), one process per sound file, killed when the sound replays.
- The `code` shell command on Linux links `~/.local/bin/<applicationName>` to the archive's `bin/<applicationName>` without a privilege prompt (upstream has the command on macOS only; a Linux package puts it on PATH itself). Proxy `<local>` adds the request's host to `--noproxy` when it has no dot, curl has no such rule. Machine info reads `/proc/cpuinfo`, `/proc/meminfo` and the cpufreq `scaling_cur_freq`.
diff --git a/port/tools/linux/smoke b/port/tools/linux/smoke
index 213ec9407c9..4b6c7d9fd19 100755
--- a/port/tools/linux/smoke
+++ b/port/tools/linux/smoke
@@ -21,6 +21,6 @@ tests=$PWD/port/fixtures/extensions/${FIXTURE:-linux-smoke-tests}
timeout 300 "$APP" "$dir/workspace" --user-data-dir "$dir/user-data" --skip-welcome --disable-workspace-trust \
--extensionDevelopmentPath="$tests" --extensionTestsPath="$tests/tests" >"$dir/log" 2>&1
code=$?
-grep -E "^handshake done|^(ok|FAILED) " "$dir/log"
+grep -E "^handshake done|^(ok|gap|FAILED) " "$dir/log"
echo "linux smoke: exit $code"
exit $code
diff --git a/port/tools/webview-check b/port/tools/webview-check
index 5343560fa9d..066f850cb04 100755
--- a/port/tools/webview-check
+++ b/port/tools/webview-check
@@ -21,7 +21,7 @@ for app in ${APP:-reference port}; do
fi
code=$?
echo "== $app"
- grep -E '(^| )(ok|FAILED) ' "$out/log" | sed -E 's/^.*(ok|FAILED) /\1 /' || tail -20 "$out/log"
+ grep -E '(^| )(ok|gap|FAILED) ' "$out/log" | sed -E 's/^.*(ok|gap|FAILED) /\1 /' || tail -20 "$out/log"
echo "exit $code"
[[ $code == 0 ]] || status=$code
rm -rf "$out"