What was wrong: a replace commit_config() and rollback() wrote the config as root to a fixed name in /tmp (/tmp/napalm_candidate.uci, /tmp/napalm_rollback.uci) and imported it with a second command. A local account could place that file (or a symlink) beforehand, or swap it in between, and have its own config imported and committed. Found in NetOrk/netork#2446.
Fix:_uci_import_command() builds one command per import: f=$(umask 077 && mktemp) && { printf '%s' <config, shlex-quoted> > "$f" && uci import < "$f" && uci commit; rm -f "$f"; }. The file is removed whether the import worked or not; the import's output still reaches the error check.
Tests:tests/unit/test_config_import_tempfile.py — commit (replace) and rollback each send one import command through a private mktemp file, no /tmp name, with the config as one word, single quotes included (red before the fix). Checked the command in a real sh with a stand-in uci: the config arrives intact, the file is mode 600 and is gone afterwards.
Merge note: #44 (set_hostname quoting) also adds to the Unreleased ### Fixed section of the CHANGELOG; whichever goes second needs a trivial merge there.
**What was wrong:** a replace `commit_config()` and `rollback()` wrote the config as root to a fixed name in /tmp (`/tmp/napalm_candidate.uci`, `/tmp/napalm_rollback.uci`) and imported it with a second command. A local account could place that file (or a symlink) beforehand, or swap it in between, and have its own config imported and committed. Found in NetOrk/netork#2446.
**Fix:** `_uci_import_command()` builds one command per import: `f=$(umask 077 && mktemp) && { printf '%s' <config, shlex-quoted> > "$f" && uci import < "$f" && uci commit; rm -f "$f"; }`. The file is removed whether the import worked or not; the import's output still reaches the error check.
**Tests:** `tests/unit/test_config_import_tempfile.py` — commit (replace) and rollback each send one import command through a private mktemp file, no /tmp name, with the config as one word, single quotes included (red before the fix). Checked the command in a real `sh` with a stand-in `uci`: the config arrives intact, the file is mode 600 and is gone afterwards.
Merge note: #44 (set_hostname quoting) also adds to the Unreleased `### Fixed` section of the CHANGELOG; whichever goes second needs a trivial merge there.
Closes #45
A replace commit_config() and rollback() wrote the config as root to a
fixed name in /tmp (/tmp/napalm_candidate.uci, /tmp/napalm_rollback.uci)
and imported it with a second command. A local account could place that
file beforehand, or swap it in between, and have its own config imported
and committed (NetOrk/netork#2446).
Each import is now one command: a mktemp file made under umask 077, the
config written to it, `uci import < "$f" && uci commit`, then the file
removed.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What was wrong: a replace
commit_config()androllback()wrote the config as root to a fixed name in /tmp (/tmp/napalm_candidate.uci,/tmp/napalm_rollback.uci) and imported it with a second command. A local account could place that file (or a symlink) beforehand, or swap it in between, and have its own config imported and committed. Found in NetOrk/netork#2446.Fix:
_uci_import_command()builds one command per import:f=$(umask 077 && mktemp) && { printf '%s' <config, shlex-quoted> > "$f" && uci import < "$f" && uci commit; rm -f "$f"; }. The file is removed whether the import worked or not; the import's output still reaches the error check.Tests:
tests/unit/test_config_import_tempfile.py— commit (replace) and rollback each send one import command through a private mktemp file, no /tmp name, with the config as one word, single quotes included (red before the fix). Checked the command in a realshwith a stand-inuci: the config arrives intact, the file is mode 600 and is gone afterwards.Merge note: #44 (set_hostname quoting) also adds to the Unreleased
### Fixedsection of the CHANGELOG; whichever goes second needs a trivial merge there.Closes #45