From d3de75f9504bebf736675e72181aab11304ace8c Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Mon, 11 Nov 2024 12:09:46 +0100 Subject: [PATCH] fix: direnv should only run in trusted projects --- CHANGELOG.md | 5 +++++ .../kotlin/com/falsepattern/zigbrains/direnv/DirenvCmd.kt | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c1289fb..d1f60479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,11 @@ Changelog structure reference: - Zig - Escape sequence highlighting in char literals +### Changed + +- Project + - Direnv now only runs automatically in trusted projects + ### Fixed - Zig diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/direnv/DirenvCmd.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/direnv/DirenvCmd.kt index 5d968102..20edbb3a 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/direnv/DirenvCmd.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/direnv/DirenvCmd.kt @@ -25,6 +25,7 @@ package com.falsepattern.zigbrains.direnv import com.falsepattern.zigbrains.ZigBrainsBundle import com.intellij.execution.configurations.GeneralCommandLine import com.intellij.execution.configurations.PathEnvironmentVariableUtil +import com.intellij.ide.impl.isTrusted import com.intellij.notification.Notification import com.intellij.notification.NotificationType import com.intellij.notification.Notifications @@ -40,7 +41,7 @@ import java.nio.file.Path object DirenvCmd { suspend fun importDirenv(project: Project): Env { - if (!direnvInstalled()) + if (!direnvInstalled() || !project.isTrusted()) return emptyEnv val workDir = project.guessProjectDir()?.toNioPath() ?: return emptyEnv @@ -94,9 +95,12 @@ object DirenvCmd { } private const val GROUP_DISPLAY_ID = "zigbrains-direnv" - fun direnvInstalled() = + + private val _direnvInstalled by lazy { // Using the builtin stuff here instead of Env because it should only scan for direnv on the process path PathEnvironmentVariableUtil.findExecutableInPathOnAnyOS("direnv") != null + } + fun direnvInstalled() = _direnvInstalled } suspend fun Project?.getDirenv(): Env {