From 364de1bcba1f3fb3a5810b298de880a7b6bc142e Mon Sep 17 00:00:00 2001 From: Nikita Iarychenko Date: Fri, 15 Nov 2024 14:34:02 +0400 Subject: [PATCH] OPENIDE #24 Restrict IDE access to untrusted sources (cherry picked from commit 5bc56a6a642bb0baba1a0434c50f6b45cae64cb9) (cherry picked from commit fdfad7b12511dc63f40e2a4d7349f3f70c9c3ec6) (cherry picked from commit b869d83490cb70b07174110aa7504999fde46f98) (cherry picked from commit 3c336d805004315254d9ede7794b2c50573ed1ef) --- .../intellij.idea.customization.base.xml | 2 +- .../base/src/OpenIdeExternalResourceUrls.kt | 31 ++++++++++ .../IntellijTestDiscoveryProducer.java | 2 +- .../resources/META-INF/JavaPlugin.xml | 6 +- .../feedback/impl/GeneralFeedbackSubmit.kt | 22 +++---- .../LibrariesDownloadConnectionService.java | 4 +- .../src/com/intellij/util/io/WhiteListUrls.kt | 34 +++++++++++ .../impl/jdkDownloader/JdkList.kt | 2 +- .../impl/jdkDownloader/RuntimeChooserJbr.kt | 3 +- .../src/com/intellij/ide/RegionUrlMapper.java | 7 ++- .../git4idea/resources/intellij.vcs.git.xml | 3 +- .../plugin-resources/intellij.gradle.xml | 2 +- .../sceneBuilder/SceneBuilderEditor.java | 59 ++++++++++--------- .../core/resources/META-INF/plugin.xml | 2 +- 14 files changed, 125 insertions(+), 54 deletions(-) create mode 100644 idea/customization/base/src/OpenIdeExternalResourceUrls.kt create mode 100644 platform/ide-core/src/com/intellij/util/io/WhiteListUrls.kt diff --git a/idea/customization/base/resources/intellij.idea.customization.base.xml b/idea/customization/base/resources/intellij.idea.customization.base.xml index b85009541bf9..eb338115a76a 100644 --- a/idea/customization/base/resources/intellij.idea.customization.base.xml +++ b/idea/customization/base/resources/intellij.idea.customization.base.xml @@ -2,7 +2,7 @@ \ No newline at end of file diff --git a/idea/customization/base/src/OpenIdeExternalResourceUrls.kt b/idea/customization/base/src/OpenIdeExternalResourceUrls.kt new file mode 100644 index 000000000000..68688d048892 --- /dev/null +++ b/idea/customization/base/src/OpenIdeExternalResourceUrls.kt @@ -0,0 +1,31 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.idea.customization.base + +import com.intellij.openapi.util.BuildNumber +import com.intellij.platform.ide.customization.ExternalProductResourceUrls +import com.intellij.util.Url +import com.intellij.util.Urls + +// TODO [OpenIDE]: replaces urls +class OpenIdeExternalResourceUrls : ExternalProductResourceUrls { + + override val helpPageUrl: ((topicId: String) -> Url)? = null + + override val gettingStartedPageUrl = null + + override val youTubeChannelUrl = null + + override val updateMetadataUrl = Urls.newFromEncoded("https://www.openide.com") + + override fun computePatchUrl(from: BuildNumber, to: BuildNumber): Url = Urls.newFromEncoded("https://www.openide.com") + + override val bugReportUrl: ((String) -> Url)? = null + + override val technicalSupportUrl: ((description: String) -> Url) ? = null + + override val feedbackReporter = null + + override val downloadPageUrl = null + + override val whatIsNewPageUrl = null +} \ No newline at end of file diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/IntellijTestDiscoveryProducer.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/IntellijTestDiscoveryProducer.java index aa41852918b4..e60536766e22 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/IntellijTestDiscoveryProducer.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/IntellijTestDiscoveryProducer.java @@ -39,7 +39,7 @@ import java.util.stream.Collectors; @InternalIgnoreDependencyViolation public final class IntellijTestDiscoveryProducer implements TestDiscoveryProducer { - private static final String INTELLIJ_TEST_DISCOVERY_HOST = "https://intellij-test-discovery.labs.intellij.net"; + private static final String INTELLIJ_TEST_DISCOVERY_HOST = ""; private static final NotNullLazyValue JSON_READER = NotNullLazyValue.createValue(() -> new ObjectMapper().readerFor(TestsSearchResult.class)); diff --git a/java/java-backend/resources/META-INF/JavaPlugin.xml b/java/java-backend/resources/META-INF/JavaPlugin.xml index e6ab836811d7..e3006436239b 100644 --- a/java/java-backend/resources/META-INF/JavaPlugin.xml +++ b/java/java-backend/resources/META-INF/JavaPlugin.xml @@ -961,7 +961,7 @@ - + @@ -1062,8 +1062,8 @@ nameKey="settings.inlay.java.external.annotations" descriptionKey="inlay.annotation.hints.external.annotations" /> - Unit, onError: () -> Unit, feedbackRequestType: FeedbackRequestType = FeedbackRequestType.TEST_REQUEST) { - ApplicationManager.getApplication().executeOnPooledThread { - val feedbackUrl = when (feedbackRequestType) { - FeedbackRequestType.NO_REQUEST -> return@executeOnPooledThread - FeedbackRequestType.TEST_REQUEST -> TEST_FEEDBACK_URL - FeedbackRequestType.PRODUCTION_REQUEST -> PRODUCTION_FEEDBACK_URL - } - - val regionalFeedbackUrl = RegionUrlMapper.tryMapUrlBlocking(feedbackUrl) - LOG.info("Feedback sent to $regionalFeedbackUrl") - sendFeedback(regionalFeedbackUrl, feedbackData, onDone, onError) - } + //ApplicationManager.getApplication().executeOnPooledThread { + // val feedbackUrl = when (feedbackRequestType) { + // FeedbackRequestType.NO_REQUEST -> return@executeOnPooledThread + // FeedbackRequestType.TEST_REQUEST -> TEST_FEEDBACK_URL + // FeedbackRequestType.PRODUCTION_REQUEST -> PRODUCTION_FEEDBACK_URL + // } + // + // val regionalFeedbackUrl = RegionUrlMapper.tryMapUrlBlocking(feedbackUrl) + // LOG.info("Feedback sent to $regionalFeedbackUrl") + // sendFeedback(regionalFeedbackUrl, feedbackData, onDone, onError) + //} } private fun sendFeedback(feedbackUrl: String, diff --git a/platform/ide-core/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java b/platform/ide-core/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java index 7ba96b90bdbd..ea9dd6ace6ec 100644 --- a/platform/ide-core/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java +++ b/platform/ide-core/src/com/intellij/facet/frameworks/LibrariesDownloadConnectionService.java @@ -3,8 +3,8 @@ package com.intellij.facet.frameworks; public final class LibrariesDownloadConnectionService extends SettingsConnectionService { - private static final String SETTINGS_URL = "https://www.jetbrains.com/idea/download-assistant.xml"; - private static final String SERVICE_URL = "https://frameworks.jetbrains.com"; + private static final String SETTINGS_URL = null; + private static final String SERVICE_URL = null; private static final LibrariesDownloadConnectionService ourInstance = new LibrariesDownloadConnectionService(); diff --git a/platform/ide-core/src/com/intellij/util/io/WhiteListUrls.kt b/platform/ide-core/src/com/intellij/util/io/WhiteListUrls.kt new file mode 100644 index 000000000000..c02943384bc3 --- /dev/null +++ b/platform/ide-core/src/com/intellij/util/io/WhiteListUrls.kt @@ -0,0 +1,34 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.util.io + +import java.net.URL +import java.net.URLConnection + +object WhiteListUrls { + private val urls = listOf( + "https://github.com", + "https://search.maven.org", + "https://repo.jfrog.org", + "https://oss.sonatype.org", + "https://repository.jboss.org", + "https://repo.maven.apache.org", + "https://plugins.gradle.org/plugin/org.jetbrains.intellij", + "https://api.github.com/repos", + "https://pypi.python.org", + "http://localhost", + "https://services.gradle.org", + "https://plugins.jetbrains.com", // TODO [OpenIDE]: replace url + "https://downloads.marketplace.jetbrains.com/files", // TODO [OpenIDE]: replace url + "https://repo1.maven.org/maven2/net/sourceforge/plantuml/plantuml/1.2023.10/plantuml-1.2023.10.jar", + ) + + @JvmStatic + fun isAvailableUrl(url: String): Boolean { + return urls.any { url.startsWith(it, true) } + } +} + +class StubUrlConnection(url: URL): URLConnection(url) { + override fun connect() { + } +} \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkList.kt b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkList.kt index 4ba23f7500be..1c2997ed79cf 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkList.kt +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkList.kt @@ -526,7 +526,7 @@ class JdkListDownloader : JdkListDownloaderBase() { return registry } } - return "https://download.jetbrains.com/jdk/feed/v1/jdks.json.xz" + return "" // TODO [OpenIDE]: replace url } } diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/RuntimeChooserJbr.kt b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/RuntimeChooserJbr.kt index 42b7475ecd99..5b58afd48ec8 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/RuntimeChooserJbr.kt +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/RuntimeChooserJbr.kt @@ -40,7 +40,8 @@ private class RuntimeChooserJbrListDownloader : JdkListDownloaderBase() { val majorVersion = runCatching { Registry.get("runtime.chooser.pretend.major").asInteger() }.getOrNull() ?: ApplicationInfo.getInstance().build.components.firstOrNull() - return "https://download.jetbrains.com/jdk/feed/v1/jbr-choose-runtime-${majorVersion}.json.xz" + return ""; // TODO [OpenIDE]: replace url + //return "https://download.jetbrains.com/jdk/feed/v1/jbr-choose-runtime-${majorVersion}.json.xz" } } diff --git a/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java b/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java index 997c9ef10cf6..85a4ace6d1a1 100644 --- a/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java +++ b/platform/platform-impl/src/com/intellij/ide/RegionUrlMapper.java @@ -11,9 +11,13 @@ import com.intellij.util.SmartList; import com.intellij.util.SystemProperties; import com.intellij.util.concurrency.annotations.RequiresBackgroundThread; import com.intellij.util.concurrency.annotations.RequiresReadLockAbsence; +import com.intellij.util.io.HttpRequests; import com.intellij.util.net.PlatformHttpClient; +import kotlinx.coroutines.Dispatchers; +import kotlinx.coroutines.ExecutorsKt; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.io.JsonReaderEx; import org.jetbrains.io.JsonUtil; @@ -159,8 +163,7 @@ public final class RegionUrlMapper { } private static @NotNull String getConfigUrl(@NotNull Region reg) { - String overridden = OVERRIDE_CONFIG_URL_TABLE.get(reg); - return overridden != null ? overridden : CONFIG_URL_TABLE.getOrDefault(reg, CONFIG_URL_DEFAULT); + return ""; } /* diff --git a/plugins/git4idea/resources/intellij.vcs.git.xml b/plugins/git4idea/resources/intellij.vcs.git.xml index 2201d22f4648..5870cb5d842f 100644 --- a/plugins/git4idea/resources/intellij.vcs.git.xml +++ b/plugins/git4idea/resources/intellij.vcs.git.xml @@ -939,7 +939,8 @@ restartRequired="true" description="Amount of time in minutes to check new Git version after IDE inactivity.\n -1 to disable check."/> - + + diff --git a/plugins/gradle/plugin-resources/intellij.gradle.xml b/plugins/gradle/plugin-resources/intellij.gradle.xml index c96ca4b8e003..6b04844f201e 100644 --- a/plugins/gradle/plugin-resources/intellij.gradle.xml +++ b/plugins/gradle/plugin-resources/intellij.gradle.xml @@ -207,7 +207,7 @@ description="Enable the phased Gradle sync execution"/> - { - DownloadableFileService service = DownloadableFileService.getInstance(); - var description = service.createFileDescription("https://cache-redirector.jetbrains.com/" + - "intellij-dependencies/org/jetbrains/intellij/deps/scenebuilderkit/" + - SceneBuilderUtil.SCENE_BUILDER_VERSION + "/" + SceneBuilderUtil.SCENE_BUILDER_KIT_FULL_NAME, SceneBuilderUtil.SCENE_BUILDER_KIT_FULL_NAME); - FileDownloader downloader = service.createDownloader(Collections.singletonList(description), "Scene Builder Kit"); - try { - Path tempDir = Files.createTempDirectory(""); - - final var list = downloader.downloadWithProgress(tempDir.toString(), myProject, myErrorPanel); - if (list == null || list.isEmpty()) { - myErrorNotification.clear(); - myErrorNotification.setText(JavaFXBundle.message("javafx.scene.builder.editor.failed.to.download.kit.error")); - return; - } - - FileUtil.copy(VfsUtilCore.virtualToIoFile(list.get(0).first), SceneBuilderUtil.getSceneBuilder11Path().toFile()); - FileUtil.delete(tempDir.toFile()); - - SceneBuilderUtil.updateLoader(); - updateState(); - } - catch (IOException e2) { - LOG.warn("Can't download SceneBuilderKit", e2); - } - } - ); + // TODO [OpenIDE]: https://git.haulmont.com/platform/open-ide/idea/-/issues/29 + //myErrorNotification.createActionLabel( + // JavaFXBundle.message("javafx.scene.builder.editor.download.scene.builder.kit"), + // () -> { + // DownloadableFileService service = DownloadableFileService.getInstance(); + // var description = service.createFileDescription("https://cache-redirector.jetbrains.com/" + + // "intellij-dependencies/org/jetbrains/intellij/deps/scenebuilderkit/" + + // SceneBuilderUtil.SCENE_BUILDER_VERSION + "/" + SceneBuilderUtil.SCENE_BUILDER_KIT_FULL_NAME, SceneBuilderUtil.SCENE_BUILDER_KIT_FULL_NAME); + // FileDownloader downloader = service.createDownloader(Collections.singletonList(description), "Scene Builder Kit"); + // try { + // Path tempDir = Files.createTempDirectory(""); + // + // final var list = downloader.downloadWithProgress(tempDir.toString(), myProject, myErrorPanel); + // if (list == null || list.isEmpty()) { + // myErrorNotification.clear(); + // myErrorNotification.setText(JavaFXBundle.message("javafx.scene.builder.editor.failed.to.download.kit.error")); + // return; + // } + // + // FileUtil.copy(VfsUtilCore.virtualToIoFile(list.get(0).first), SceneBuilderUtil.getSceneBuilder11Path().toFile()); + // FileUtil.delete(tempDir.toFile()); + // + // SceneBuilderUtil.updateLoader(); + // updateState(); + // } + // catch (IOException e2) { + // LOG.warn("Can't download SceneBuilderKit", e2); + // } + // } + //); myLayout.show(myPanel, ERROR_CARD); return; } diff --git a/plugins/markdown/core/resources/META-INF/plugin.xml b/plugins/markdown/core/resources/META-INF/plugin.xml index 7d1ba64eeee7..9c1a2ee5dc93 100644 --- a/plugins/markdown/core/resources/META-INF/plugin.xml +++ b/plugins/markdown/core/resources/META-INF/plugin.xml @@ -328,7 +328,7 @@ defaultValue="600000" description="Interval in milliseconds defining how often Markdown plugin caches (e.g. PlantUML diagrams) should be cleared"/>