From 701ce32fe5ba8cb622c0e0342a376a6beb47d738 Mon Sep 17 00:00:00 2001
From: "GPT 5.6" <codex@openai.com>
Date: Sun, 12 Jul 2026 15:06:42 +0200
Subject: [PATCH] fix: Guard unsafe git command options (GHSA-956x-8gvw-wg5v)

Reject command options that can execute arbitrary helpers or write files when passed through archive, revision traversal, blame, clone, fetch, pull, push, and ls-remote APIs. Validate positional option tokens and transformed keyword options consistently, including Git-supported long-option abbreviations, attached short-option values, and falsey stringifiable remotes. Preserve explicit allow_unsafe_options and allow_unsafe_protocols escape hatches.

Add regression coverage for each guarded API, option spelling and abbreviation forms, inert keyword values, mixed positional and keyword candidates, tuple blame options, stringifiable remotes, and unsafe commands that must not create marker files.

Reviewed-by: Sebastian Thiel <sebastian.thiel@icloud.com>
---
 git/cmd.py            | 37 +++++++++++++++++++-
 git/objects/commit.py | 12 +++++++
 git/remote.py         | 15 ++++++--
 git/repo/base.py      | 80 +++++++++++++++++++++++++++++++++++++++----
 test/test_clone.py    |  4 +++
 test/test_commit.py   | 13 +++++++
 test/test_git.py      | 16 +++++++++
 test/test_remote.py   | 43 ++++++++++++++++++++++-
 test/test_repo.py     | 71 ++++++++++++++++++++++++++++++++++++++
 9 files changed, 279 insertions(+), 12 deletions(-)

Index: GitPython-3.1.34.1693646983.2a2ae77/git/cmd.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/git/cmd.py
+++ GitPython-3.1.34.1693646983.2a2ae77/git/cmd.py
@@ -267,6 +267,11 @@ class Git(LazyMixin):
 
     re_unsafe_protocol = re.compile("(.+)::.+")
 
+    unsafe_git_ls_remote_options = [
+        # This option allows arbitrary command execution in git-ls-remote.
+        "--upload-pack",
+    ]
+
     def __getstate__(self) -> Dict[str, Any]:
         return slots_to_dict(self, exclude=self._excluded_)
 
@@ -558,6 +563,20 @@ class Git(LazyMixin):
                         f"{unsafe_option} is not allowed, use `allow_unsafe_options=True` to allow it."
                     )
 
+    @classmethod
+    def _option_candidates(cls, args: Sequence[Any] = (), kwargs: Optional[Mapping[str, Any]] = None) -> List[str]:
+        """Collect possible option spellings before command-line transformation."""
+        options = [
+            option for option in cls._unpack_args([arg for arg in args if arg is not None]) if option.startswith("-")
+        ]
+        if kwargs:
+            for key, value in kwargs.items():
+                values = value if isinstance(value, (list, tuple)) else (value,)
+                if any(value is True or (value is not False and value is not None) for value in values):
+                    key = str(key)
+                    options.append(f"-{key}" if len(key) == 1 else f"--{dashify(key)}")
+        return options
+
 
     class AutoInterrupt(object):
         """Kill/Interrupt the stored process instance once this instance goes out of scope. It is
@@ -832,6 +851,22 @@ class Git(LazyMixin):
         """:return: Git directory we are working on"""
         return self._working_dir
 
+    def ls_remote(
+        self,
+        *args: Any,
+        allow_unsafe_options: bool = False,
+        **kwargs: Any,
+    ) -> Union[str, bytes, Tuple[int, Union[str, bytes], str], "Git.AutoInterrupt"]:
+        """List references in a remote repository.
+
+        :param allow_unsafe_options:
+            Allow unsafe options, like ``--upload-pack``.
+        """
+        if not allow_unsafe_options:
+            candidate_options = self._option_candidates(args, kwargs)
+            Git.check_unsafe_options(options=candidate_options, unsafe_options=self.unsafe_git_ls_remote_options)
+        return self._call_process("ls_remote", *args, **kwargs)
+
     @property
     def version_info(self) -> Tuple[int, int, int, int]:
         """
@@ -1256,7 +1291,7 @@ class Git(LazyMixin):
         return args
 
     @classmethod
-    def _unpack_args(cls, arg_list: Sequence[str]) -> List[str]:
+    def _unpack_args(cls, arg_list: Sequence[Any]) -> List[str]:
         outlist = []
         if isinstance(arg_list, (list, tuple)):
             for arg in arg_list:
Index: GitPython-3.1.34.1693646983.2a2ae77/git/objects/commit.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/git/objects/commit.py
+++ GitPython-3.1.34.1693646983.2a2ae77/git/objects/commit.py
@@ -76,6 +76,12 @@ class Commit(base.Object, TraversableIte
     # INVARIANTS
     default_encoding = "UTF-8"
 
+    # Options to :manpage:`git-rev-list(1)` that can overwrite files.
+    unsafe_git_rev_options = [
+        "--output",
+        "-o",
+    ]
+
     # object configuration
     type: Literal["commit"] = "commit"
     __slots__ = (
@@ -265,6 +271,7 @@ class Commit(base.Object, TraversableIte
         repo: "Repo",
         rev: Union[str, "Commit", "SymbolicReference"],  # type: ignore
         paths: Union[PathLike, Sequence[PathLike]] = "",
+        allow_unsafe_options: bool = False,
         **kwargs: Any,
     ) -> Iterator["Commit"]:
         """Find all commits matching the given criteria.
@@ -284,6 +291,11 @@ class Commit(base.Object, TraversableIte
             raise ValueError("--pretty cannot be used as parsing expects single sha's only")
         # END handle pretty
 
+        if not allow_unsafe_options:
+            Git.check_unsafe_options(
+                options=Git._option_candidates([rev], kwargs), unsafe_options=cls.unsafe_git_rev_options
+            )
+
         # use -- in any case, to prevent possibility of ambiguous arguments
         # see https://github.com/gitpython-developers/GitPython/issues/264
 
Index: GitPython-3.1.34.1693646983.2a2ae77/git/remote.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/git/remote.py
+++ GitPython-3.1.34.1693646983.2a2ae77/git/remote.py
@@ -1006,7 +1006,10 @@ class Remote(LazyMixin, IterableObj):
                     Git.check_unsafe_protocols(ref)
 
         if not allow_unsafe_options:
-            Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=self.unsafe_git_fetch_options)
+            Git.check_unsafe_options(
+                options=Git._option_candidates([], kwargs),
+                unsafe_options=self.unsafe_git_fetch_options,
+            )
 
         proc = self.repo.git.fetch(
             "--", self, *args, as_process=True, with_stdout=False, universal_newlines=True, v=verbose, **kwargs
@@ -1046,7 +1049,10 @@ class Remote(LazyMixin, IterableObj):
                 Git.check_unsafe_protocols(ref)
 
         if not allow_unsafe_options:
-            Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=self.unsafe_git_pull_options)
+            Git.check_unsafe_options(
+                options=Git._option_candidates([], kwargs),
+                unsafe_options=self.unsafe_git_pull_options,
+            )
 
         proc = self.repo.git.pull(
             "--", self, refspec, with_stdout=False, as_process=True, universal_newlines=True, v=True, **kwargs
@@ -1102,7 +1108,10 @@ class Remote(LazyMixin, IterableObj):
                 Git.check_unsafe_protocols(ref)
 
         if not allow_unsafe_options:
-            Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=self.unsafe_git_push_options)
+            Git.check_unsafe_options(
+                options=Git._option_candidates([], kwargs),
+                unsafe_options=self.unsafe_git_push_options,
+            )
 
         proc = self.repo.git.push(
             "--",
Index: GitPython-3.1.34.1693646983.2a2ae77/git/repo/base.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/git/repo/base.py
+++ GitPython-3.1.34.1693646983.2a2ae77/git/repo/base.py
@@ -149,6 +149,20 @@ class Repo(object):
         "-c",
     ]
 
+    unsafe_git_archive_options = [
+        # Allows arbitrary command execution through the remote git-upload-archive command.
+        "--exec",
+        # Writes output to a caller-controlled filesystem path.
+        "--output",
+        "-o",
+    ]
+
+    unsafe_git_revision_options = [
+        # This option allows output to be written to arbitrary files before revision parsing.
+        "--output",
+        "-o",
+    ]
+
     # invariants
     # represents the configuration level of a configuration file
     config_level: ConfigLevels_Tup = ("system", "user", "global", "repository")
@@ -639,6 +653,7 @@ class Repo(object):
         self,
         rev: Union[str, Commit, "SymbolicReference", None] = None,
         paths: Union[PathLike, Sequence[PathLike]] = "",
+        allow_unsafe_options: bool = False,
         **kwargs: Any,
     ) -> Iterator[Commit]:
         """A list of Commit objects representing the history of a given ref/commit
@@ -658,11 +673,25 @@ class Repo(object):
         :note: to receive only commits between two named revisions, use the
             "revA...revB" revision specifier
 
+        :param allow_unsafe_options:
+            Allow unsafe options in the revision argument, like ``--output``.
+
         :return: ``git.Commit[]``"""
         if rev is None:
             rev = self.head.commit
 
-        return Commit.iter_items(self, rev, paths, **kwargs)
+        if not allow_unsafe_options:
+            Git.check_unsafe_options(
+                options=Git._option_candidates([rev], kwargs), unsafe_options=self.unsafe_git_revision_options
+            )
+
+        return Commit.iter_items(
+            self,
+            rev,
+            paths,
+            allow_unsafe_options=allow_unsafe_options,
+            **kwargs,
+        )
 
     def merge_base(self, *rev: TBD, **kwargs: Any) -> List[Union[Commit_ish, None]]:
         """Find the closest common ancestor for the given revision (e.g. Commits, Tags, References, etc)
@@ -839,6 +868,9 @@ class Repo(object):
             Files currently untracked as they have not been staged yet. Paths
             are relative to the current working directory of the git command.
 
+        :param allow_unsafe_options:
+            Allow unsafe options in the revision argument, like ``--output``.
+
         :note:
             ignored files will not appear here, i.e. files mentioned in .gitignore
         :note:
@@ -895,7 +927,9 @@ class Repo(object):
         # reveal_type(self.head.reference)  # => Reference
         return self.head.reference
 
-    def blame_incremental(self, rev: str | HEAD, file: str, **kwargs: Any) -> Iterator["BlameEntry"]:
+    def blame_incremental(
+        self, rev: str | HEAD | None, file: str, allow_unsafe_options: bool = False, **kwargs: Any
+    ) -> Iterator["BlameEntry"]:
         """Iterator for blame information for the given file at the given revision.
 
         Unlike .blame(), this does not return the actual file's contents, only
@@ -906,9 +940,16 @@ class Repo(object):
                  indicates the commit to blame for the line, and range
                  indicates a span of line numbers in the resulting file.
 
+        :param allow_unsafe_options:
+            Allow unsafe options in revision argument, like ``--output``.
+
         If you combine all line number ranges outputted by this command, you
         should get a continuous range spanning all line numbers in the file.
         """
+        if not allow_unsafe_options:
+            Git.check_unsafe_options(
+                options=Git._option_candidates([rev], kwargs), unsafe_options=self.unsafe_git_revision_options
+            )
 
         data: bytes = self.git.blame(rev, "--", file, p=True, incremental=True, stdout_as_string=False, **kwargs)
         commits: Dict[bytes, Commit] = {}
@@ -985,21 +1026,29 @@ class Repo(object):
         rev: Union[str, HEAD],
         file: str,
         incremental: bool = False,
-        rev_opts: Optional[List[str]] = None,
+        rev_opts: Optional[Sequence[str]] = None,
+        allow_unsafe_options: bool = False,
         **kwargs: Any,
     ) -> List[List[Commit | List[str | bytes] | None]] | Iterator[BlameEntry] | None:
         """The blame information for the given file at the given revision.
 
         :param rev: revision specifier, see git-rev-parse for viable options.
+        :param allow_unsafe_options:
+            Allow unsafe options in revision argument, like ``--output``.
         :return:
             list: [git.Commit, list: [<line>]]
             A list of lists associating a Commit object with a list of lines that
             changed within the given commit. The Commit objects will be given in order
             of appearance."""
         if incremental:
-            return self.blame_incremental(rev, file, **kwargs)
-        rev_opts = rev_opts or []
-        data: bytes = self.git.blame(rev, *rev_opts, "--", file, p=True, stdout_as_string=False, **kwargs)
+            return self.blame_incremental(rev, file, allow_unsafe_options=allow_unsafe_options, **kwargs)
+        rev_opts_list = list(rev_opts or [])
+        if not allow_unsafe_options:
+            Git.check_unsafe_options(
+                options=Git._option_candidates([rev, rev_opts_list], kwargs),
+                unsafe_options=self.unsafe_git_revision_options,
+            )
+        data: bytes = self.git.blame(rev, *rev_opts_list, "--", file, p=True, stdout_as_string=False, **kwargs)
         commits: Dict[str, Commit] = {}
         blames: List[List[Commit | List[str | bytes] | None]] = []
 
@@ -1204,7 +1253,10 @@ class Repo(object):
         if not allow_unsafe_protocols:
             Git.check_unsafe_protocols(str(url))
         if not allow_unsafe_options:
-            Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=cls.unsafe_git_clone_options)
+            Git.check_unsafe_options(
+                options=Git._option_candidates([], kwargs),
+                unsafe_options=cls.unsafe_git_clone_options,
+            )
         if not allow_unsafe_options and multi:
             Git.check_unsafe_options(options=multi, unsafe_options=cls.unsafe_git_clone_options)
 
