Skip to content

--clearenv leaks environment #725

Open
pratikpawar009/bubblewrap
#2

Description

@niansa

Hi,

You'd expect --unshare-pid --proc /proc --clearenv to safely hide all environment variables. However, when not using --as-pid-1, the environment is leaked in /proc/1/environ!

Not sure if this is actually relevant security wise, but I'd better hope nobody is using --clearenv to clear sensitive environment variables!

Activity

  1. changed the title [-]--clearenv leaks environment[/-] [+]`--clearenv` leaks environment[/+] on Jan 8, 2026
  2. added a commit that references this issue on Sep 17, 2026
    f99cfd6
  3. smcv commented on Sep 18, 2026

    @smcv
    Collaborator

    Not sure if this is actually relevant security wise, but I'd better hope nobody is using --clearenv to clear sensitive environment variables!

    I don't think bubblewrap ever intended it to be a security guarantee that --unsetenv or --clearenv would make the environment variables' values not visible to processes inside the container - I'd always seen it as a way to clear environment variables that are functionally inappropriate for the container (for example when a Flatpak app swaps to a different /usr, it needs to clear the LD_LIBRARY_PATH).

    As a general design principle, I would recommend reducing the scope of sensitive environment variables to be as narrow as possible, and preferring to reference a file containing secrets (for example this is how $XAUTHORITY and $DOCKER_CONFIG work) rather than directly putting the secret in the environment variable.

  4. chjj commented on Sep 19, 2026

    @chjj

    I don't think bubblewrap ever intended it to be a security guarantee that --unsetenv or --clearenv would make the environment variables' values not visible to processes inside the container

    Perhaps that could be stated in the man page? e.g. "warning: --clearenv is not a security feature. sanitize your own environment beforehand"

    Judging by the number of PR references to this issue, it seems people thought --clearenv was a security feature, and the confusion is understandable.

  5. swick commented on Sep 21, 2026

    @swick
    Contributor

    Personally, I would appreciate if --clearenv actually made the environment of the caller inaccessible.

  6. karthik20066002 commented on Sep 24, 2026

    @karthik20066002

    well, there's quite a few PR's already, can I help out if needed?

  7. added a commit that references this issue on Sep 25, 2026
    76dfe5c
  8. chjj commented on Sep 27, 2026

    @chjj

    Also, as an aside, /proc/1/cmdline will leak the original bwrap commandline, allowing an attacker to infer details about the host machine and the sandbox itself. Not as scary as the env leak, but it's still probably best to use an --args FD to hide the commandline.

  9. smcv commented on Sep 27, 2026

    @smcv
    Collaborator

    @shleder, please don't use another project's issue tracker as somewhere to advertise your vaguely related project.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions