Skip to content

Commit a21caa1

Browse files
authored
Merge pull request #17 from contentstack/bugfix/DX-780
DX - 780 - Semgrep issues resolved and version bump
2 parents 9ebed9d + 27dedc6 commit a21caa1

File tree

10 files changed

+2019
-13
lines changed

10 files changed

+2019
-13
lines changed

.github/workflows/release.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Release
2+
on:
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build:
8+
name: Build and upload
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3.5.3
13+
with:
14+
fetch-depth: 0
15+
- name: Setup Node.js
16+
uses: actions/setup-node@v3.7.0
17+
with:
18+
node-version: "18.x"
19+
- name: Install dependencies
20+
run: npm install
21+
- name: Upload dist
22+
uses: actions/upload-artifact@v3.1.2
23+
with:
24+
name: lib
25+
path: lib
26+
27+
release:
28+
name: Download dist and release
29+
runs-on: ubuntu-latest
30+
needs: build
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v3.5.3
34+
with:
35+
fetch-depth: 0
36+
- name: Download dist
37+
uses: actions/download-artifact@v3
38+
with:
39+
name: lib
40+
path: lib
41+
- name: Display directories
42+
run: ls -R lib
43+
- name: Publish to npm
44+
id: release-plugin
45+
uses: JS-DevTools/npm-publish@v2.2.0
46+
with:
47+
token: ${{ secrets.NPM_TOKEN }}
48+
- name: Create GitHub release
49+
env:
50+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
51+
run: gh release create v${{ steps.release-plugin.outputs.version }} --title "Release ${{ steps.release-plugin.outputs.version }}" --generate-notes

.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

LICENSE.txt renamed to LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2018 Contentstack
3+
Copyright (c) 2024 Contentstack
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

SECURITY.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## Security
2+
3+
Contentstack takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations.
4+
5+
If you believe you have found a security vulnerability in any Contentstack-owned repository, please report it to us as described below.
6+
7+
## Reporting Security Issues
8+
9+
**Please do not report security vulnerabilities through public GitHub issues.**
10+
11+
Send email to [security@contentstack.com](mailto:security@contentstack.com).
12+
13+
You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message.
14+
15+
Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
16+
17+
- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
18+
- Full paths of source file(s) related to the manifestation of the issue
19+
- The location of the affected source code (tag/branch/commit or direct URL)
20+
- Any special configuration required to reproduce the issue
21+
- Step-by-step instructions to reproduce the issue
22+
- Proof-of-concept or exploit code (if possible)
23+
- Impact of the issue, including how an attacker might exploit the issue
24+
25+
This information will help us triage your report more quickly.
26+
27+
[https://www.contentstack.com/trust/](https://www.contentstack.com/trust/)

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/request.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ var makeCall = module.exports = function(req, cb, RETRY) {
4848
return cb(new Error('Max retry limit exceeded!'));
4949
}
5050
debug(`Requesting API\n${JSON.stringify(req, null, 2)}`);
51+
//NOTE: Please delete the below three lines in case the code breaks :)
52+
let tempObj = Object.create(null);
53+
merge(tempObj,req);
54+
req = tempObj;
5155
return request(req, function(err, response, body) {
5256
if (err) {
5357
return cb(err);

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)