@@ -1341,6 +1393,8 @@ class Repo(object):
         ostream: Union[TextIO, BinaryIO],
         treeish: Optional[str] = None,
         prefix: Optional[str] = None,
+        allow_unsafe_options: bool = False,
+        allow_unsafe_protocols: bool = False,
         **kwargs: Any,
     ) -> Repo:
         """Archive the tree at the given revision.
@@ -1355,12 +1409,26 @@ class Repo(object):
             * You may specify the special **path** keyword, which may either be a repository-relative
               path to a directory or file to place into the archive, or a list or tuple of multiple paths.
 
+        :param allow_unsafe_options:
+            Allow unsafe options, like ``--exec`` or ``--output``.
+
+        :param allow_unsafe_protocols:
+            Allow unsafe protocols to be used in ``remote``, like ``ext``.
+
         :raise GitCommandError: in case something went wrong
         :return: self"""
         if treeish is None:
             treeish = self.head.commit
         if prefix and "prefix" not in kwargs:
             kwargs["prefix"] = prefix
+        remote = kwargs.get("remote")
+        if not allow_unsafe_protocols and remote is not None:
+            Git.check_unsafe_protocols(str(remote))
+        if not allow_unsafe_options:
+            Git.check_unsafe_options(
+                options=Git._option_candidates([], kwargs),
+                unsafe_options=self.unsafe_git_archive_options,
+            )
         kwargs["output_stream"] = ostream
         path = kwargs.pop("path", [])
         path = cast(Union[PathLike, List[PathLike], Tuple[PathLike, ...]], path)
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_clone.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_clone.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_clone.py
@@ -114,11 +114,13 @@ class TestClone(TestBase):
             tmp_file = tmp_dir / "pwn"
             unsafe_options = [
                 f"--upload-pack='touch {tmp_file}'",
+                f"--upl='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",
+                "--conf=protocol.ext.allow=always",
                 "-c protocol.ext.allow=always",
                 "-cprotocol.ext.allow=always",
                 "-vcprotocol.ext.allow=always",
@@ -130,8 +132,11 @@ class TestClone(TestBase):
 
             unsafe_options = [
                 {"upload-pack": f"touch {tmp_file}"},
+                {"upload_pack": f"touch {tmp_file}"},
+                {"upl": f"touch {tmp_file}"},
                 {"u": f"touch {tmp_file}"},
                 {"config": "protocol.ext.allow=always"},
+                {"conf": "protocol.ext.allow=always"},
                 {"c": "protocol.ext.allow=always"},
             ]
             for unsafe_option in unsafe_options:
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_commit.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_commit.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_commit.py
@@ -7,6 +7,7 @@
 import copy
 from datetime import datetime
 from io import BytesIO
+import tempfile
 import re
 import sys
 import time
@@ -17,6 +18,7 @@ from git import (
     Actor,
 )
 from git import Repo
+from git.exc import UnsafeOptionError
 from git.objects.util import tzoffset, utc
 from git.repo.fun import touch
 from test.lib import TestBase, with_rw_repo, fixture_path, StringProcessAdapter
@@ -284,6 +286,17 @@ class TestCommit(TestCommitSerialization
         # pretty not allowed
         self.assertRaises(ValueError, Commit.iter_items, self.rorepo, "master", pretty="raw")
 
+    def test_iter_items_rejects_unsafe_revision(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            marker = osp.join(tdir, "pwn")
+            self.assertRaises(UnsafeOptionError, Commit.iter_items, self.rorepo, f"--output={marker}")
+
+    def test_iter_items_rejects_unsafe_options(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            marker = osp.join(tdir, "pwn")
+            with self.assertRaises(UnsafeOptionError):
+                list(Commit.iter_items(self.rorepo, "HEAD", output=marker))
+
     def test_rev_list_bisect_all(self):
         """
         'git rev-list --bisect-all' returns additional information
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_git.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_git.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_git.py
@@ -95,6 +95,9 @@ class TestGit(TestBase):
             (["c"], ["-c"]),
             (["--upload-pack=/tmp/helper"], ["--upload-pack"]),
             (["--config core.filemode=false"], ["--config"]),
+            (["--upl=/tmp/helper"], ["--upload-pack"]),
+            (["conf"], ["--config"]),
+            (["--out=/tmp/output"], ["--output"]),
         ]
 
         for options, unsafe_options in cases:
@@ -129,6 +132,18 @@ class TestGit(TestBase):
 
         Git.check_unsafe_options(options=["-oupstream", "-bcurrent"], unsafe_options=unsafe_options)
 
+    def test_option_candidates_ignore_untransformed_kwargs(self):
+        options = Git._option_candidates(
+            kwargs={
+                "output": None,
+                "upload_pack": False,
+                "exec": [],
+                "config": [None, False],
+                "max_count": 1,
+            }
+        )
+
+        self.assertEqual(options, ["--max-count"])
 
     def test_it_executes_git_to_shell_and_returns_result(self):
         self.assertRegex(self.git.execute(["git", "version"]), r"^git version [\d\.]{2}.*$")
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_remote.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_remote.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_remote.py
@@ -8,7 +8,7 @@ import os
 import random
 import tempfile
 import pytest
-from unittest import skipIf
+from unittest import mock, skipIf
 
 from git import (
     RemoteProgress,
@@ -979,6 +979,47 @@ class TestRemote(TestBase):
                 assert tmp_file.exists()
                 tmp_file.unlink()
 
+    @with_rw_repo("HEAD")
+    def test_ls_remote_unsafe_options(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            unsafe_options = [
+                {"upload-pack": f"touch {tmp_file}"},
+                {"upload_pack": f"touch {tmp_file}"},
+                {"upl": f"touch {tmp_file}"},
+            ]
+            for unsafe_option in unsafe_options:
+                with self.assertRaises(UnsafeOptionError):
+                    rw_repo.git.ls_remote(".", **unsafe_option)
+            with self.assertRaises(UnsafeOptionError):
+                rw_repo.git.ls_remote([f"--upload-pack={tmp_file}"], ".")
+            with self.assertRaises(UnsafeOptionError):
+                rw_repo.git.ls_remote([f"--upl={tmp_file}"], ".")
+            with self.assertRaises(UnsafeOptionError):
+                rw_repo.git.ls_remote(f"--upload-pack={tmp_file}", ".")
+            with self.assertRaises(UnsafeOptionError):
+                rw_repo.git.ls_remote(f"--upl={tmp_file}", ".")
+            with self.assertRaises(UnsafeOptionError):
+                rw_repo.git.ls_remote("--upload-pack", "touch", ".")
+            with self.assertRaises(UnsafeOptionError):
+                rw_repo.git.ls_remote("--refs", ".", upl=f"touch {tmp_file}")
+
+    def test_ls_remote_allows_operand_named_like_unsafe_option(self):
+        with mock.patch.object(Git, "_call_process") as git:
+            Git().ls_remote("upload-pack")
+        git.assert_called_once()
+
+    @with_rw_repo("HEAD")
+    def test_ls_remote_unsafe_options_allowed(self, rw_repo):
+        with tempfile.TemporaryDirectory() as tdir:
+            tmp_dir = Path(tdir)
+            tmp_file = tmp_dir / "pwn"
+            unsafe_options = [{"upload-pack": f"touch {tmp_file}"}]
+            for unsafe_option in unsafe_options:
+                with self.assertRaises(GitCommandError):
+                    rw_repo.git.ls_remote(".", **unsafe_option, allow_unsafe_options=True)
+
 
 class TestTimeouts(TestBase):
     @with_rw_repo("HEAD", bare=False)
Index: GitPython-3.1.34.1693646983.2a2ae77/test/test_repo.py
===================================================================
--- GitPython-3.1.34.1693646983.2a2ae77.orig/test/test_repo.py
+++ GitPython-3.1.34.1693646983.2a2ae77/test/test_repo.py
@@ -35,6 +35,8 @@ from git import (
     BadName,
     GitCommandError,
 )
+from git.exc import UnsafeOptionError
+from git.exc import UnsafeProtocolError
 from git.exc import BadObject
 from git.repo.fun import touch
 from test.lib import TestBase, with_rw_repo, fixture
@@ -388,6 +390,54 @@ class TestRepo(TestBase):
             assert stream.tell()
         os.remove(tmpfile)
 
+    def test_archive_rejects_unsafe_options(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            output_marker = osp.join(tdir, "pwn")
+            with self.assertRaises(UnsafeOptionError):
+                self.rorepo.archive(io.BytesIO(), "0.1.6", exec=f"touch {output_marker}")
+            assert not osp.exists(output_marker)
+            with self.assertRaises(UnsafeOptionError):
+                self.rorepo.archive(io.BytesIO(), "0.1.6", output=output_marker)
+            assert not osp.exists(output_marker)
+
+    def test_archive_rejects_unsafe_remote_protocol(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            output_marker = osp.join(tdir, "pwn")
+            with self.assertRaises(UnsafeProtocolError):
+                self.rorepo.archive(io.BytesIO(), "HEAD", remote=f"ext::sh -c touch% {output_marker}")
+            assert not osp.exists(output_marker)
+
+    def test_archive_preserves_positional_allow_unsafe_options(self):
+        with mock.patch.object(Git, "_call_process") as git:
+            self.rorepo.archive(io.BytesIO(), "HEAD", None, True, exec="git-upload-archive")
+        git.assert_called_once()
+
+    def test_archive_accepts_stringifiable_remote(self):
+        class StringifiableRemote:
+            def __str__(self):
+                return "origin"
+
+        with mock.patch.object(Git, "_call_process") as git:
+            self.rorepo.archive(io.BytesIO(), "HEAD", remote=StringifiableRemote())
+        git.assert_called_once()
+
+    def test_archive_rejects_unsafe_falsey_remote_protocol(self):
+        class FalseyRemote:
+            def __bool__(self):
+                return False
+
+            def __str__(self):
+                return "ext::sh -c true"
+
+        with self.assertRaises(UnsafeProtocolError):
+            self.rorepo.archive(io.BytesIO(), "HEAD", remote=FalseyRemote())
+
+    def test_iter_commits_rejects_unsafe_revision(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            target = osp.join(tdir, "pwn")
+            with self.assertRaises(UnsafeOptionError):
+                list(self.rorepo.iter_commits(f"--output={target}", max_count=1))
+
     @mock.patch.object(Git, "_call_process")
     def test_should_display_blame_information(self, git):
         git.return_value = fixture("blame")
@@ -437,6 +487,27 @@ class TestRepo(TestBase):
         assert c, "Should have executed at least one blame command"
         assert nml, "There should at least be one blame commit that contains multiple lines"
 
+    def test_blame_rejects_unsafe_revision(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            output_marker = osp.join(tdir, "pwn")
+            with self.assertRaises(UnsafeOptionError):
+                self.rorepo.blame(f"--output={output_marker}", "README.md")
+            assert not osp.exists(output_marker)
+
+    def test_blame_rejects_unsafe_options(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            output_marker = osp.join(tdir, "pwn")
+            with self.assertRaises(UnsafeOptionError):
+                self.rorepo.blame("HEAD", "README.md", output=output_marker)
+            assert not osp.exists(output_marker)
+
+    def test_blame_rejects_unsafe_rev_opts(self):
+        with tempfile.TemporaryDirectory() as tdir:
+            output_marker = osp.join(tdir, "pwn")
+            with self.assertRaises(UnsafeOptionError):
+                self.rorepo.blame("HEAD", "README.md", rev_opts=(f"--output={output_marker}",))
+            assert not osp.exists(output_marker)
+
     @mock.patch.object(Git, "_call_process")
     def test_blame_incremental(self, git):
         # loop over two fixtures, create a test fixture for 2.11.1+ syntax
