@contrast/cli 1.25.0 → 1.26.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/rewrite.js +25 -18
- package/package.json +8 -8
package/lib/rewrite.js
CHANGED
|
@@ -90,20 +90,28 @@ class RewriteVisitor extends Visitor {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
* Visit
|
|
94
|
-
*
|
|
95
|
-
* @param {swc.
|
|
93
|
+
* Visit the String Literal argument of either `import` or `require`, trying
|
|
94
|
+
* to rewrite the arg if it's a valid (i.e., absolute) path.
|
|
95
|
+
* @param {swc.StringLiteral} n
|
|
96
96
|
*/
|
|
97
|
-
|
|
97
|
+
visitImportOrRequireString(n) {
|
|
98
98
|
try {
|
|
99
|
-
const filename = this.require.resolve(n.
|
|
99
|
+
const filename = this.require.resolve(n.value);
|
|
100
100
|
if (path.isAbsolute(filename)) {
|
|
101
101
|
rewriteFile(filename);
|
|
102
102
|
}
|
|
103
103
|
} catch (err) {
|
|
104
|
-
logger.debug({ n, err }, 'unable to resolve %s', n.
|
|
104
|
+
logger.debug({ n, err }, 'unable to resolve %s', n.value);
|
|
105
105
|
}
|
|
106
|
+
}
|
|
106
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Visit `import ... from 'source'`, recursively rewriting the resolved path
|
|
110
|
+
* of `source`.
|
|
111
|
+
* @param {swc.ImportDeclaration} n
|
|
112
|
+
*/
|
|
113
|
+
visitImportDeclaration(n) {
|
|
114
|
+
this.visitImportOrRequireString(n.source);
|
|
107
115
|
return super.visitImportDeclaration(n);
|
|
108
116
|
}
|
|
109
117
|
|
|
@@ -116,14 +124,7 @@ class RewriteVisitor extends Visitor {
|
|
|
116
124
|
if (n.callee.type === 'Import' || (n.callee.type === 'Identifier' && n.callee.value === 'require')) {
|
|
117
125
|
const { expression } = n.arguments[0];
|
|
118
126
|
if (expression.type === 'StringLiteral') {
|
|
119
|
-
|
|
120
|
-
const filename = this.require.resolve(expression.value);
|
|
121
|
-
if (path.isAbsolute(filename)) {
|
|
122
|
-
rewriteFile(filename);
|
|
123
|
-
}
|
|
124
|
-
} catch (err) {
|
|
125
|
-
logger.debug({ n, err }, 'unable to resolve %s', expression.value);
|
|
126
|
-
}
|
|
127
|
+
this.visitImportOrRequireString(expression);
|
|
127
128
|
}
|
|
128
129
|
}
|
|
129
130
|
|
|
@@ -164,11 +165,14 @@ async function rewriteFile(filename) {
|
|
|
164
165
|
* @param {string} filename
|
|
165
166
|
* @param {object} opts
|
|
166
167
|
* @param {boolean=} opts.assess
|
|
168
|
+
* @param {boolean=} opts.protect
|
|
167
169
|
*/
|
|
168
170
|
async function action(filename, opts) {
|
|
169
|
-
if (config.assess.enable || opts.assess)
|
|
170
|
-
|
|
171
|
-
|
|
171
|
+
if (!opts.protect && (config.assess.enable || opts.assess)) {
|
|
172
|
+
rewriter.install('assess');
|
|
173
|
+
} else {
|
|
174
|
+
rewriter.install('protect');
|
|
175
|
+
}
|
|
172
176
|
|
|
173
177
|
logger.info(
|
|
174
178
|
'Caching rewriter results to %s',
|
|
@@ -187,7 +191,10 @@ if (require.main === module) {
|
|
|
187
191
|
.version(version)
|
|
188
192
|
.description('Rewrites application files, caching them so that rewriting does not need to occur when the application runs.')
|
|
189
193
|
.argument('<entrypoint>', 'The entrypoint for the application', entrypoint => path.resolve(entrypoint))
|
|
190
|
-
.option('-a, --assess', '
|
|
194
|
+
.option('-a, --assess', 'rewrite in assess mode')
|
|
195
|
+
.option('-p, --protect', 'rewrite in protect mode')
|
|
191
196
|
.action(action)
|
|
192
197
|
.parse(process.argv);
|
|
193
198
|
}
|
|
199
|
+
|
|
200
|
+
module.exports.action = action;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.26.2",
|
|
4
4
|
"description": "A collection of agent related CLI utilities",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -14,19 +14,19 @@
|
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
16
16
|
"npm": ">=6.13.7 <7 || >= 8.3.1",
|
|
17
|
-
"node": ">= 14.
|
|
17
|
+
"node": ">= 14.18.0"
|
|
18
18
|
},
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "../scripts/test.sh"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@contrast/find-package-json": "^1.1.0",
|
|
24
|
-
"@contrast/rewriter": "1.7.
|
|
25
|
-
"@contrast/config": "1.27.
|
|
26
|
-
"@contrast/core": "1.31.
|
|
27
|
-
"@contrast/logger": "1.8.
|
|
28
|
-
"@contrast/reporter": "1.26.
|
|
29
|
-
"@contrast/scopes": "
|
|
24
|
+
"@contrast/rewriter": "1.7.2",
|
|
25
|
+
"@contrast/config": "1.27.1",
|
|
26
|
+
"@contrast/core": "1.31.2",
|
|
27
|
+
"@contrast/logger": "1.8.1",
|
|
28
|
+
"@contrast/reporter": "1.26.1",
|
|
29
|
+
"@contrast/scopes": "1.4.1",
|
|
30
30
|
"@swc/core": "1.3.39",
|
|
31
31
|
"commander": "^9.4.1"
|
|
32
32
|
}
|