-
-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unsafe operations plugin extended to prevent the use of potential att…
…ack vectors `--upload-pack` or `--receive-pack` (or the shorthand version `-u` in `git clone`) without explicitly opting in with the `allowUnsafePack` option.
- Loading branch information
Showing
5 changed files
with
147 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { promiseError } from "@kwsites/promise-result"; | ||
import { assertExecutedCommands, assertGitError, closeWithSuccess, newSimpleGit } from "./__fixtures__"; | ||
|
||
describe("blockUnsafeOperationsPlugin", () => { | ||
|
||
it.each([ | ||
["cmd", "--upload-pack=touch /tmp/pwn0"], | ||
["cmd", "--receive-pack=touch /tmp/pwn1"], | ||
["clone", "-u touch /tmp/pwn"] | ||
])("allows %s %s only when using override", async (cmd, option) => { | ||
assertGitError( | ||
await promiseError(newSimpleGit({ unsafe: {} }).raw(cmd, option)), | ||
"allowUnsafePack" | ||
); | ||
|
||
const err = promiseError( | ||
newSimpleGit({ unsafe: { allowUnsafePack: true } }).raw(cmd, option) | ||
); | ||
|
||
await closeWithSuccess(); | ||
expect(await err).toBeUndefined(); | ||
assertExecutedCommands(cmd, option); | ||
}); | ||
|
||
it("allows -u for non-clone commands", async () => { | ||
const git = newSimpleGit({ unsafe: {} }); | ||
const err = promiseError( | ||
git.raw("push", "-u", "origin/main") | ||
); | ||
|
||
await closeWithSuccess(); | ||
expect(await err).toBeUndefined(); | ||
assertExecutedCommands("push", "-u", "origin/main"); | ||
}); | ||
|
||
it("blocks -u for clone command", async () => { | ||
const git = newSimpleGit({ unsafe: {} }); | ||
const err = promiseError( | ||
git.clone("-u touch /tmp/pwn", "file:///tmp/zero12") | ||
); | ||
|
||
assertGitError(await err, "allowUnsafePack"); | ||
}); | ||
|
||
it("allows -u for clone command with override", async () => { | ||
const git = newSimpleGit({ unsafe: { allowUnsafePack: true } }); | ||
const err = promiseError( | ||
git.clone("-u touch /tmp/pwn", "file:///tmp/zero12") | ||
); | ||
|
||
await closeWithSuccess(); | ||
expect(await err).toBeUndefined(); | ||
assertExecutedCommands("clone", "-u touch /tmp/pwn", "file:///tmp/zero12"); | ||
}); | ||
|
||
it("blocks pull --upload-pack", async () => { | ||
const git = newSimpleGit({ unsafe: {} }); | ||
const err = await promiseError( | ||
git.pull("--upload-pack=touch /tmp/pwn0", "master") | ||
); | ||
|
||
assertGitError(err, "allowUnsafePack"); | ||
}); | ||
|
||
it("blocks push --receive-pack", async () => { | ||
const git = newSimpleGit({ unsafe: {} }); | ||
const err = await promiseError( | ||
git.push("--receive-pack=touch /tmp/pwn1", "master") | ||
); | ||
|
||
assertGitError(err, "allowUnsafePack"); | ||
}); | ||
|
||
it("blocks raw --upload-pack", async () => { | ||
const git = newSimpleGit({ unsafe: {} }); | ||
const err = await promiseError(git.raw("pull", `--upload-pack=touch /tmp/pwn0`)); | ||
|
||
assertGitError(err, "allowUnsafePack"); | ||
}); | ||
|
||
it("blocks raw --receive-pack", async () => { | ||
const git = newSimpleGit({ unsafe: {} }); | ||
const err = await promiseError(git.raw("push", `--receive-pack=touch /tmp/pwn1`)); | ||
|
||
assertGitError(err, "allowUnsafePack"); | ||
}); | ||
|
||
it("blocks listRemote --upload-pack", async () => { | ||
const git = newSimpleGit({ unsafe: {} }); | ||
const err = await promiseError( | ||
git.listRemote(["--upload-pack=touch /tmp/pwn2", "main"]) | ||
); | ||
|
||
assertGitError(err, "allowUnsafePack"); | ||
}); | ||
|
||
}); |
9545931
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wtf is this