Skip to content

Conversation

@alirana01
Copy link
Collaborator

@alirana01 alirana01 commented Sep 8, 2025

Description

Original bug report: #1303

Some conflicting variables from the system environment can cause issues with the export script so we need to remove those.

Fixes # (IEP-1628)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How has this been tested?

Try to add IDF_PYTHON_ENV_PATH in your system env variables and run the IDE and try installing tools they should install without any problems

Test Configuration:

  • ESP-IDF Version: any
  • OS (Windows,Linux and macOS): Windows (POSIX based systems usually dont get this as long as they are not run from CLI adding the environment to the executable being run)

Checklist

  • PR Self Reviewed
  • Applied Code formatting
  • Verified on Windows

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of the IDF Tools export by cleaning the system environment before running export commands to avoid stray environment variables causing failures.
    • More consistent detection and launching of required tools during tool operations, reducing setup friction across different machines and installations.
    • Added additional environment logging around tool execution to aid diagnostics.

@alirana01 alirana01 self-assigned this Sep 8, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 8, 2025

Walkthrough

Adds a new utility to prune IDF-related environment variables and invokes it before launching IDF subprocesses. The cleanup is implemented in IDFUtil and called from ExportIDFTools and ToolsJob (after PATH/git adjustments) with added logging around the cleaned environment.

Changes

Cohort / File(s) Summary
IDF environment helper
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java
- Added public static void cleanUpSystemEnvironment(Map<String,String>) that removes IDF-related keys (IDF_PYTHON_ENV_PATH, IDF_PATH, ESP_IDF_VERSION, IDF_CCACHE_ENABLE, IDF_COMPONENT_MANAGER, IDF_MAINTAINER, OPENOCD_SCRIPTS) from the provided env map.
Export: run export with cleaned env
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java
- After preparing a copy of the environment and possibly adding Git to PATH, calls IDFUtil.cleanUpSystemEnvironment(environment) before executing idf_tools.py export. No public method signatures changed.
Tools job: logging + cleanup before exec
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java
- Added logging of the environment before and after pruning.
- Invokes IDFUtil.cleanUpSystemEnvironment(environment) (after PATH/git augmentation) prior to process launch in both runCommand overloads.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Caller as ToolsJob / ExportIDFTools
  participant Env as env Map (copy)
  participant IDF as IDFUtil.cleanUpSystemEnvironment
  participant Proc as subprocess (idf_tools.py / other)

  Caller->>Env: copy system env\n(possibly add Git to PATH)
  note right of Env: Environment prepared
  Caller->>IDF: cleanUpSystemEnvironment(env)
  note right of IDF #D3E4CD: Removes IDF_* and OPENOCD_SCRIPTS keys
  IDF-->>Env: cleaned env
  Caller->>Proc: launch process with cleaned env
  Proc-->>Caller: output / exit
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • AndriiFilippov
  • kolipakakondal

Poem

"I’m a rabbit in the code-lined glen,
I hop and trim the noisy fen.
I tuck away each stray IDF key,
So subprocesses run tidy and free.
Hops, carrots, clean env — joy again! 🐇"

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "IEP-1628: Remove conflicting System env variables for export command" accurately and concisely captures the primary change—removing system environment variables that conflict with the export command—and includes the issue key for traceability.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch IEP-1628

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Collaborator Author

@alirana01 alirana01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Self review

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (2)

163-182: Simplify cleanup, fix typo, drop extra allocation.

No need for a LinkedList or containsKey checks; remove keys directly. Also fix the local variable typo keysToRenmove → keysToRemove.

Apply:

-    List<String> keysToRenmove = new LinkedList<>();
-    keysToRenmove.add(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH);
-    keysToRenmove.add(IDFEnvironmentVariables.IDF_PATH);
-    
-    for (String key : keysToRenmove)
-    {
-        if (environment.containsKey(key))
-        {
-            environment.remove(key);
-        }
-    }
+    for (String key : java.util.Arrays.asList(
+            IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH,
+            IDFEnvironmentVariables.IDF_PATH)) {
+        environment.remove(key);
+    }

Optional: add a one-line debug to aid support without exposing values:

// Logger.log("Removed conflicting env vars: IDF_PYTHON_ENV_PATH, IDF_PATH");

