You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Extensions can modify the environment variables of the integrated terminal using environmentVariableCollection. In particular an extension can append or prepend a value to an existing environment variable; most notably this allows extensions to add directories to the PATH in order to make relevant commands available in the terminal.
With the potential exception of environment variables overridden in the TerminalOptions passed when creating the terminal, the integrated terminal will inherit the environment variables of the parent process. However, once an extension appends or prepends a value to such an inherited environment variable, instead of concatenating the previous value and the appended or prepended value, the previous value is actually replaced by the value that was meant to be appended / prepended.
This is particularly problematic when the variable in question is the PATH: if the user happens to activate an extension that (innocently) modifies the PATH, every terminal opened from that point on will suddenly have its PATH reduced to the value added by the extension, meaning most commands that were previously available will not work anymore.
I believe this issue does not happen when the environment variable is set in TerminalOptions.
But in applyToProcessEnvironment on lines 255 and 258, if the environment variable modified by an extension is not in the initial map, then an the value is prepended or appended to an empty string. It should instead be be prepended or appended to the environment variable inherited from the parent process.
The text was updated successfully, but these errors were encountered:
Hi @xavth,
Your description above is excellent, and the provided plugin really helps,
To continue the story, the provided variable customization is then applied to the process environment variables, see [1],
This could have pretty bad consequences if e.g. the PATH variable is being affected as seen in [2].
I am looking at a solution where the environment variables to be applied to the process get initialized before calling applyToProcessEnvironment.
Bug Description
Context
Extensions can modify the environment variables of the integrated terminal using
environmentVariableCollection
. In particular an extension canappend
orprepend
a value to an existing environment variable; most notably this allows extensions to add directories to thePATH
in order to make relevant commands available in the terminal.This feature was added to Theia in #8523.
Description
With the potential exception of environment variables overridden in the
TerminalOptions
passed when creating the terminal, the integrated terminal will inherit the environment variables of the parent process. However, once an extensionappends
orprepends
a value to such an inherited environment variable, instead of concatenating the previous value and the appended or prepended value, the previous value is actually replaced by the value that was meant to be appended / prepended.This is particularly problematic when the variable in question is the
PATH
: if the user happens to activate an extension that (innocently) modifies thePATH
, every terminal opened from that point on will suddenly have itsPATH
reduced to the value added by the extension, meaning most commands that were previously available will not work anymore.I believe this issue does not happen when the environment variable is set in
TerminalOptions
.Steps to Reproduce
I use the demo extension https://lab.nexedi.com/jerome/demo-environmentvariablecollection to demonstrate this bug in Gitpod:
build_theia_from_master.mp4
SOME_VARIABLE
in the example):start_theia_and_check_environment_variable.mp4
download_extension_vsix.mp4
install_demo_extension_from_vsix.mp4
path/number/four
toSOME_VARIABLE
:View -> Find Command
(Ctrl+Shift+P
)Demo environmentVariableCollection API
Append to terminal environment variable
SOME_VARIABLE
and hitEnter
path/number/four
and hitEnter
append_to_environment_variable_and_check_result.mp4
The expected value would have been
path/number/one:path/number/two:path/number/three:path/number/four
.Likely cause
Below is what I could figure out:
The
applyToProcessEnvironment
method at https://github.com/eclipse-theia/theia/blob/v1.12.1/packages/terminal/src/node/base-terminal-server.ts#L244 is where the various environment variable modifications requested by extensions are applied to the environment map that will later be used to set the terminal environment.The initial environment map passed to
applyToProcessEnvironment
is just the map of overridden environment variables set inTerminalOptions
, as can be seen here https://github.com/eclipse-theia/theia/blob/v1.12.1/packages/terminal/src/node/shell-terminal-server.ts#L39, meaning it's potentially just an empty map, and that it doesn't contain all the environment variables of the parent process.But in
applyToProcessEnvironment
on lines 255 and 258, if the environment variable modified by an extension is not in the initial map, then an the value is prepended or appended to an empty string. It should instead be be prepended or appended to the environment variable inherited from the parent process.The text was updated successfully, but these errors were encountered: