Skip to content

Commit ec97a39

Browse files
authored
Block unsafe pack (push --exec) (#882)
Add `git push --exec` to the set of blocked operations without the use of an `allowUnsafePack` override.
1 parent 0a623e5 commit ec97a39

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

.changeset/fair-cobras-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'simple-git': patch
3+
---
4+
5+
Include restricting the use of git push --exec with other allowUnsafePack exclusions, thanks to @stsewd for the suggestion.

docs/PLUGIN-UNSAFE-ACTIONS.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,27 @@ that any parameter sourced from user input is validated before being passed to t
66
In some cases where there is an elevated potential for harm `simple-git` will throw an exception unless you have
77
explicitly opted in to the potentially unsafe action.
88

9+
### Enabling custom upload and receive packs
10+
11+
Instead of using the default `git-receive-pack` and `git-upload-pack` binaries to parse incoming and outgoing
12+
data, `git` can be configured to use _any_ arbitrary binary or evaluable script.
13+
14+
To avoid accidentally triggering the evaluation of a malicious script when merging user provided parameters
15+
into command executed by `simple-git`, custom pack options (usually with the `--receive-pack` and `--upload-pack`)
16+
are blocked without explicitly opting into their use
17+
18+
```typescript
19+
import { simpleGit } from 'simple-git';
20+
21+
// throws
22+
await simpleGit()
23+
.raw('push', '--receive-pack=git-receive-pack-custom');
24+
25+
// allows calling clone with a helper transport
26+
await simpleGit({ unsafe: { allowUnsafePack: true } })
27+
.raw('push', '--receive-pack=git-receive-pack-custom');
28+
```
29+
930
### Overriding allowed protocols
1031

1132
A standard installation of `git` permits `file`, `http` and `ssh` protocols for a remote. A range of

simple-git/src/lib/plugins/block-unsafe-operations-plugin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ function preventUploadPack(arg: string, method: string) {
3939
`Use of clone with option -u is not permitted without enabling allowUnsafePack`
4040
);
4141
}
42+
43+
if (method === 'push' && /^\s*--exec\b/.test(arg)) {
44+
throw new GitPluginError(
45+
undefined,
46+
'unsafe',
47+
`Use of push with option --exec is not permitted without enabling allowUnsafePack`
48+
);
49+
}
4250
}
4351

4452
export function blockUnsafeOperationsPlugin({

simple-git/test/unit/plugin.unsafe.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88

99
describe('blockUnsafeOperationsPlugin', () => {
1010
it.each([
11+
['clone', '-u touch /tmp/pwn'],
1112
['cmd', '--upload-pack=touch /tmp/pwn0'],
1213
['cmd', '--receive-pack=touch /tmp/pwn1'],
13-
['clone', '-u touch /tmp/pwn'],
14+
['push', '--exec=touch /tmp/pwn2'],
1415
])('allows %s %s only when using override', async (cmd, option) => {
1516
assertGitError(
1617
await promiseError(newSimpleGit({ unsafe: {} }).raw(cmd, option)),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy