diff --git a/NEWS b/NEWS index a5d32dbb..b0e0047c 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ * When syslog verbosity is enabled, log to systemd's journal (if present) with structured data. See the documentation for more information: https://torsion.org/borgmatic/reference/command-line/logging/#systemd-journal + * SECURITY: Prevent shell injection attacks via constant interpolation in command hooks. (This was + already implemented for deprecated "before_*"/"after_*" command hooks.) * Promote the ZFS, LVM, and Btrfs hooks from beta features to stable. 2.0.13 diff --git a/borgmatic/config/constants.py b/borgmatic/config/constants.py index 876d986e..806e656f 100644 --- a/borgmatic/config/constants.py +++ b/borgmatic/config/constants.py @@ -58,7 +58,7 @@ def apply_constants(value, constants, shell_escape=False): shell_escape=( shell_escape or option_name.startswith(('before_', 'after_')) - or option_name == 'on_error' + or option_name in {'on_error', 'run'} ), ) diff --git a/tests/unit/config/test_constants.py b/tests/unit/config/test_constants.py index a4c69631..d475902b 100644 --- a/tests/unit/config/test_constants.py +++ b/tests/unit/config/test_constants.py @@ -50,6 +50,7 @@ def test_apply_constants_with_empty_constants_passes_through_value(): ({'before_backup': '{inject}'}, {'before_backup': "'echo hi; naughty-command'"}), ({'after_backup': '{inject}'}, {'after_backup': "'echo hi; naughty-command'"}), ({'on_error': '{inject}'}, {'on_error': "'echo hi; naughty-command'"}), + ({'run': '{inject}'}, {'run': "'echo hi; naughty-command'"}), ( { 'before_backup': '{env_pass}',