# git: Fix commit message generation in untrusted projects and block external diff \(\#51323\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/697e5be795ba5b2949f2087016e005f11073108a)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 697e5be795ba5b2949f2087016e005f11073108a

Requested commit: 697e5be795ba5b2949f2087016e005f11073108a

Commit: 697e5be795ba5b2949f2087016e005f11073108a

Tree: f761275fc225175a8444cba4f118f234ea2d3dc0

Author: Dino

Committer: GitHub

## Message

```
git: Fix commit message generation in untrusted projects and block external diff (#51323)

When on a untrusted project, if one was to try and use the commit
generation functionality, the command would fail because of the `-c
diff.external` configuration provided in `GitBinary::build_command`, as
git would interpret this as `""` and try to run that command.

This `-c diff.external` is a good safeguard to have on untrusted
repositories because it prevents random commands, configured in
`.git/config` from being run. For example, if one uses `git config
diff.external "touch bananas.txt"` and then run `git diff`, a new
`bananas.txt` file would be created.

However, it was still possible to bypass this safeguard using the
following strategy:

1. Specify a custom diff for a specific file format. For example, for
markdown files, with `printf '*.md diff=pwned\n' > .gitattributes`
2. Update the command run by the `pwned` diff, for example, `git config
diff.pwned.command "touch bananas.txt"`
3. Open Zed and attempt to generate a commit message in an untrusted
repository and check that a new `bananas.txt` file was created

This is only prevented by using the `--no-ext-diff` flag on the `diff`
command, so a new `GitBinary::build_diff_command` has been introduced
which simply wraps `GitBinary::build_command` and adds the
`--no-ext-diff` flag, if necessary.

As a side-effect, this also makes it so that generating a commit message
in an untrusted repository works again, which was accidentally broken on
https://github.com/zed-industries/zed/pull/50649 .

Before you mark this PR as ready for review, make sure that you have:
- [X] Added a solid test coverage and/or screenshots from doing manual
testing
- [X] Done a self-review taking into account security and performance
aspects
- [X] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Fixed commit message generation in untrusted repositories
```

## Parents

- [3e7f2e3f9a576c4704c2f71497f6ba3516d9339b](https://git.cafe/gitcafe/zed/commit/3e7f2e3f9a576c4704c2f71497f6ba3516d9339b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/697e5be795ba5b2949f2087016e005f11073108a?format=markdown)
