Skip to content

Commit d572fc3

Browse files
committed
resolved semgrep issues, version bump
1 parent 9ebed9d commit d572fc3

File tree

6 files changed

+1941
-10
lines changed

6 files changed

+1941
-10
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
node_modules
2-
package-lock.json

lib/helper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var prompt = require('prompt');
1616
var ncp = require('ncp').ncp;
1717
var mkdirp = require('mkdirp');
1818
var chalk = require('chalk');
19+
const sanitizePath = require('./Utility');
1920
var log = console.log;
2021
var success = chalk.green;
2122
var error = chalk.red;
@@ -119,7 +120,7 @@ exports.confirm = function(config, lang, backup, callback) {
119120
exports.createBackupDir = function(storagePath, lang, callback) {
120121
log(info('Creating backup...'));
121122
var d = new Date();
122-
ncp(path.join(storagePath, lang), path.join(storagePath, lang, '..', `${d.getTime()}_${lang}_backup`), function(err) {
123+
ncp(path.join(sanitizePath(storagePath), sanitizePath(lang)), path.join(sanitizePath(storagePath), sanitizePath(lang), '..', `${d.getTime()}_${sanitizePath(lang)}_backup`), function(err) {
123124
if (err) {
124125
log(error(
125126
`Failed to create backup, due to the following error\n${err.message || err}`

lib/plugin.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@ var error = chalk.red;
2020
var info = chalk.cyan;
2121

2222
var helper = require('./helper');
23+
const sanitizePath = require('./utility');
2324

2425
/**
2526
* Create contentstack-express framework plugin
2627
*/
2728
var Plugin = function(name) {
2829
try {
29-
var dir = path.join(process.cwd(), 'plugins');
30+
var dir = path.join(sanitizePath(process.cwd()), 'plugins');
3031
var match = (name && typeof name == 'string') ? name.match(/^[a-zA-Z0-9\-_]+$/g) : null;
3132
if (match && match.length) {
3233
name = name.trim().toLowerCase();
3334
if (fs.existsSync(dir)) {
34-
var _path = path.join(dir, name);
35+
var _path = path.join(sanitizePath(dir), sanitizePath(name));
3536
log(info(`Creating Contentstack plugin at ${_path}`));
3637
prompt.message = '';
3738
prompt.delimiter = '>';

lib/utility.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const sanitizePath = function (str) {
2+
return str?.replace(/^(\.\.(\/|\\|$))+/, "");
3+
};
4+
5+
module.exports = sanitizePath

0 commit comments

Comments
 (0)