Skip to content

Commit 6a966be

Browse files
authored
Fix vulnerability in git-loader: use execFile instead of exec (#2470)
1 parent d27ed53 commit 6a966be

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

.changeset/green-cycles-drive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/git-loader': patch
3+
---
4+
5+
Fix vulnerability: use execFile instead of exec

packages/loaders/git/src/load-git.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { exec, execSync } from 'child_process';
1+
import { execFile, execFileSync } from 'child_process';
22

33
type Input = { ref: string; path: string };
44

55
const createLoadError = (error: any) => new Error('Unable to load file from git: ' + error);
6-
const createCommand = ({ ref, path }: Input) => {
7-
return `git show ${ref}:${path}`;
6+
const createCommand = ({ ref, path }: Input): string[] => {
7+
return ['show', `${ref}:${path}`];
88
};
99

1010
/**
@@ -13,7 +13,7 @@ const createCommand = ({ ref, path }: Input) => {
1313
export async function loadFromGit(input: Input): Promise<string | never> {
1414
try {
1515
return await new Promise((resolve, reject) => {
16-
exec(createCommand(input), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
16+
execFile('git', createCommand(input), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
1717
if (error) {
1818
reject(error);
1919
} else {
@@ -31,7 +31,7 @@ export async function loadFromGit(input: Input): Promise<string | never> {
3131
*/
3232
export function loadFromGitSync(input: Input): string | never {
3333
try {
34-
return execSync(createCommand(input), { encoding: 'utf-8' });
34+
return execFileSync('git', createCommand(input), { encoding: 'utf-8' });
3535
} catch (error) {
3636
throw createLoadError(error);
3737
}

0 commit comments

Comments
 (0)