@contrast/rewriter 1.20.0 → 1.21.1
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/LICENSE +1 -1
- package/lib/cache.js +1 -1
- package/lib/index.js +1 -1
- package/lib/rewrite-is-deadzoned.js +143 -0
- package/package.json +5 -5
package/LICENSE
CHANGED
package/lib/cache.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2025 Contrast Security, Inc
|
|
3
|
+
* Contact: support@contrastsecurity.com
|
|
4
|
+
* License: Commercial
|
|
5
|
+
|
|
6
|
+
* NOTICE: This Software and the patented inventions embodied within may only be
|
|
7
|
+
* used as part of Contrast Security’s commercial offerings. Even though it is
|
|
8
|
+
* made available through public repositories, use of this Software is subject to
|
|
9
|
+
* the applicable End User Licensing Agreement found at
|
|
10
|
+
* https://www.contrastsecurity.com/enduser-terms-0317a or as otherwise agreed
|
|
11
|
+
* between Contrast Security and the End User. The Software may not be reverse
|
|
12
|
+
* engineered, modified, repackaged, sold, redistributed or otherwise used in a
|
|
13
|
+
* way not consistent with the End User License Agreement.
|
|
14
|
+
*/
|
|
15
|
+
'use strict';
|
|
16
|
+
|
|
17
|
+
const { sep } = require('path');
|
|
18
|
+
|
|
19
|
+
// todo: find optimal way to do these lookups
|
|
20
|
+
const DEADZONED_PATHS = [
|
|
21
|
+
'ast-types', // CONTRAST-33909: `String` injection causes this module to crash.
|
|
22
|
+
'angular',
|
|
23
|
+
'acorn',
|
|
24
|
+
'archiver',
|
|
25
|
+
'archiver-utils',
|
|
26
|
+
'bcrypt',
|
|
27
|
+
'bcrypt-nodejs',
|
|
28
|
+
'bcryptjs', // node_modules/bcryptjs/index.js, node_modules/bcryptjs/dist/bcrypt.js
|
|
29
|
+
'@babel', // this should handle all namespaced packages
|
|
30
|
+
'babel',
|
|
31
|
+
'babel-cli',
|
|
32
|
+
'babel-core',
|
|
33
|
+
'babel-traverse',
|
|
34
|
+
'babel-generator',
|
|
35
|
+
'babylon',
|
|
36
|
+
'bn.js',
|
|
37
|
+
'browserify',
|
|
38
|
+
'bson',
|
|
39
|
+
'bunyan',
|
|
40
|
+
'chai', // not sure why chai was rewritten
|
|
41
|
+
'coffeescript',
|
|
42
|
+
'compression',
|
|
43
|
+
'@cyclonedx',
|
|
44
|
+
'etag',
|
|
45
|
+
// 'cookie', // todo: verify this doesn't break sources/propagation (*)
|
|
46
|
+
// 'cookie-signature', // (*)
|
|
47
|
+
'gzippo', // 149 weekly downloads
|
|
48
|
+
// 'handlebars', // (*)
|
|
49
|
+
'handlebars-precompiler',
|
|
50
|
+
// 'hbs', // ditto
|
|
51
|
+
'html-webpack-plugin',
|
|
52
|
+
'iconv-lite',
|
|
53
|
+
'jquery',
|
|
54
|
+
'jsrsasign',
|
|
55
|
+
'less',
|
|
56
|
+
// 'dustjs-linkedin', // todo
|
|
57
|
+
'logger-console', // 2 weekly downloads
|
|
58
|
+
'loopback-datasource-juggler',
|
|
59
|
+
'moment',
|
|
60
|
+
'moment-timezone',
|
|
61
|
+
'node-forge',
|
|
62
|
+
'node-webpack',
|
|
63
|
+
'pem',
|
|
64
|
+
'react',
|
|
65
|
+
'react-dom', // doesn't this cover the next line?
|
|
66
|
+
//'react-dom/server',
|
|
67
|
+
'requirejs',
|
|
68
|
+
'semver',
|
|
69
|
+
'strong-remoting',
|
|
70
|
+
'type-is',
|
|
71
|
+
'uglify-js',
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
// maybe make the value an object for more complex strategies in the future
|
|
75
|
+
// NOTE: they key should appear in the list above as well. if it's not there
|
|
76
|
+
// then this object will never be checked.
|
|
77
|
+
const CUSTOM_REWRITERS = {
|
|
78
|
+
'acorn': 'no-propagation',
|
|
79
|
+
'archiver': 'no-propagation',
|
|
80
|
+
'babel-core': 'no-propagation',
|
|
81
|
+
'@babel': 'no-propagation',
|
|
82
|
+
'bcryptjs': 'no-propagation',
|
|
83
|
+
'bson': 'no-propagation',
|
|
84
|
+
'coffeescript': 'no-propagation',
|
|
85
|
+
'jsrsasign': 'no-propagation',
|
|
86
|
+
'less': 'no-propagation',
|
|
87
|
+
'@cyclonedx': 'no-propagation',
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const nodeModules = `${sep}node_modules${sep}`;
|
|
91
|
+
|
|
92
|
+
function rewriteIsDeadzoned(absolutePath) {
|
|
93
|
+
// we should only match the last node_modules folder
|
|
94
|
+
const startingPoint = absolutePath.lastIndexOf(nodeModules) + nodeModules.length;
|
|
95
|
+
|
|
96
|
+
for (const path of DEADZONED_PATHS) {
|
|
97
|
+
const start = absolutePath.indexOf(path, startingPoint);
|
|
98
|
+
// we return the name of the deadzoned module if it is found
|
|
99
|
+
if (start >= 0 && (start + path.length === absolutePath.length || absolutePath[start + path.length] === sep)) {
|
|
100
|
+
return path;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// the next function is used if/when we implement custom rewrite strategies.
|
|
108
|
+
// NODE-3512 implements that and this was taken from there.
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns an array with a package name and that package's rewrite strategy.
|
|
112
|
+
* The package name is only returned the package strategy is not 'default'.
|
|
113
|
+
* Strategies:
|
|
114
|
+
* - 'default': rewrite the module using the original, default rewriter
|
|
115
|
+
* - 'deadzone': do not rewrite the module
|
|
116
|
+
* - 'no-propagation': rewrite the module with the no-propagation rewriter
|
|
117
|
+
*
|
|
118
|
+
* why does this return the package name? mostly just because it had to extract
|
|
119
|
+
* it from the path, so returning means the caller doesn't have to.
|
|
120
|
+
*
|
|
121
|
+
* @param {string} absolutePath
|
|
122
|
+
* @returns {[string | undefined, 'default' | 'deadzone' | 'no-propagation']}
|
|
123
|
+
*/
|
|
124
|
+
function getPackageRewriteStrategy(absolutePath) {
|
|
125
|
+
const pkg = rewriteIsDeadzoned(absolutePath);
|
|
126
|
+
if (!pkg) {
|
|
127
|
+
return [undefined, 'default'];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const strategy = CUSTOM_REWRITERS[pkg];
|
|
131
|
+
if (strategy && process.env.CSI_USE_CUSTOM_REWRITERS) {
|
|
132
|
+
return [pkg, strategy];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return [pkg, 'deadzone'];
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
module.exports = {
|
|
139
|
+
DEADZONED_PATHS,
|
|
140
|
+
CUSTOM_REWRITERS,
|
|
141
|
+
rewriteIsDeadzoned,
|
|
142
|
+
getPackageRewriteStrategy,
|
|
143
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/rewriter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
4
4
|
"description": "A transpilation tool mainly used for instrumentation",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@contrast/agent-swc-plugin": "^2.0.0",
|
|
18
|
-
"@contrast/common": "1.29.
|
|
19
|
-
"@contrast/config": "1.
|
|
20
|
-
"@contrast/core": "1.
|
|
21
|
-
"@contrast/logger": "1.
|
|
18
|
+
"@contrast/common": "1.29.1",
|
|
19
|
+
"@contrast/config": "1.40.1",
|
|
20
|
+
"@contrast/core": "1.45.1",
|
|
21
|
+
"@contrast/logger": "1.18.1",
|
|
22
22
|
"@swc/core": "1.5.29"
|
|
23
23
|
}
|
|
24
24
|
}
|