Skip to content

Commit 3f5adc9

Browse files
Merge pull request #8435 from Shopify/security-validate-git-author-7844826945563519319
[Security] Validate git commit author argument
2 parents 3dd2b4f + 653cab9 commit 3f5adc9

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

packages/cli-kit/src/public/node/git.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ describe('commit()', () => {
277277

278278
expect(mockedExeca).toHaveBeenCalledWith('git', ['commit', '-m', 'msg', '--author', author], {cwd: directory})
279279
})
280+
281+
test('throws an error if author starts with a hyphen', async () => {
282+
const author = '-invalid-author'
283+
284+
await expect(git.createGitCommit('msg', {author})).rejects.toThrowError(
285+
/Invalid commit author: -invalid-author. Author name\/email can't start with a hyphen./,
286+
)
287+
expect(mockedExeca).not.toHaveBeenCalled()
288+
})
280289
})
281290

282291
describe('getHeadSymbolicRef()', () => {

packages/cli-kit/src/public/node/git.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ export interface CreateGitCommitOptions {
299299
export async function createGitCommit(message: string, options?: CreateGitCommitOptions): Promise<string> {
300300
const args = ['commit', '-m', message]
301301
if (options?.author) {
302+
// Guard against option injection attacks if author starts with '-'
303+
if (options.author.startsWith('-')) {
304+
throw new AbortError(`Invalid commit author: ${options.author}. Author name/email can't start with a hyphen.`)
305+
}
302306
args.push('--author', options.author)
303307
}
304308
await gitCommand(args, options?.directory)

0 commit comments

Comments
 (0)