Skip to content

Use shlex to quote environment variables#307

Merged
Dramelac merged 1 commit into
ThePorgs:devfrom
Hackndo:patch-1
Jul 19, 2026
Merged

Use shlex to quote environment variables#307
Dramelac merged 1 commit into
ThePorgs:devfrom
Hackndo:patch-1

Conversation

@Hackndo

@Hackndo Hackndo commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Problem

When opening a shell on a container with -e/--env, Exegol builds the docker exec command as a single string and runs it through os.system(), which executes it via /bin/sh. The environment values are interpolated without any quoting:

options += f" -e {' -e '.join(envs)}"
if spawn_all_capabilities:
options += " --privileged"
cmd = f"docker exec{options} -ti {self.getFullId()} {self.config.getShellCommand()}"

As soon as an environment value contains a character that is special to the shell, the command breaks.

Reproduction

export MYVAR='abc;def #ghi'
exegol start mycontainer -e MYVAR

[*] Creating new exegol container
[+] Exegol container successfully created!
[+] Successfully deployed my-resources!
[*] Location of the exegol workspace on the host : /home/pixis/.exegol/workspaces/mycontainer
[+] Opening zsh shell in Exegol mycontainer
[+] Using system value for env MYVAR.
docker: 'docker exec' requires at least 2 arguments

Usage:  docker exec [OPTIONS] CONTAINER COMMAND [ARG...]

See 'docker exec --help' for more information
sh: 1: def: not found

The ; terminates the docker exec invocation early (so Docker complains about missing arguments), and the remainder of the value is executed by the shell as a separate command.

This can be weaponized like so by executing arbitrary command on the host

$ MYVAR='$(echo owned > /tmp/pwned)'
$ exegol start mycontainer -e MYVAR
[*] Exegol Enterprise is currently in version v5.1.10
[*] More about Exegol at: https://exegol.com
[*] Skipping interactive mode (arguments supplied)
[*] Location of the exegol workspace on the host : /home/pixis/.exegol/workspaces/mycontainer
[+] Opening zsh shell in Exegol mycontainer
[+] Using system value for env MYVAR.
[Jun 19, 2026 - 14:04:43 (CEST)] exegol-mycontainer /workspace # exit
$ cat /tmp/pwned
owned

Fix

Shell-quote each environment entry with shlex.quote() before building the command string.

options += " " + " ".join(f"-e {shlex.quote(env)}" for env in envs)

@Dramelac
Dramelac changed the base branch from master to dev July 19, 2026 11:16

@Dramelac Dramelac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix!

@Dramelac
Dramelac merged commit cf3c34d into ThePorgs:dev Jul 19, 2026
3 of 4 checks passed
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.

3 participants