mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-09 06:12:28 +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
18
packages/docusaurus-utils/src/shellUtils.ts
Normal file
18
packages/docusaurus-utils/src/shellUtils.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// TODO move from shelljs to execa later?
|
||||
// Execa is well maintained and widely used
|
||||
// Even shelljs recommends execa for security / escaping:
|
||||
// https://github.com/shelljs/shelljs/wiki/Security-guidelines
|
||||
|
||||
// Inspired by https://github.com/xxorax/node-shell-escape/blob/master/shell-escape.js
|
||||
export function escapeShellArg(s: string): string {
|
||||
let res = `'${s.replace(/'/g, "'\\''")}'`;
|
||||
res = res.replace(/^(?:'')+/g, '').replace(/\\'''/g, "\\'");
|
||||
return res;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue