Visual Studio Code, rebuilt in Rust
Rust
fix(extensions): reject a gallery VSIX name that leaves its folder
rokarturc4fe3eb964ba
diff --git a/native/crates/app/src/workbench/extension_management.rs b/native/crates/app/src/workbench/extension_management.rsindex 0ba43af6a2e..5230b55fb68 100644--- a/native/crates/app/src/workbench/extension_management.rs+++ b/native/crates/app/src/workbench/extension_management.rs@@ -398,14 +398,14 @@ impl Workbench {Err(error) => return workbench.update(cx, |workbench, cx| notify_failure(workbench, format!("{error:#}"), cx)),},};+ let file_name = match vsix_file_name(&found.id, &found.version, target_platform) {+ Ok(file_name) => file_name,+ Err(error) => return workbench.update(cx, |workbench, cx| notify_failure(workbench, format!("{error:#}"), cx)),+ };let dialog = FileDialog { title: Some("Select folder to download the VSIX".into()), button_label: Some("Download".into()), folders: true, ..FileDialog::default() };let picked = workbench.update(cx, |workbench, cx| workbench.show_open_dialog(dialog, cx))?;let Some(folder) = picked.await.unwrap_or_default().into_iter().next() else { return Ok(()) };- let suffix = match target_platform {- exthost::gallery::UNDEFINED | exthost::gallery::UNIVERSAL | exthost::gallery::UNKNOWN => String::new(),- platform => format!("-{platform}"),- };- let location = folder.join(format!("{}-{}{suffix}.vsix", found.id, found.version));+ let location = folder.join(file_name);let mut progress = Notification::new(Severity::Info, "Downloading VSIX...");progress.progress = Some(Progress { infinite: true, ..Progress::default() });let key = workbench.update(cx, |workbench, cx| {@@ -725,6 +725,21 @@ fn version_pick(versions: &[GalleryVersion], current: Option<&str>, placeholder:input}+/// `<id>-<version>[-<platform>].vsix`; the gallery's id and version are untrusted, so a part that is not a plain file+/// name component (empty, `..`, a separator) is rejected before it is joined to the picked folder.+fn vsix_file_name(id: &str, version: &str, target_platform: &str) -> anyhow::Result<String> {+ for part in [id, version] {+ if part.is_empty() || part.contains(['/', '\\']) || part.contains("..") {+ anyhow::bail!("The gallery sent an invalid extension id or version: '{part}'.");+ }+ }+ let suffix = match target_platform {+ exthost::gallery::UNDEFINED | exthost::gallery::UNIVERSAL | exthost::gallery::UNKNOWN => String::new(),+ platform => format!("-{platform}"),+ };+ Ok(format!("{id}-{version}{suffix}.vsix"))+}+fn notify_failure(workbench: &mut Workbench, message: String, cx: &mut Context<Workbench>) {workbench.notify_error(message);cx.notify();diff --git a/native/crates/app/src/workbench/extension_management/tests.rs b/native/crates/app/src/workbench/extension_management/tests.rsindex 3a381c3d536..826faa531c8 100644--- a/native/crates/app/src/workbench/extension_management/tests.rs+++ b/native/crates/app/src/workbench/extension_management/tests.rs@@ -57,6 +57,32 @@ fn workbench_on_gallery<'a>(name: &str, entries: &[(&str, &[&str], &[&str])], cx(Fixture { dir, messages }, workbench, cx)}+/// extensionsActions.ts `InstallAction` on an unsigned extension: the prompt is refused in tests (skipDialogs), and the+/// signed install fails `NotSigned`; "Install Anyway" (`donotVerifySignature`) installs it.+#[gpui::test]+fn install_anyway_installs_an_unsigned_extension(cx: &mut TestAppContext) {+ let (fixture, workbench, cx) = workbench_on_gallery("install-unsigned", &[("a.yaml", &[], &[])], cx);+ workbench.update(cx, |workbench, _| workbench.settings.lock().unwrap().update_value("extensions.verifySignature", Some(&json!(true)), config::service::Target::User, None, &[]).unwrap());+ workbench.update_in(cx, |workbench, window, cx| drop(workbench.execute_command("workbench.extensions.action.installUnsigned", vec![json!("a.yaml")], window, cx)));+ cx.run_until_parked();+ workbench.update(cx, |workbench, cx| drop(workbench.install_from_gallery_verifying("a.yaml".into(), None, false, true, cx)));+ cx.run_until_parked();+ assert_eq!(sent_jobs(&fixture.messages), Vec::<String>::new(), "refused prompt and the signed install send nothing");+ workbench.update(cx, |workbench, cx| drop(workbench.install_from_gallery_verifying("a.yaml".into(), None, false, false, cx)));+ cx.run_until_parked();+ assert_eq!(sent_jobs(&fixture.messages), ["a.yaml"]);+}++/// The gallery's id and version are untrusted: one that would leave the picked folder names no file.+#[test]+fn a_vsix_name_rejects_a_path_from_the_gallery() {+ use super::vsix_file_name;+ assert_eq!(vsix_file_name("a.yaml", "2.0.0", exthost::gallery::UNDEFINED).unwrap(), "a.yaml-2.0.0.vsix");+ for (id, version) in [("..", "1.0.0"), ("a/../../b", "1.0.0"), ("a.b", "..\\x"), ("", "1.0.0"), ("a.b", "")] {+ assert!(vsix_file_name(id, version, exthost::gallery::UNDEFINED).is_err(), "{id} {version}");+ }+}+/// The jobs sent to the host: a gallery install by its id, a VSIX install as `vsix`.fn sent_jobs(messages: &Receiver<HostMessage>) -> Vec<String> {let mut jobs = Vec::new();diff --git a/port/ledger.md b/port/ledger.mdindex 8d094b76009..dfff8fdcdb0 100644--- a/port/ledger.md+++ b/port/ledger.md@@ -536,7 +536,7 @@ One row per upstream unit, generated by `bun port/tools/gen-ledger.ts`; mileston| workbench/contrib/emergencyAlert | workbench contribution | | removed | | no AI or Microsoft services by decision (port/notes.md); API stays inert || workbench/contrib/emmet | workbench contribution | M13 | verified | | workbench/emmet.rs: Emmet: Expand Abbreviation (`emmet.expandAbbreviation` with the language at the cursor and the emmet parent mode of its grammar's scope, emmetAction.test.ts cases), Tab with `emmet.triggerExpansionOnTab`, the Edit menu entry: cargo test -p app emmet menubar || workbench/contrib/encryption | workbench contribution | M10 | n/a | | encryption.contribution.ts only migrates Linux `password-store` argv values to gnome-libsecret; the port runs on macOS and keeps secrets in the Keychain |-| workbench/contrib/extensions | workbench contribution | M18 | ported | [3 M] extensions.contribution.ts: the `MenuId.ExtensionContext` item Apply Extension to all Profiles (`toggleApplyToAllProfiles`) waits for application-scoped extensions: extensionsScannerService.ts `scanExtensionsFromProfile` adds the default profile's `isApplicationScoped` entries to every other profile, exthost extension_management.rs `UserExtensions::scan` reads only the current profile's extensions.json; [3 S] the row's activation time in ui-pair `menus/extension-context.json`: languageService.ts `onDidRequestRichLanguageFeatures` sends `onLanguage` for every text model an editor widget asks features of, the view's SuggestEnabledInput search box (`createModel('', null)`) included, host_sync.rs only for open editor documents, so with no editor open the reference's Emmet row shows its activation time (34ms) and the port's none; Developer: Startup Performance lists the eager activations in both | cargo test -p app extension the_manage_menu_lists_the_extension_context_menu the_manage_menu_installs_a_version_and_toggles_an_ignored_recommendation the_manage_menu_auto_updates_a_publisher_and_toggles_a_workspace_recommendation download_specific_version_picks_a_version_then_a_folder install_specific_version_installs_the_picked_version an_activated_extensions_row_shows_its_activation_time the_manage_menu_sets_a_theme_of_the_extension the_views_are_panes extension_bisect bisect_finds_the_extension_and_keeps_it_disabled extension_features the_runtime_status_lists_uncaught_errors_and_messages invalid_contributed static_entries_need_the_proposal group_needs_the_proposal debuggers_merge_by_type_and_keep_the_built_in_values skipped_menu_contributions_are_extension_messages contributed_command_messages invalid_views_and_view_containers_are_extension_messages invalid_configuration_is_an_extension_message invalid_json_validation_is_an_extension_message invalid_colors_and_icons_are_extension_messages invalid_semantic_token_contributions_are_extension_messages invalid_problem_patterns_and_matchers_are_extension_messages invalid_grammars_are_extension_messages invalid_notebook_contributions_are_extension_messages (extensionsViews, extensionQuery, extensionEnablementService tests); cargo test -p exthost all_compatible_versions_follow_the_kind_and_the_engine all_versions_ignore_the_engine_but_not_the_block; ui-pair `menus/extension-context.json` with `--extensionDevelopmentPath=<repo>/port/fixtures/extensions/menus`, `menus/extension-theme.json`, port/fixtures/extensions/ui-view.json. Out with removed parts: Report Issue & Continue (contrib/issue), the authentication point and the Account Preferences item (services/authentication), the Install (Do not Sync), Install Pre-Release (Do not Sync) and Sync This Extension items (Settings Sync, no sign-in by decision, port/notes.md) |+| workbench/contrib/extensions | workbench contribution | M18 | ported | [3 M] extensions.contribution.ts: the `MenuId.ExtensionContext` item Apply Extension to all Profiles (`toggleApplyToAllProfiles`) waits for application-scoped extensions: extensionsScannerService.ts `scanExtensionsFromProfile` adds the default profile's `isApplicationScoped` entries to every other profile, exthost extension_management.rs `UserExtensions::scan` reads only the current profile's extensions.json; [3 S] the row's activation time in ui-pair `menus/extension-context.json`: languageService.ts `onDidRequestRichLanguageFeatures` sends `onLanguage` for every text model an editor widget asks features of, the view's SuggestEnabledInput search box (`createModel('', null)`) included, host_sync.rs only for open editor documents, so with no editor open the reference's Emmet row shows its activation time (34ms) and the port's none; Developer: Startup Performance lists the eager activations in both | cargo test -p app extension the_manage_menu_lists_the_extension_context_menu the_manage_menu_installs_a_version_and_toggles_an_ignored_recommendation the_manage_menu_auto_updates_a_publisher_and_toggles_a_workspace_recommendation download_specific_version_picks_a_version_then_a_folder a_vsix_name_rejects_a_path_from_the_gallery install_anyway_installs_an_unsigned_extension install_specific_version_installs_the_picked_version an_activated_extensions_row_shows_its_activation_time the_manage_menu_sets_a_theme_of_the_extension the_views_are_panes extension_bisect bisect_finds_the_extension_and_keeps_it_disabled extension_features the_runtime_status_lists_uncaught_errors_and_messages invalid_contributed static_entries_need_the_proposal group_needs_the_proposal debuggers_merge_by_type_and_keep_the_built_in_values skipped_menu_contributions_are_extension_messages contributed_command_messages invalid_views_and_view_containers_are_extension_messages invalid_configuration_is_an_extension_message invalid_json_validation_is_an_extension_message invalid_colors_and_icons_are_extension_messages invalid_semantic_token_contributions_are_extension_messages invalid_problem_patterns_and_matchers_are_extension_messages invalid_grammars_are_extension_messages invalid_notebook_contributions_are_extension_messages (extensionsViews, extensionQuery, extensionEnablementService tests); cargo test -p exthost all_compatible_versions_follow_the_kind_and_the_engine all_versions_ignore_the_engine_but_not_the_block; ui-pair `menus/extension-context.json` with `--extensionDevelopmentPath=<repo>/port/fixtures/extensions/menus`, `menus/extension-theme.json`, port/fixtures/extensions/ui-view.json. Out with removed parts: Report Issue & Continue (contrib/issue), the authentication point and the Account Preferences item (services/authentication), the Install (Do not Sync), Install Pre-Release (Do not Sync) and Sync This Extension items (Settings Sync, no sign-in by decision, port/notes.md) || workbench/contrib/externalTerminal | workbench contribution | M15 | verified | | workbench/external_terminal.rs: Open New External Terminal (`workbench.action.terminal.openNativeConsole`, cmd+shift+c), with several workspace folders after the Select workspace folder pick (cargo test -p app open_native_console_picks_a_folder_in_a_multi_root_workspace); cargo test -p app external_terminal; ui-pair (port/results/terminal.md) || workbench/contrib/externalUriOpener | workbench contribution | M12 | verified | | workbench/opener.rs: externalUriOpenerService.ts getRequestedOpener (workbench.externalUriOpeners globs), chooseOpener, "How would you like to open: {0}" picker; no Simple Browser (out of scope); verified at port-m12b-verify: cargo test -p app opener 4/4; Simple Browser is out of scope by decision || workbench/contrib/files | workbench contribution | M12 | verified | | explorer.rs, dialog.rs, workbench/workspace_editing.rs, workbench/file_compare.rs: cargo test -p app explorer_actions file_actions view_state nest copy_path copied_path_labels compact get_context compressed_navigation explorer_find find_filters files_dropped_from_finder view_title_and_file_actions new_file_creates file_compare focus_view_commands files_that_do_not_resolve open_editors body_limits_clamp sticky pinned_editors tab_scroll tree_guides hover unpin_hover open_with_opens_the_resource the_context_menu_selects_the_row readonly_keys_follow_the_focused_item_and_its_parent a_failed_create_offers a_folder_dropped_on_the_root a_delete_confirmation_follows_the_dialog_style cmd_v_pastes_the_files_finder_copied dragging_a_root_reorders_the_workspace_folders compacts_single_child_folders_into_one_row a_workspace_root_that_fails_to_resolve_is_decorated_with_its_error a_copy_onto_a_dirty_model_reverts_it_to_the_copied_file an_unreadable_folder_expands_to_no_children (explorerFileNestingTrie.test.ts); ui-pair port/fixtures/ui-pair/m12/workspace-folders.json, port/fixtures/ui-pair/m12/compare-saved.json, m12/compare.json, m12/find-in-folder.json, m12/folder-terminal.json, m12/explorer-ops.json, m12/editor-placeholders.json, m12/open-editors.json, m12/tab-scroll.json, m12/explorer-guides.json, m12/pinned-tabs.json (port/results/contextmenu.md). Differences left (port/notes.md milestone 12): a long tooltip breaks one segment earlier (GPUI line wrapper), the pin action loses its hover after Cmd+W until the pointer moves, a shrink sticky tab with a badge has no room for its name. Virtual workspaces: milestone 25 |