mirror of
https://github.com/facebook/docusaurus.git
synced 2025-08-06 02:08:55 +02:00
fix(create-docusaurus): potential security issue with command injection (#7507)
This commit is contained in:
parent
cd7cf781cd
commit
dbd161d67c
7 changed files with 59 additions and 22 deletions
|
@ -97,26 +97,19 @@ export function getFileCommitDate(
|
|||
);
|
||||
}
|
||||
|
||||
let formatArg = '--format=%ct';
|
||||
if (includeAuthor) {
|
||||
formatArg += ',%an';
|
||||
}
|
||||
const args = [
|
||||
`--format=%ct${includeAuthor ? ',%an' : ''}`,
|
||||
'--max-count=1',
|
||||
age === 'oldest' ? '--follow --diff-filter=A' : undefined,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
|
||||
let extraArgs = '--max-count=1';
|
||||
if (age === 'oldest') {
|
||||
// --follow is necessary to follow file renames
|
||||
// --diff-filter=A ensures we only get the commit which (A)dded the file
|
||||
extraArgs += ' --follow --diff-filter=A';
|
||||
}
|
||||
|
||||
const result = shell.exec(
|
||||
`git log ${extraArgs} ${formatArg} -- "${path.basename(file)}"`,
|
||||
{
|
||||
// Setting cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
||||
cwd: path.dirname(file),
|
||||
silent: true,
|
||||
},
|
||||
);
|
||||
const result = shell.exec(`git log ${args} -- "${path.basename(file)}"`, {
|
||||
// Setting cwd is important, see: https://github.com/facebook/docusaurus/pull/5048
|
||||
cwd: path.dirname(file),
|
||||
silent: true,
|
||||
});
|
||||
if (result.code !== 0) {
|
||||
throw new Error(
|
||||
`Failed to retrieve the git history for file "${file}" with exit code ${result.code}: ${result.stderr}`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue