Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 987
fix: block unsafe long-option prefixes (GHSA-2f96-g7mh-g2hx)#2161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -118,8 +118,13 @@ def test_clone_unsafe_options(self, rw_repo): | ||
| unsafe_options = [ | ||
| f"--upload-pack='touch {tmp_file}'", | ||
| f"-u 'touch {tmp_file}'", | ||
| f"-utouch {tmp_file}; false", | ||
| f"-futouch${{IFS}}{tmp_file}; false", | ||
| f"-qutouch${{IFS}}{tmp_file}; false", | ||
| "--config=protocol.ext.allow=always", | ||
| "-c protocol.ext.allow=always", | ||
| "-cprotocol.ext.allow=always", | ||
| "-vcprotocol.ext.allow=always", | ||
| ] | ||
| for unsafe_option in unsafe_options: | ||
| with self.assertRaises(UnsafeOptionError): | ||
| @@ -129,6 +134,7 @@ def test_clone_unsafe_options(self, rw_repo): | ||
| unsafe_options = [ | ||
| {"upload-pack": f"touch {tmp_file}"}, | ||
| {"upload_pack": f"touch {tmp_file}"}, | ||
| {"upload_p": f"touch {tmp_file}"}, | ||
| {"u": f"touch {tmp_file}"}, | ||
| {"config": "protocol.ext.allow=always"}, | ||
| {"c": "protocol.ext.allow=always"}, | ||
| @@ -191,7 +197,9 @@ def test_clone_safe_options(self, rw_repo): | ||
| options = [ | ||
| "--depth=1", | ||
| "--single-branch", | ||
| "--origin upload", | ||
| "-q", | ||
| "-oupstream", | ||
| ] | ||
| for option in options: | ||
| destination = tmp_dir / option | ||
| @@ -207,8 +215,13 @@ def test_clone_from_unsafe_options(self, rw_repo): | ||
| unsafe_options = [ | ||
| f"--upload-pack='touch {tmp_file}'", | ||
| f"-u 'touch {tmp_file}'", | ||
| f"-utouch {tmp_file}; false", | ||
| f"-futouch${{IFS}}{tmp_file}; false", | ||
| f"-qutouch${{IFS}}{tmp_file}; false", | ||
Byron marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| "--config=protocol.ext.allow=always", | ||
| "-c protocol.ext.allow=always", | ||
| "-cprotocol.ext.allow=always", | ||
| "-vcprotocol.ext.allow=always", | ||
| ] | ||
| for unsafe_option in unsafe_options: | ||
| with self.assertRaises(UnsafeOptionError): | ||
| @@ -218,6 +231,7 @@ def test_clone_from_unsafe_options(self, rw_repo): | ||
| unsafe_options = [ | ||
| {"upload-pack": f"touch {tmp_file}"}, | ||
| {"upload_pack": f"touch {tmp_file}"}, | ||
| {"upload_p": f"touch {tmp_file}"}, | ||
| {"u": f"touch {tmp_file}"}, | ||
| {"config": "protocol.ext.allow=always"}, | ||
| {"c": "protocol.ext.allow=always"}, | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -158,10 +158,21 @@ def test_it_transforms_kwargs_into_git_command_arguments(self): | ||
| def test_check_unsafe_options_normalizes_kwargs(self): | ||
| cases = [ | ||
| (["upload_pack"], ["--upload-pack"]), | ||
| (["upload_p"], ["--upload-pack"]), | ||
| (["upload_pac"], ["--upload-pack"]), | ||
| (["receive_pack"], ["--receive-pack"]), | ||
| (["receive_p"], ["--receive-pack"]), | ||
| (["exec"], ["--exec"]), | ||
| (["exe"], ["--exec"]), | ||
| (["u"], ["-u"]), | ||
| (["-utouch /tmp/pwn"], ["-u"]), | ||
| (["-futouch /tmp/pwn"], ["-u"]), | ||
| (["-qutouch${IFS}/tmp/pwn"], ["-u"]), | ||
| (["c"], ["-c"]), | ||
Byron marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| (["-cprotocol.ext.allow=always"], ["-c"]), | ||
| (["-vcprotocol.ext.allow=always"], ["-c"]), | ||
| (["conf"], ["--config"]), | ||
| (["confi"], ["--config"]), | ||
| (["--upload-pack=/tmp/helper"], ["--upload-pack"]), | ||
| (["--config core.filemode=false"], ["--config"]), | ||
| ] | ||
| @@ -170,6 +181,35 @@ def test_check_unsafe_options_normalizes_kwargs(self): | ||
| with self.assertRaises(UnsafeOptionError): | ||
| Git.check_unsafe_options(options=options, unsafe_options=unsafe_options) | ||
| def test_check_unsafe_options_keeps_short_options_exact(self): | ||
| cases = [ | ||
| (["u"], ["--upload-pack"]), | ||
| (["-u helper"], ["--upload-pack"]), | ||
| (["c"], ["--config"]), | ||
| (["-c protocol.ext.allow=always"], ["--config"]), | ||
| (["e"], ["--exec"]), | ||
| (["r"], ["--receive-pack"]), | ||
| ] | ||
| for options, unsafe_options in cases: | ||
| Git.check_unsafe_options(options=options, unsafe_options=unsafe_options) | ||
| def test_check_unsafe_options_ignores_multi_option_values(self): | ||
| Git.check_unsafe_options( | ||
| options=["--origin", "upload"], | ||
| unsafe_options=["--upload-pack", "--config"], | ||
| bare_options_are_long=False, | ||
| ) | ||
| def test_check_unsafe_options_allows_attached_safe_short_option_values(self): | ||
| cases = [ | ||
| ["-oupstream"], | ||
| ["-bcurrent"], | ||
| ] | ||
| for options in cases: | ||
| Git.check_unsafe_options(options=options, unsafe_options=["--upload-pack", "-u", "--config", "-c"]) | ||
| _shell_cases = ( | ||
| # value_in_call, value_from_class, expected_popen_arg | ||
| (None, False, False), | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.