[GH-ISSUE #6399] --private allows writing to the real ~/.bashrc (shell redirect) #3264

Closed
opened 2026-05-05 09:52:21 -06:00 by gitea-mirror · 4 comments
Owner

Originally created by @ghost on GitHub (Jul 6, 2024).
Original GitHub issue: https://github.com/netblue30/firejail/issues/6399

Yesterday on IRC something odd came up regarding the private option. Expecting this option to create a sandbox in which all modifications get discarded at shutdown, it turns out this isn't respected.

The following command variations all allow editing ${HOME}/.bashrc:

$ firejail --private cat >> ~/.bashrc
$ firejail --private --blacklist='${HOME}/.bashrc' cat >> ~/.bashrc
$ firejail --private -- cat >> ~/.bashrc
$ firejail --private --blacklist='${HOME}/.bashrc' -- cat >> ~/.bashrc
$ firejail --private echo "#test" >> ~/.bashrc
$ firejail --private --blacklist='${HOME}/.bashrc' echo "#test" >> ~/.bashrc
$ firejail --private --blacklist='${HOME}/.bashrc' -- echo "#test" >> ~/.bashrc

So, to summarize:

  • setting ${HOME}/.bashrc read-only via disable-common.inc (included from default.profile) is not being enforced;
  • the ${HOME}/.bashrc modifications survive sandbox shutdown, allthough private shouldn't allow this;
  • explicitly blacklisting ${HOME}/.bashrc is not preventing this from happening.

This easy and unexpected circumvention of the above restrictions make me wonder what is actually causing this (besides apparent shell redirection). I could use a sanity check here :)

Note: I'm seeing this on my firejail-git, but a user confirmed this also happens on 0.9.72.

Originally created by @ghost on GitHub (Jul 6, 2024). Original GitHub issue: https://github.com/netblue30/firejail/issues/6399 Yesterday on IRC something odd came up regarding the `private` option. Expecting this option to create a sandbox in which all modifications get `discarded` at shutdown, it turns out this isn't respected. The following command variations all allow editing ${HOME}/.bashrc: ```sh $ firejail --private cat >> ~/.bashrc $ firejail --private --blacklist='${HOME}/.bashrc' cat >> ~/.bashrc $ firejail --private -- cat >> ~/.bashrc $ firejail --private --blacklist='${HOME}/.bashrc' -- cat >> ~/.bashrc $ firejail --private echo "#test" >> ~/.bashrc $ firejail --private --blacklist='${HOME}/.bashrc' echo "#test" >> ~/.bashrc $ firejail --private --blacklist='${HOME}/.bashrc' -- echo "#test" >> ~/.bashrc ``` So, to summarize: - setting ${HOME}/.bashrc `read-only` via `disable-common.inc` (included from `default.profile`) is not being enforced; - the ${HOME}/.bashrc modifications survive sandbox shutdown, allthough `private` shouldn't allow this; - explicitly `blacklisting` ${HOME}/.bashrc is not preventing this from happening. This easy and unexpected circumvention of the above restrictions make me wonder what is actually causing this (besides apparent shell redirection). I could use a sanity check here :) Note: I'm seeing this on my `firejail-git`, but a user confirmed this also happens on `0.9.72`.
gitea-mirror 2026-05-05 09:52:21 -06:00
  • closed this issue
  • added the
    notabug
    label
Author
Owner

@rusty-snake commented on GitHub (Jul 6, 2024):

Shell redirection is a feature of your shell. i.e. the process that writes to ~/.bashrc in the following process tree is the bash process that wraps/starts firejail.

-bash
|-firejail --private
  |-cat
<!-- gh-comment-id:2211783648 --> @rusty-snake commented on GitHub (Jul 6, 2024): Shell redirection is a feature of your shell. i.e. the process that writes to `~/.bashrc` in the following process tree is the bash process that wraps/starts firejail. ``` -bash |-firejail --private |-cat ```
Author
Owner

@kmk3 commented on GitHub (Jul 6, 2024):

@rusty-snake on Jul 6:

Shell redirection is a feature of your shell. i.e. the process that writes to
~/.bashrc in the following process tree is the bash process that
wraps/starts firejail.

The shell indeed opens the file and sets up the redirection before firejail
starts, though I think that technically the child process is still the one that
writes to the stream.

@glitsj16

Can you reproduce this without shell redirects?

<!-- gh-comment-id:2211895127 --> @kmk3 commented on GitHub (Jul 6, 2024): @rusty-snake [on Jul 6](https://github.com/netblue30/firejail/issues/6399#issuecomment-2211783648): > Shell redirection is a feature of your shell. i.e. the process that writes to > `~/.bashrc` in the following process tree is the bash process that > wraps/starts firejail. The shell indeed opens the file and sets up the redirection before firejail starts, though I think that technically the child process is still the one that writes to the stream. @glitsj16 Can you reproduce this without shell redirects?
Author
Owner

@rusty-snake commented on GitHub (Jul 6, 2024):

Well, technically your right. Though it only helps if you understand the difference between open and read/write.

<!-- gh-comment-id:2211910271 --> @rusty-snake commented on GitHub (Jul 6, 2024): Well, technically your right. Though it only helps if you understand the difference between open and read/write.
Author
Owner

@ghost commented on GitHub (Jul 7, 2024):

Can you reproduce this without shell redirects?

All good without shell redirection:

$ firejail --quiet --private -- sh -c 'echo "#test" >> "${HOME}/.bashrc"'
sh: line 1: /home/glitsj16/.bashrc: Read-only file system
firejail --quiet --private --blacklist="${HOME}/.bashrc" -- sh -c 'echo "#test" >> "${HOME}/.bashrc"'
sh: line 1: /home/glitsj16/.bashrc: Permission denied

Sorry for the noise.

<!-- gh-comment-id:2212312929 --> @ghost commented on GitHub (Jul 7, 2024): > Can you reproduce this without shell redirects? All good without shell redirection: ```sh $ firejail --quiet --private -- sh -c 'echo "#test" >> "${HOME}/.bashrc"' sh: line 1: /home/glitsj16/.bashrc: Read-only file system ``` ```sh firejail --quiet --private --blacklist="${HOME}/.bashrc" -- sh -c 'echo "#test" >> "${HOME}/.bashrc"' sh: line 1: /home/glitsj16/.bashrc: Permission denied ``` Sorry for the noise.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#3264
No description provided.