Optional nit: tweak Javadoc grammar:

  • “Remove variables that can affect … These variables can come from the system environment.”

11-11: Remove unnecessary LinkedList import.

After simplifying cleanUpSystemEnvironment, LinkedList is unused. Replace with Arrays (if you use the Arrays.asList variant).

-import java.util.LinkedList;
+import java.util.Arrays;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f62d42 and ea86896.

📒 Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build_macos
  • GitHub Check: build

Copy link
Collaborator

@sigmaaa sigmaaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Could you also check the question I added in the review?

Comment on lines 170 to 172
List<String> keysToRenmove = new LinkedList<>();
keysToRenmove.add(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH);
keysToRenmove.add(IDFEnvironmentVariables.IDF_PATH);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to exclude other environment variables that have IDF in their name to avoid conflicts? For example, in IDFEnvironmentVariables we also have IDF_CCACHE_ENABLE, IDF_COMPONENT_MANAGER, IDF_MAINTAINER, and ESP_IDF_VERSION, which can potentially affect the plugin's functionality.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that sounds about right I think I missed those
Thanks

@espressif espressif deleted a comment from coderabbitai bot Sep 9, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (1)

170-178: Good coverage of additional IDF_ vars noted earlier.*

Including IDF_CCACHE_ENABLE, IDF_COMPONENT_MANAGER, IDF_MAINTAINER, and ESP_IDF_VERSION addresses the prior feedback.

🧹 Nitpick comments (3)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (3)

163-187: Make removal case-insensitive, fix typo, simplify list creation.

  • keysToRenmove → keysToRemove (typo).
  • Environment keys are case-insensitive on Windows; remove using equalsIgnoreCase to be robust.
  • Use a fixed list instead of building a LinkedList.
-   private void cleanUpSystemEnvironment(Map<String, String> environment)
-   {
-       List<String> keysToRenmove = new LinkedList<>();
-       keysToRenmove.add(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH);
-       keysToRenmove.add(IDFEnvironmentVariables.IDF_PATH);
-       keysToRenmove.add(IDFEnvironmentVariables.ESP_IDF_VERSION);
-       keysToRenmove.add(IDFEnvironmentVariables.IDF_CCACHE_ENABLE);
-       keysToRenmove.add(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER);
-       keysToRenmove.add(IDFEnvironmentVariables.IDF_MAINTAINER);
-       keysToRenmove.add(IDFEnvironmentVariables.OPENOCD_SCRIPTS);
-       
-       for (String key : keysToRenmove)
-       {
-           if (environment.containsKey(key))
-           {
-               environment.remove(key);
-           }
-       }
-   }
+   private void cleanUpSystemEnvironment(final Map<String, String> environment)
+   {
+       if (environment == null || environment.isEmpty())
+       {
+           return;
+       }
+
+       final List<String> keysToRemove = java.util.Arrays.asList(
+               IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH,
+               IDFEnvironmentVariables.IDF_PATH,
+               IDFEnvironmentVariables.ESP_IDF_VERSION,
+               IDFEnvironmentVariables.IDF_CCACHE_ENABLE,
+               IDFEnvironmentVariables.IDF_COMPONENT_MANAGER,
+               IDFEnvironmentVariables.IDF_MAINTAINER,
+               IDFEnvironmentVariables.OPENOCD_SCRIPTS
+       );
+
+       // Remove keys in a case-insensitive way to match Windows env semantics
+       for (String existingKey : new ArrayList<>(environment.keySet()))
+       {
+           for (String target : keysToRemove)
+           {
+               if (existingKey.equalsIgnoreCase(target))
+               {
+                   environment.remove(existingKey);
+                   break;
+               }
+           }
+       }
+   }

163-167: Tighten Javadoc phrasing.

Minor wording tweak and clarify in-place mutation.

-    /**
-     * Remove the variables which can affect the idf_tools.py export command
-     * These variables can come from system environment
-     * @param environment
-     */
+    /**
+     * Remove variables that can affect the idf_tools.py export command.
+     * These variables may come from the system environment.
+     * Mutates the provided environment map in place.
+     * @param environment environment map passed to the export process
+     */

11-11: Drop LinkedList import if adopting the refactor.

If you switch to a fixed list (Arrays.asList/List.of), remove this import.

- import java.util.LinkedList;
+ // (no change if you fully qualify Arrays; otherwise)
+ // import java.util.Arrays;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea86896 and 060265c.

📒 Files selected for processing (1)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_macos

Comment on lines 136 to 137
cleanUpSystemEnvironment(environment);

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Apply env cleanup to all export paths, not just the “given IDF path” flow.

The conflicting vars will still leak into these two flows:

  • runToolsExportAndProcessOutput(...)
  • getToolsExportOutput(...)

Call cleanUpSystemEnvironment(environment) there as well to make the fix complete.

*** a/.../ExportIDFTools.java
--- b/.../ExportIDFTools.java
@@ public IStatus runToolsExportAndProcessOutput(final String pythonExePath, final String gitExePath, final MessageConsoleStream console, MessageConsoleStream errorConsoleStream)
-        if (gitExePath != null)
-        {
-            addGitToEnvironment(environment, gitExePath);
-        }
+        if (gitExePath != null)
+        {
+            addGitToEnvironment(environment, gitExePath);
+        }
+        cleanUpSystemEnvironment(environment);
@@ public IStatus getToolsExportOutput(final String pythonExePath, final String gitExePath, final MessageConsoleStream console, MessageConsoleStream errorConsoleStream)
-        if (gitExePath != null)
-        {
-            addGitToEnvironment(environment, gitExePath);
-        }
+        if (gitExePath != null)
+        {
+            addGitToEnvironment(environment, gitExePath);
+        }
+        cleanUpSystemEnvironment(environment);

Please also verify Windows tool installation via all three code paths.


🏁 Script executed:

#!/bin/bash
set -eux
# locate ExportIDFTools.java
FILE=$(rg -l "class ExportIDFTools" -g "*.java")
echo "Found file: $FILE"
# show all cleanUpSystemEnvironment calls with context
rg -nP -C3 "cleanUpSystemEnvironment" "$FILE"
# show definitions of target methods with context
echo "\nMethod runToolsExportAndProcessOutput definition with context:"
rg -nP -C3 "public IStatus runToolsExportAndProcessOutput" "$FILE"
echo "\nMethod getToolsExportOutput definition with context:"
rg -nP -C3 "public IStatus getToolsExportOutput" "$FILE"

Length of output: 2461


Add cleanup in all export flows and verify Windows tool installation

  • Insert cleanUpSystemEnvironment(environment); immediately after the addGitToEnvironment(...) block in both runToolsExportAndProcessOutput(...) and getToolsExportOutput(...).
  • Confirm Windows tool installation works correctly across all three export paths.
🤖 Prompt for AI Agents
In
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java
around lines 136-137, add a call to cleanUpSystemEnvironment(environment)
immediately after each addGitToEnvironment(...) call in both
runToolsExportAndProcessOutput(...) and getToolsExportOutput(...); ensure the
cleanup runs on all export code paths (normal, fallback and any Windows-specific
branch) and then run or write tests to verify Windows tool installation succeeds
across all three export flows so the environment is restored and Windows tools
install correctly.

Copy link
Collaborator

@kolipakakondal kolipakakondal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AndriiFilippov, could you try to reproduce this issue (even by manually configuring conflicting environment variables)?
#1303

That way, we can better test this PR.

@AndriiFilippov
Copy link
Collaborator

@kolipakakondal hi !
already doing that

image

@AndriiFilippov
Copy link
Collaborator

@alirana01 hi !

Tested under:
OS - Windows 11
ESP-IDF: v5.5

preconditions: to reproduce the original issue I have added IDF_PYTHON_ENV_PATH into my System Env variables. I used the path where my python.exe located (but not venv folder there) -> path: C:\Users\andri\e

I was not able to install tools, got the CreateProcess error=2 error:

image

log.txt

just let me know, if I did reproduce it correctly

Moved the cleanup to utility class and also added the cleanup call in required command runs
@alirana01
Copy link
Collaborator Author

@AndriiFilippov kindly verify after the build

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (1)

49-55: Apply env cleanup to all export flows, not just the “given IDF path” one.
Both runToolsExportAndProcessOutput(...) and getToolsExportOutput(...) still pass unpruned env, so conflicts can persist.

@@ public IStatus runToolsExportAndProcessOutput(...)
-		if (gitExePath != null)
-		{
-			addGitToEnvironment(environment, gitExePath);
-		}
+		if (gitExePath != null)
+		{
+			addGitToEnvironment(environment, gitExePath);
+		}
+		IDFUtil.cleanUpSystemEnvironment(environment);
@@ public IStatus getToolsExportOutput(...)
-		if (gitExePath != null)
-		{
-			addGitToEnvironment(environment, gitExePath);
-		}
+		if (gitExePath != null)
+		{
+			addGitToEnvironment(environment, gitExePath);
+		}
+		IDFUtil.cleanUpSystemEnvironment(environment);
#!/bin/bash
# Verify all export paths prune env before launching idf_tools.py
rg -nP -C2 'class ExportIDFTools|runToolsExportAndProcessOutput|getToolsExportOutput|getToolsExportOutputFromGivenIdfPath|cleanUpSystemEnvironment' bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java

Also applies to: 91-97

🧹 Nitpick comments (2)
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java (2)

13-13: Remove unused LinkedList import.
Use List.of/Arrays.asList in the method and drop this import.

-import java.util.LinkedList;

997-1021: Harden cleanup: fix typo, null/empty guard, and case‑insensitive removal.
Prevents NPEs and ensures removal on Windows where env keys can vary in case.

-	public static void cleanUpSystemEnvironment(Map<String, String> environment)
-	{
-		List<String> keysToRenmove = new LinkedList<>();
-		keysToRenmove.add(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH);
-		keysToRenmove.add(IDFEnvironmentVariables.IDF_PATH);
-		keysToRenmove.add(IDFEnvironmentVariables.ESP_IDF_VERSION);
-		keysToRenmove.add(IDFEnvironmentVariables.IDF_CCACHE_ENABLE);
-		keysToRenmove.add(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER);
-		keysToRenmove.add(IDFEnvironmentVariables.IDF_MAINTAINER);
-		keysToRenmove.add(IDFEnvironmentVariables.OPENOCD_SCRIPTS);
-		
-		for (String key : keysToRenmove)
-		{
-			if (environment.containsKey(key))
-			{
-				environment.remove(key);
-			}
-		}
-	}
+	public static void cleanUpSystemEnvironment(Map<String, String> environment)
+	{
+		if (environment == null || environment.isEmpty()) {
+			return;
+		}
+		final java.util.List<String> keysToRemove = java.util.Arrays.asList(
+			IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH,
+			IDFEnvironmentVariables.IDF_PATH,
+			IDFEnvironmentVariables.ESP_IDF_VERSION,
+			IDFEnvironmentVariables.IDF_CCACHE_ENABLE,
+			IDFEnvironmentVariables.IDF_COMPONENT_MANAGER,
+			IDFEnvironmentVariables.IDF_MAINTAINER,
+			IDFEnvironmentVariables.OPENOCD_SCRIPTS
+		);
+		// Remove matching keys ignoring case (important for Windows)
+		environment.keySet().removeIf(k -> keysToRemove.stream().anyMatch(r -> r.equalsIgnoreCase(k)));
+	}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 060265c and bdd4169.

