@newrelic/security-agent 2.0.0 → 2.1.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/CHANGELOG.md +13 -0
- package/THIRD_PARTY_NOTICES.md +36 -6
- package/lib/instrumentation-security/core/request-manager.js +37 -7
- package/lib/instrumentation-security/core/sec-utils.js +5 -5
- package/lib/instrumentation-security/hooks/director/nr-director.js +6 -6
- package/lib/instrumentation-security/hooks/express/nr-express.js +11 -8
- package/lib/instrumentation-security/hooks/fastify/nr-fastify.js +6 -6
- package/lib/instrumentation-security/hooks/fs/nr-fs.js +6 -27
- package/lib/instrumentation-security/hooks/grpc-js/nr-grpc.js +4 -4
- package/lib/instrumentation-security/hooks/hapi/nr-hapi.js +7 -7
- package/lib/instrumentation-security/hooks/http/nr-http.js +15 -9
- package/lib/instrumentation-security/hooks/koa/@koa/nr-@koa-router.js +5 -5
- package/lib/instrumentation-security/hooks/ldap/nr-ldap.js +4 -0
- package/lib/instrumentation-security/hooks/mongodb/nr-mongodb.js +4 -0
- package/lib/instrumentation-security/hooks/mysql/nr-mysql.js +4 -0
- package/lib/instrumentation-security/hooks/native/nr-childProcess.js +4 -0
- package/lib/instrumentation-security/hooks/postgres/nr-postgres.js +4 -0
- package/lib/instrumentation-security/hooks/restify/nr-restify.js +7 -7
- package/lib/instrumentation-security/hooks/undici/nr-undici.js +4 -0
- package/lib/instrumentation-security/hooks/xpath/nr-xpath.js +4 -0
- package/lib/nr-security-agent/index.js +38 -5
- package/lib/nr-security-agent/lib/core/Auth-headers.js +19 -0
- package/lib/nr-security-agent/lib/core/ExceptionReporting.js +1 -0
- package/lib/nr-security-agent/lib/core/agent.js +3 -0
- package/lib/nr-security-agent/lib/core/commonUtils.js +132 -4
- package/lib/nr-security-agent/lib/core/connections/websocket/response/IASTUtils.js +28 -2
- package/lib/nr-security-agent/lib/core/connections/websocket/response/fuzz-request-handler.js +36 -4
- package/lib/nr-security-agent/lib/core/connections/websocket/response/startup-handshake-handler.js +5 -1
- package/lib/nr-security-agent/lib/core/connections/websocket/response/ws-reconnect.js +7 -4
- package/lib/nr-security-agent/lib/core/connections/websocket/websocket.js +17 -2
- package/lib/nr-security-agent/lib/core/health-check.js +6 -1
- package/lib/nr-security-agent/lib/core/sec-util.js +5 -1
- package/lib/nr-security-agent/lib/core/websocket-client.js +31 -8
- package/lib/nr-security-api/index.js +47 -15
- package/package.json +3 -2
|
@@ -70,22 +70,22 @@ const initialize = function () {
|
|
|
70
70
|
setInterval(sendHC, HC_INTERVAL_MS);
|
|
71
71
|
sendHC();
|
|
72
72
|
try {
|
|
73
|
-
let apiEndpoints =
|
|
74
|
-
let data
|
|
75
|
-
logger.debug("All API end points of the application is:",JSON.stringify(data));
|
|
73
|
+
let apiEndpoints = require('../../../instrumentation-security/core/route-manager').getAllAPIEndPoints();
|
|
74
|
+
let data = require('./apiEndpoints').APIEndPoint(apiEndpoints);
|
|
75
|
+
logger.debug("All API end points of the application is:", JSON.stringify(data));
|
|
76
76
|
getDispatcherAndSendEvent(data);
|
|
77
77
|
require('../core/ExceptionReporting').startExceptionSendingSchedular();
|
|
78
78
|
} catch (error) {
|
|
79
|
-
logger.debug("Error while processing API endpoints",error);
|
|
79
|
+
logger.debug("Error while processing API endpoints", error);
|
|
80
80
|
}
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
try {
|
|
83
83
|
const framework = NRAgent.environment.get('Framework')[0];
|
|
84
84
|
const dispatcher = NRAgent.environment.get('Dispatcher')[0];
|
|
85
85
|
const logMessage = new LogMessage.logMessage("INFO", `Detected framework: ${framework} and dispatcher: ${dispatcher}`, __filename, null);
|
|
86
86
|
commonUtils.addLogEventtoBuffer(logMessage);
|
|
87
87
|
} catch (error) {
|
|
88
|
-
logger.debug("Error while extracting data from APM environment",error);
|
|
88
|
+
logger.debug("Error while extracting data from APM environment", error);
|
|
89
89
|
}
|
|
90
90
|
}, 20000);
|
|
91
91
|
|
|
@@ -103,13 +103,26 @@ function initializeInMainThread() {
|
|
|
103
103
|
const validatorService = commonUtils.getValidatorServiceEndpointURL();
|
|
104
104
|
wsInstance = new SecWebSocket(validatorService, {}, logger);
|
|
105
105
|
dispatcher = function dispatcher(message) {
|
|
106
|
-
|
|
106
|
+
if (Agent.getAgent().status.getStatus() == 'active') {
|
|
107
|
+
wsInstance.dispatch(message);
|
|
108
|
+
}
|
|
107
109
|
};
|
|
108
110
|
} else {
|
|
109
111
|
return wsInstance;
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
|
|
115
|
+
function getTestIdentifier() {
|
|
116
|
+
try {
|
|
117
|
+
let authHeaders = require('./Auth-headers').getInstance();
|
|
118
|
+
let testIdentifer = authHeaders['NR-CSEC-IAST-TEST-IDENTIFIER'] ? authHeaders['NR-CSEC-IAST-TEST-IDENTIFIER'] : '';
|
|
119
|
+
return testIdentifer
|
|
120
|
+
} catch (error) {
|
|
121
|
+
logger.debug("unable to get test identifier", error);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
113
126
|
/**
|
|
114
127
|
* Sends Agent HelthCheck to Validator.
|
|
115
128
|
*/
|
|
@@ -143,12 +156,17 @@ const sendHC = async function () {
|
|
|
143
156
|
json.eventSendRejectionCount = json.eventRejectionCount;
|
|
144
157
|
json.eventSendErrorCount = json.eventProcessingErrorCount;
|
|
145
158
|
|
|
159
|
+
json.scanStartTime = commonUtils.scanStartTime;
|
|
160
|
+
json.trafficStartedTime = commonUtils.trafficStartedTime;
|
|
161
|
+
json.iastTestIdentifer = getTestIdentifier();
|
|
162
|
+
|
|
146
163
|
hc.getInstance().resetDropCount();
|
|
147
164
|
hc.getInstance().resetProcessedCount();
|
|
148
165
|
hc.getInstance().resetEventSentCount();
|
|
149
166
|
hc.getInstance().resetHttpRequestCount();
|
|
150
167
|
hc.getInstance().resetEventStats();
|
|
151
168
|
|
|
169
|
+
|
|
152
170
|
logger.info('Health Check Status:', JSON.stringify(json));
|
|
153
171
|
getDispatcherAndSendEvent(json);
|
|
154
172
|
}
|
|
@@ -190,9 +208,14 @@ function obeyReconnect() {
|
|
|
190
208
|
wsInstance.obeyReconnect();
|
|
191
209
|
}
|
|
192
210
|
|
|
211
|
+
function closeWS() {
|
|
212
|
+
wsInstance.closeWS();
|
|
213
|
+
}
|
|
214
|
+
|
|
193
215
|
module.exports = {
|
|
194
216
|
initialize,
|
|
195
217
|
write: sendEvent,
|
|
196
218
|
dispatcher: getDispatcherAndSendEvent,
|
|
197
|
-
obeyReconnect
|
|
219
|
+
obeyReconnect,
|
|
220
|
+
closeWS
|
|
198
221
|
};
|
|
@@ -10,7 +10,39 @@ let NRAgent;
|
|
|
10
10
|
*
|
|
11
11
|
* @returns NewRelic Agent instance
|
|
12
12
|
*/
|
|
13
|
-
function getNRAgent(){
|
|
13
|
+
function getNRAgent() {
|
|
14
|
+
if (NRAgent && NRAgent.config && !NRAgent.config.security.scan_schedule) {
|
|
15
|
+
NRAgent.config.security.scan_schedule = {};
|
|
16
|
+
NRAgent.config.security.scan_schedule.delay = 0;
|
|
17
|
+
NRAgent.config.security.scan_schedule.duration = 0;
|
|
18
|
+
NRAgent.config.security.scan_schedule.schedule = '';
|
|
19
|
+
NRAgent.config.security.scan_schedule.always_sample_traces = false;
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
if ( NRAgent && NRAgent.config && !NRAgent.config.security.scan_controllers) {
|
|
23
|
+
NRAgent.config.security.scan_controllers = {};
|
|
24
|
+
NRAgent.config.security.scan_controllers.iast_scan_request_rate_limit = 3600;
|
|
25
|
+
NRAgent.config.security.scan_controllers.scan_instance_count = 0;
|
|
26
|
+
}
|
|
27
|
+
if (NRAgent && NRAgent.config && !NRAgent.config.security.exclude_from_iast_scan) {
|
|
28
|
+
NRAgent.config.security.exclude_from_iast_scan = {};
|
|
29
|
+
NRAgent.config.security.exclude_from_iast_scan.api = [];
|
|
30
|
+
NRAgent.config.security.exclude_from_iast_scan.http_request_parameters = {};
|
|
31
|
+
NRAgent.config.security.exclude_from_iast_scan.http_request_parameters.header = [];
|
|
32
|
+
NRAgent.config.security.exclude_from_iast_scan.http_request_parameters.query = [];
|
|
33
|
+
NRAgent.config.security.exclude_from_iast_scan.http_request_parameters.body = [];
|
|
34
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category = {};
|
|
35
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.insecure_settings = false;
|
|
36
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.invalid_file_access = false;
|
|
37
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.sql_injection = false;
|
|
38
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.nosql_injection = false;
|
|
39
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.ldap_injection = false;
|
|
40
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.javascript_injection = false;
|
|
41
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.command_injection = false;
|
|
42
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.xpath_injection = false;
|
|
43
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.ssrf = false;
|
|
44
|
+
NRAgent.config.security.exclude_from_iast_scan.iast_detection_category.rxss = false;
|
|
45
|
+
}
|
|
14
46
|
return NRAgent;
|
|
15
47
|
}
|
|
16
48
|
|
|
@@ -18,7 +50,7 @@ function getNRAgent(){
|
|
|
18
50
|
* API to set newrelic agent object.
|
|
19
51
|
* @param {*} agent
|
|
20
52
|
*/
|
|
21
|
-
function setNRAgent(agent){
|
|
53
|
+
function setNRAgent(agent) {
|
|
22
54
|
NRAgent = agent;
|
|
23
55
|
}
|
|
24
56
|
|
|
@@ -26,11 +58,11 @@ function setNRAgent(agent){
|
|
|
26
58
|
* API to get security agent
|
|
27
59
|
* @returns Security Agent instanace
|
|
28
60
|
*/
|
|
29
|
-
function getSecAgent(){
|
|
61
|
+
function getSecAgent() {
|
|
30
62
|
const Agent = require('../nr-security-agent/lib/core/agent').Agent;
|
|
31
63
|
const csecAgent = Agent.getAgent();
|
|
32
|
-
if(csecAgent){
|
|
33
|
-
|
|
64
|
+
if (csecAgent) {
|
|
65
|
+
return csecAgent;
|
|
34
66
|
}
|
|
35
67
|
}
|
|
36
68
|
|
|
@@ -38,11 +70,11 @@ function getSecAgent(){
|
|
|
38
70
|
* API to get status of security agent
|
|
39
71
|
* @returns Security Agent status
|
|
40
72
|
*/
|
|
41
|
-
function getSecAgentStatus(){
|
|
73
|
+
function getSecAgentStatus() {
|
|
42
74
|
const Agent = require('../nr-security-agent/lib/core/agent').Agent;
|
|
43
|
-
if(Agent.getAgent()){
|
|
75
|
+
if (Agent.getAgent()) {
|
|
44
76
|
return Agent.getAgent().status.getStatus()
|
|
45
|
-
|
|
77
|
+
}
|
|
46
78
|
}
|
|
47
79
|
|
|
48
80
|
/**
|
|
@@ -50,15 +82,15 @@ function getSecAgentStatus(){
|
|
|
50
82
|
* @param {*} securityMetadata
|
|
51
83
|
* @returns security event object
|
|
52
84
|
*/
|
|
53
|
-
function generateSecEvent(securityMetadata){
|
|
54
|
-
|
|
85
|
+
function generateSecEvent(securityMetadata) {
|
|
86
|
+
return require('../nr-security-agent/lib/core/sec-util').generateSecEvent(securityMetadata);
|
|
55
87
|
}
|
|
56
88
|
|
|
57
89
|
/**
|
|
58
90
|
* API to send security event
|
|
59
91
|
* @param {*} secEvent
|
|
60
92
|
*/
|
|
61
|
-
function sendEvent(secEvent){
|
|
93
|
+
function sendEvent(secEvent) {
|
|
62
94
|
require('../nr-security-agent/lib/core/sec-util').sendEvent(secEvent);
|
|
63
95
|
}
|
|
64
96
|
|
|
@@ -66,7 +98,7 @@ function sendEvent(secEvent){
|
|
|
66
98
|
* API to get logger instance
|
|
67
99
|
* @returns
|
|
68
100
|
*/
|
|
69
|
-
function getLogger(){
|
|
101
|
+
function getLogger() {
|
|
70
102
|
return require('../nr-security-agent/lib/core/logging').getLogger();
|
|
71
103
|
}
|
|
72
104
|
/**
|
|
@@ -76,7 +108,7 @@ function getLogger(){
|
|
|
76
108
|
* @param {*} responseHeaders
|
|
77
109
|
* @returns
|
|
78
110
|
*/
|
|
79
|
-
function checkForReflectedXSS(secRequest, responseBody, responseHeaders){
|
|
111
|
+
function checkForReflectedXSS(secRequest, responseBody, responseHeaders) {
|
|
80
112
|
return require('../nr-security-agent/lib/core/xss-utils').checkForReflectedXSS(secRequest, responseBody, responseHeaders);
|
|
81
113
|
}
|
|
82
114
|
|
|
@@ -84,7 +116,7 @@ function checkForReflectedXSS(secRequest, responseBody, responseHeaders){
|
|
|
84
116
|
* API to get security agent policy
|
|
85
117
|
* @returns security agent policy
|
|
86
118
|
*/
|
|
87
|
-
function getPolicy(){
|
|
119
|
+
function getPolicy() {
|
|
88
120
|
return require('../nr-security-agent/lib/core/Policy').getInstance();
|
|
89
121
|
}
|
|
90
122
|
|
|
@@ -92,7 +124,7 @@ function getPolicy(){
|
|
|
92
124
|
* API to generate Exit event
|
|
93
125
|
* @param {*} event
|
|
94
126
|
*/
|
|
95
|
-
function generateExitEvent(event){
|
|
127
|
+
function generateExitEvent(event) {
|
|
96
128
|
require('../nr-security-agent/lib/core/sec-util').generateExitEvent(event);
|
|
97
129
|
}
|
|
98
130
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@newrelic/security-agent",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "New Relic Security Agent for Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"jsonVersion": "1.2.
|
|
6
|
+
"jsonVersion": "1.2.9",
|
|
7
7
|
"contributors": [
|
|
8
8
|
{
|
|
9
9
|
"name": "Sumit Suthar",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"axios": "^1.7.4",
|
|
43
43
|
"check-disk-space": "^3.4.0",
|
|
44
44
|
"content-type": "^1.0.5",
|
|
45
|
+
"cron": "^3.1.7",
|
|
45
46
|
"fast-safe-stringify": "^2.1.1",
|
|
46
47
|
"find-package-json": "^1.2.0",
|
|
47
48
|
"hash.js": "^1.1.7",
|