Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/cli-kit/src/public/node/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ describe('commit()', () => {

expect(mockedExeca).toHaveBeenCalledWith('git', ['commit', '-m', 'msg', '--author', author], {cwd: directory})
})

test('throws an error if author starts with a hyphen', async () => {
const author = '-invalid-author'

await expect(git.createGitCommit('msg', {author})).rejects.toThrowError(
/Invalid commit author: -invalid-author. Author name\/email can't start with a hyphen./,
)
expect(mockedExeca).not.toHaveBeenCalled()
})
})

describe('getHeadSymbolicRef()', () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli-kit/src/public/node/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export interface CreateGitCommitOptions {
export async function createGitCommit(message: string, options?: CreateGitCommitOptions): Promise<string> {
const args = ['commit', '-m', message]
if (options?.author) {
// Guard against option injection attacks if author starts with '-'
if (options.author.startsWith('-')) {
throw new AbortError(`Invalid commit author: ${options.author}. Author name/email can't start with a hyphen.`)
}
args.push('--author', options.author)
}
await gitCommand(args, options?.directory)
Expand Down
Loading