📒 Files selected for processing (3)
  • bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java (2 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java (2 hunks)
  • bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (1)
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java (1)
  • IDFUtil (60-1022)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java (2)
bundles/com.espressif.idf.core/src/com/espressif/idf/core/logging/Logger.java (1)
  • Logger (21-137)
bundles/com.espressif.idf.core/src/com/espressif/idf/core/util/IDFUtil.java (1)
  • IDFUtil (60-1022)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_macos
🔇 Additional comments (1)
bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/update/ExportIDFTools.java (1)

135-136: Good call: cleanup before export with explicit IDF path.
Matches the PR goal and should prevent the reported CreateProcess error.

Comment on lines +474 to 476
Logger.log("Environment Variables from System:");
Logger.log(environment.toString());
environment.put("PYTHONUNBUFFERED", "1"); //$NON-NLS-1$ //$NON-NLS-2$
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Stop logging full environment (secrets/PII risk).
Dumping env maps can leak tokens, proxies, and credentials to logs.

-			Logger.log("Environment Variables from System:");
-			Logger.log(environment.toString());
+			// Avoid logging full environment; contains secrets.
@@
-			
-			Logger.log("Environment Variables after filtering from system:");
-			IDFUtil.cleanUpSystemEnvironment(environment);
-			Logger.log(environment.toString());
-			
+			IDFUtil.cleanUpSystemEnvironment(environment);

Also applies to: 492-495


🏁 Script executed:

#!/bin/bash
# Find other places that log entire environment maps/values
rg -nP -C1 '(environment\\.toString\\(\\)|Logger\\.log\\(.+Environment Variables)' -g '!**/target/**' .

Length of output: 72


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Searching for environment.toString occurrences..."
rg -n -C1 --hidden --no-ignore 'environment\.toString\(' -g '!**/target/**' . || true

echo "Searching for Logger.log(...) containing 'Environment Variables'..."
rg -n -C1 --hidden --no-ignore 'Logger\.log\([^)]*Environment Variables' -g '!**/target/**' . || true

echo "Searching for Logger.log(...) that logs environment.toString..."
rg -n -C1 --hidden --no-ignore 'Logger\.log\([^)]*environment\.toString\(' -g '!**/target/**' . || true

echo "Searching for System.getenv / System.getProperty usages..."
rg -n -C1 --hidden --no-ignore 'System\.getenv\(|System\.getProperty\(' -g '!**/target/**' . || true

echo "Done"

Length of output: 245


Stop logging full environment (secrets risk).

File: bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java — lines 474–476 and 492–495

-			Logger.log("Environment Variables from System:");
-			Logger.log(environment.toString());
+			// Avoid logging full environment; contains secrets.
@@
-			
-			Logger.log("Environment Variables after filtering from system:");
-			IDFUtil.cleanUpSystemEnvironment(environment);
-			Logger.log(environment.toString());
-			
+			IDFUtil.cleanUpSystemEnvironment(environment);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Logger.log("Environment Variables from System:");
Logger.log(environment.toString());
environment.put("PYTHONUNBUFFERED", "1"); //$NON-NLS-1$ //$NON-NLS-2$
// Avoid logging full environment; contains secrets.
environment.put("PYTHONUNBUFFERED", "1"); //$NON-NLS-1$ //$NON-NLS-2$
...
IDFUtil.cleanUpSystemEnvironment(environment);
🤖 Prompt for AI Agents
In bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/tools/ToolsJob.java
around lines 474–476 and 492–495, the code currently logs the full environment
map which may expose secrets; remove the Logger.log(environment.toString()) call
and any other direct prints of the environment, and instead log non-sensitive
metadata (e.g., number of variables or a filtered list of safe, whitelisted
variable names) or redact values before logging; ensure PYTHONUNBUFFERED is
still set but never include full environment contents or unredacted values in
logs.

Comment on lines +1003 to 1022
public static void cleanUpSystemEnvironment(Map<String, String> environment)
{
List<String> keysToRenmove = new LinkedList<>();
keysToRenmove.add(IDFEnvironmentVariables.IDF_PYTHON_ENV_PATH);
keysToRenmove.add(IDFEnvironmentVariables.IDF_PATH);
keysToRenmove.add(IDFEnvironmentVariables.ESP_IDF_VERSION);
keysToRenmove.add(IDFEnvironmentVariables.IDF_CCACHE_ENABLE);
keysToRenmove.add(IDFEnvironmentVariables.IDF_COMPONENT_MANAGER);
keysToRenmove.add(IDFEnvironmentVariables.IDF_MAINTAINER);
keysToRenmove.add(IDFEnvironmentVariables.OPENOCD_SCRIPTS);

for (String key : keysToRenmove)
{
if (environment.containsKey(key))
{
environment.remove(key);
}
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of cleaning up system environment variables, why can't we rely only on the environment variables configured in the IDE and that includes PATH as well?

IDFEnvironmentVariables().getEnvMap()

Otherwise, if we go with the cleanup approach, we'll have to maintain this code all the time whenever there are changes in the IDF environment variables.

Please check?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants