@contrast/protect 1.36.1 → 1.38.0
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/error-handlers/index.js +3 -2
- package/lib/error-handlers/install/restify.js +52 -0
- package/lib/input-analysis/index.js +1 -0
- package/lib/input-analysis/install/restify.js +67 -0
- package/lib/input-tracing/index.js +2 -0
- package/lib/input-tracing/install/http.js +1 -2
- package/lib/input-tracing/install/http2.js +63 -0
- package/lib/input-tracing/install/spdy.js +63 -0
- package/lib/make-response-blocker.js +7 -1
- package/package.json +5 -5
|
@@ -25,10 +25,11 @@ module.exports = function(core) {
|
|
|
25
25
|
require('./init-domain')(core);
|
|
26
26
|
|
|
27
27
|
// installers
|
|
28
|
-
require('./install/fastify')(core);
|
|
29
|
-
require('./install/koa2')(core);
|
|
30
28
|
require('./install/express4')(core);
|
|
29
|
+
require('./install/fastify')(core);
|
|
31
30
|
require('./install/hapi')(core);
|
|
31
|
+
require('./install/koa2')(core);
|
|
32
|
+
require('./install/restify')(core);
|
|
32
33
|
|
|
33
34
|
errorHandlers.install = function() {
|
|
34
35
|
callChildComponentMethodsSync(errorHandlers, 'install');
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { isSecurityException } = require('../../security-exception');
|
|
19
|
+
const { patchType } = require('../constants');
|
|
20
|
+
|
|
21
|
+
module.exports = function init(core) {
|
|
22
|
+
const { depHooks, logger, patcher, protect } = core;
|
|
23
|
+
|
|
24
|
+
return protect.errorHandlers.restifyErrorHandler = {
|
|
25
|
+
install() {
|
|
26
|
+
depHooks.resolve(
|
|
27
|
+
{ name: 'restify', file: 'lib/server.js', version: '>=8' },
|
|
28
|
+
(Server) => {
|
|
29
|
+
patcher.patch(Server.prototype, '_onHandlerError', {
|
|
30
|
+
name: 'restify.Server.prototype._onHandlerError',
|
|
31
|
+
patchType,
|
|
32
|
+
around(orig, { args: [err], funcKey }) {
|
|
33
|
+
if (isSecurityException(err)) {
|
|
34
|
+
const sourceContext = protect.getSourceContext();
|
|
35
|
+
|
|
36
|
+
if (!sourceContext) {
|
|
37
|
+
logger.info({ funcKey }, 'source context not found; unable to handle response');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
sourceContext.block(...sourceContext.securityException);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return orig();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { isSecurityException } = require('../../security-exception');
|
|
19
|
+
const { patchType } = require('../constants');
|
|
20
|
+
|
|
21
|
+
module.exports = function init(core) {
|
|
22
|
+
const { depHooks, patcher, logger, protect } = core;
|
|
23
|
+
const { inputAnalysis } = protect;
|
|
24
|
+
|
|
25
|
+
return inputAnalysis.restifyInstrumentation = {
|
|
26
|
+
install() {
|
|
27
|
+
depHooks.resolve(
|
|
28
|
+
{ name: 'restify', file: 'lib/server.js', version: '>=8' },
|
|
29
|
+
(Server) => {
|
|
30
|
+
patcher.patch(Server.prototype, '_afterUse', {
|
|
31
|
+
name: 'restify.Server.prototype._afterUse',
|
|
32
|
+
patchType,
|
|
33
|
+
pre(data) {
|
|
34
|
+
const sourceContext = protect.getSourceContext();
|
|
35
|
+
if (!sourceContext) return;
|
|
36
|
+
|
|
37
|
+
const req = data.args[1];
|
|
38
|
+
try {
|
|
39
|
+
if (req.body && !sourceContext.parsedBody) {
|
|
40
|
+
sourceContext.parsedBody = req.body;
|
|
41
|
+
inputAnalysis.handleParsedBody(sourceContext, req.body);
|
|
42
|
+
}
|
|
43
|
+
if (req.params && !sourceContext.parsedParams) {
|
|
44
|
+
sourceContext.parsedParams = req.params;
|
|
45
|
+
inputAnalysis.handleUrlParams(sourceContext, req.params);
|
|
46
|
+
}
|
|
47
|
+
if (req.query && !sourceContext.parsedQuery) {
|
|
48
|
+
sourceContext.parsedQuery = req.query;
|
|
49
|
+
inputAnalysis.handleQueryParams(sourceContext, req.query);
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (isSecurityException(err)) {
|
|
53
|
+
data.args[0] = err;
|
|
54
|
+
} else {
|
|
55
|
+
logger.error(
|
|
56
|
+
{ err, funcKey: data.funcKey },
|
|
57
|
+
'Unexpected error during input analysis'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
};
|
|
@@ -29,12 +29,14 @@ module.exports = function(core) {
|
|
|
29
29
|
require('./install/fs')(core);
|
|
30
30
|
require('./install/function')(core);
|
|
31
31
|
require('./install/http')(core);
|
|
32
|
+
require('./install/http2')(core);
|
|
32
33
|
require('./install/marsdb')(core);
|
|
33
34
|
require('./install/mongodb')(core);
|
|
34
35
|
require('./install/mssql')(core);
|
|
35
36
|
require('./install/mysql')(core);
|
|
36
37
|
require('./install/postgres')(core);
|
|
37
38
|
require('./install/sequelize')(core);
|
|
39
|
+
require('./install/spdy')(core);
|
|
38
40
|
require('./install/sqlite3')(core);
|
|
39
41
|
require('./install/vm')(core);
|
|
40
42
|
// TODO: NODE-2360 (oracledb)
|
|
@@ -37,10 +37,9 @@ module.exports = function(core) {
|
|
|
37
37
|
if (instrumentation.isLocked()) return;
|
|
38
38
|
|
|
39
39
|
const sourceContext = protect.getSourceContext(name);
|
|
40
|
-
|
|
41
40
|
if (!sourceContext) return;
|
|
42
41
|
|
|
43
|
-
const value = data.args[0]?.toString();
|
|
42
|
+
const value = data.args[0]?.toString?.();
|
|
44
43
|
if (!value) return;
|
|
45
44
|
|
|
46
45
|
const sinkContext = {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { patchType } = require('../constants');
|
|
19
|
+
|
|
20
|
+
module.exports = function(core) {
|
|
21
|
+
const {
|
|
22
|
+
scopes: { instrumentation },
|
|
23
|
+
patcher,
|
|
24
|
+
depHooks,
|
|
25
|
+
protect,
|
|
26
|
+
protect: { inputTracing }
|
|
27
|
+
} = core;
|
|
28
|
+
|
|
29
|
+
function install() {
|
|
30
|
+
depHooks.resolve({ name: 'http2' }, http2 => {
|
|
31
|
+
for (const method of ['write', 'end']) {
|
|
32
|
+
const name = `http2.Http2ServerResponse.prototype.${method}`;
|
|
33
|
+
patcher.patch(http2.Http2ServerResponse.prototype, method, {
|
|
34
|
+
name,
|
|
35
|
+
patchType,
|
|
36
|
+
pre(data) {
|
|
37
|
+
if (instrumentation.isLocked()) return;
|
|
38
|
+
|
|
39
|
+
const sourceContext = protect.getSourceContext(name);
|
|
40
|
+
|
|
41
|
+
if (!sourceContext) return;
|
|
42
|
+
|
|
43
|
+
const value = data.args[0]?.toString();
|
|
44
|
+
if (!value) return;
|
|
45
|
+
|
|
46
|
+
const sinkContext = {
|
|
47
|
+
name,
|
|
48
|
+
value,
|
|
49
|
+
stacktraceOpts: { constructorOpt: data.hooked },
|
|
50
|
+
};
|
|
51
|
+
inputTracing.handleReflectedXss(sourceContext, sinkContext);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const http2Instrumentation = inputTracing.http2Instrumentation = {
|
|
59
|
+
install
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return http2Instrumentation;
|
|
63
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright: 2024 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
|
+
|
|
16
|
+
'use strict';
|
|
17
|
+
|
|
18
|
+
const { patchType } = require('../constants');
|
|
19
|
+
|
|
20
|
+
module.exports = function(core) {
|
|
21
|
+
const {
|
|
22
|
+
scopes: { instrumentation },
|
|
23
|
+
patcher,
|
|
24
|
+
depHooks,
|
|
25
|
+
protect,
|
|
26
|
+
protect: { inputTracing }
|
|
27
|
+
} = core;
|
|
28
|
+
|
|
29
|
+
function install() {
|
|
30
|
+
depHooks.resolve({ name: 'spdy' }, spdy => {
|
|
31
|
+
const name = 'spdy.response.end';
|
|
32
|
+
patcher.patch(spdy.response, 'end', {
|
|
33
|
+
name,
|
|
34
|
+
patchType,
|
|
35
|
+
pre({ args, obj: response, hooked }) {
|
|
36
|
+
if (instrumentation.isLocked()) return;
|
|
37
|
+
|
|
38
|
+
const sourceContext = protect.getSourceContext(name);
|
|
39
|
+
|
|
40
|
+
if (!sourceContext) return;
|
|
41
|
+
|
|
42
|
+
const value = args[0]?.toString();
|
|
43
|
+
if (!value) return;
|
|
44
|
+
|
|
45
|
+
const sinkContext = {
|
|
46
|
+
name,
|
|
47
|
+
value,
|
|
48
|
+
stacktraceOpts: { constructorOpt: hooked },
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
response.spdyStream.once('finish', () => response.emit('finish'));
|
|
52
|
+
inputTracing.handleReflectedXss(sourceContext, sinkContext);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const spdyInstrumentation = inputTracing.spdyInstrumentation = {
|
|
59
|
+
install
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
return spdyInstrumentation;
|
|
63
|
+
};
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
StringPrototypeToUpperCase,
|
|
20
|
+
symbols: { kMetrics }
|
|
21
|
+
} = require('@contrast/common');
|
|
19
22
|
|
|
20
23
|
module.exports = function(core) {
|
|
21
24
|
// i think this should be a weakset. we don't want to accumulate
|
|
@@ -34,6 +37,9 @@ module.exports = function(core) {
|
|
|
34
37
|
const writeHead = patcher.unwrap(res.writeHead);
|
|
35
38
|
|
|
36
39
|
try {
|
|
40
|
+
clearTimeout(res[kMetrics]?.timeout);
|
|
41
|
+
delete res[kMetrics];
|
|
42
|
+
|
|
37
43
|
if (!res.headersSent) writeHead.call(res, 403);
|
|
38
44
|
end.call(res, '');
|
|
39
45
|
logger.info({ mode, ruleId }, 'Request blocked');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contrast/protect",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.38.0",
|
|
4
4
|
"description": "Contrast service providing framework-agnostic Protect support",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@contrast/agent-lib": "^7.0.1",
|
|
21
|
-
"@contrast/common": "1.21.
|
|
22
|
-
"@contrast/config": "1.28.
|
|
23
|
-
"@contrast/core": "1.32.
|
|
24
|
-
"@contrast/esm-hooks": "2.6.
|
|
21
|
+
"@contrast/common": "1.21.3",
|
|
22
|
+
"@contrast/config": "1.28.3",
|
|
23
|
+
"@contrast/core": "1.32.3",
|
|
24
|
+
"@contrast/esm-hooks": "2.6.3",
|
|
25
25
|
"@contrast/scopes": "1.4.1",
|
|
26
26
|
"ipaddr.js": "^2.0.1",
|
|
27
27
|
"semver": "^7.3.7"
|