@newrelic/security-agent 0.0.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.
Files changed (87) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/CONTRIBUTING.md +23 -0
  3. package/LICENSE +43 -0
  4. package/README.md +98 -0
  5. package/THIRD_PARTY_NOTICES.md +2909 -0
  6. package/index.js +24 -0
  7. package/lib/instrumentation-security/core/constants.js +66 -0
  8. package/lib/instrumentation-security/core/event-constants.js +49 -0
  9. package/lib/instrumentation-security/core/request-manager.js +73 -0
  10. package/lib/instrumentation-security/core/route-manager.js +30 -0
  11. package/lib/instrumentation-security/core/sec-trace.js +134 -0
  12. package/lib/instrumentation-security/core/sec-utils.js +212 -0
  13. package/lib/instrumentation-security/core/security-metadata.js +34 -0
  14. package/lib/instrumentation-security/core/stack-trace.js +156 -0
  15. package/lib/instrumentation-security/hooks/director/nr-director.js +98 -0
  16. package/lib/instrumentation-security/hooks/express/nr-express.js +106 -0
  17. package/lib/instrumentation-security/hooks/fastify/nr-fastify.js +155 -0
  18. package/lib/instrumentation-security/hooks/fs/nr-fs.js +391 -0
  19. package/lib/instrumentation-security/hooks/hapi/nr-hapi.js +131 -0
  20. package/lib/instrumentation-security/hooks/http/nr-http.js +461 -0
  21. package/lib/instrumentation-security/hooks/koa/@koa/nr-@koa-router.js +110 -0
  22. package/lib/instrumentation-security/hooks/ldap/nr-ldap.js +81 -0
  23. package/lib/instrumentation-security/hooks/mongodb/common.js +239 -0
  24. package/lib/instrumentation-security/hooks/mongodb/constants.js +91 -0
  25. package/lib/instrumentation-security/hooks/mongodb/nr-mongodb.js +49 -0
  26. package/lib/instrumentation-security/hooks/mongodb/v2-mongo.js +91 -0
  27. package/lib/instrumentation-security/hooks/mongodb/v3-mongo.js +36 -0
  28. package/lib/instrumentation-security/hooks/mongodb/v4-mongo.js +17 -0
  29. package/lib/instrumentation-security/hooks/mysql/nr-mysql.js +232 -0
  30. package/lib/instrumentation-security/hooks/native/nr-childProcess.js +131 -0
  31. package/lib/instrumentation-security/hooks/postgres/nr-postgres.js +131 -0
  32. package/lib/instrumentation-security/hooks/require/nr-require.js +93 -0
  33. package/lib/instrumentation-security/hooks/restify/nr-restify.js +104 -0
  34. package/lib/instrumentation-security/hooks/xpath/nr-xpath.js +91 -0
  35. package/lib/instrumentation-security/index.js +171 -0
  36. package/lib/nr-security-agent/index.js +170 -0
  37. package/lib/nr-security-agent/lib/core/Auth-headers.js +58 -0
  38. package/lib/nr-security-agent/lib/core/ContainerProperties.js +42 -0
  39. package/lib/nr-security-agent/lib/core/ECSProperties.js +34 -0
  40. package/lib/nr-security-agent/lib/core/FuzzFailEvent.js +27 -0
  41. package/lib/nr-security-agent/lib/core/LinkingMetadata.js +21 -0
  42. package/lib/nr-security-agent/lib/core/LogMessage.js +47 -0
  43. package/lib/nr-security-agent/lib/core/PodProperties.js +36 -0
  44. package/lib/nr-security-agent/lib/core/Policy.js +105 -0
  45. package/lib/nr-security-agent/lib/core/agent-status.js +56 -0
  46. package/lib/nr-security-agent/lib/core/agent.js +146 -0
  47. package/lib/nr-security-agent/lib/core/applicationinfo.js +634 -0
  48. package/lib/nr-security-agent/lib/core/commonUtils.js +411 -0
  49. package/lib/nr-security-agent/lib/core/connections/aws-lambda-client.js +55 -0
  50. package/lib/nr-security-agent/lib/core/connections/restclient.js +20 -0
  51. package/lib/nr-security-agent/lib/core/connections/websocket/index.js +25 -0
  52. package/lib/nr-security-agent/lib/core/connections/websocket/response/collecotor-policy-error-handler.js +18 -0
  53. package/lib/nr-security-agent/lib/core/connections/websocket/response/collector-policy-handler.js +20 -0
  54. package/lib/nr-security-agent/lib/core/connections/websocket/response/fuzz-request-handler.js +171 -0
  55. package/lib/nr-security-agent/lib/core/connections/websocket/response/index.js +47 -0
  56. package/lib/nr-security-agent/lib/core/connections/websocket/response/no-op-handler.js +12 -0
  57. package/lib/nr-security-agent/lib/core/connections/websocket/response/startup-handshake-handler.js +27 -0
  58. package/lib/nr-security-agent/lib/core/connections/websocket/response/unsupported-agent-handler.js +18 -0
  59. package/lib/nr-security-agent/lib/core/connections/websocket/response/ws-reconnect.js +14 -0
  60. package/lib/nr-security-agent/lib/core/connections/websocket/websocket.js +443 -0
  61. package/lib/nr-security-agent/lib/core/event.js +186 -0
  62. package/lib/nr-security-agent/lib/core/health-check.js +159 -0
  63. package/lib/nr-security-agent/lib/core/json-file-handler.js +66 -0
  64. package/lib/nr-security-agent/lib/core/jsonValidator.js +149 -0
  65. package/lib/nr-security-agent/lib/core/lambda-delegated-task-service.js +90 -0
  66. package/lib/nr-security-agent/lib/core/logging.js +176 -0
  67. package/lib/nr-security-agent/lib/core/sec-agent-constants.js +173 -0
  68. package/lib/nr-security-agent/lib/core/sec-util.js +166 -0
  69. package/lib/nr-security-agent/lib/core/sha-size-util.js +338 -0
  70. package/lib/nr-security-agent/lib/core/sha_worker.js +24 -0
  71. package/lib/nr-security-agent/lib/core/startup-config.js +29 -0
  72. package/lib/nr-security-agent/lib/core/statusUtils.js +157 -0
  73. package/lib/nr-security-agent/lib/core/timeunit.js +44 -0
  74. package/lib/nr-security-agent/lib/core/websocket-client.js +335 -0
  75. package/lib/nr-security-agent/lib/core/worker-entities.js +82 -0
  76. package/lib/nr-security-agent/lib/core/worker.js +148 -0
  77. package/lib/nr-security-agent/lib/core/xss-utils.js +297 -0
  78. package/lib/nr-security-agent/lib/models/lambda-delegated-task/constants.js +12 -0
  79. package/lib/nr-security-agent/lib/models/lambda-delegated-task/index.js +15 -0
  80. package/lib/nr-security-agent/lib/models/lambda-delegated-task/lambda-delegated-sha-calculation.js +37 -0
  81. package/lib/nr-security-agent/lib/models/lambda-delegated-task/lambda-delegated-task-base.js +50 -0
  82. package/lib/nr-security-agent/lib/models/lambda-delegated-task/lambda-delegated-task-type.js +17 -0
  83. package/lib/nr-security-agent/resources/cert.pem +31 -0
  84. package/lib/nr-security-agent/resources/config.js +19 -0
  85. package/lib/nr-security-agent/resources/default-policy.yaml +36 -0
  86. package/lib/nr-security-api/index.js +111 -0
  87. package/package.json +95 -0
@@ -0,0 +1,111 @@
1
+ /*
2
+ * Copyright 2023 New Relic Corporation. All rights reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+
6
+ let newrelic;
7
+ let NRAgent;
8
+
9
+ /**
10
+ *
11
+ * @returns NewRelic Agent instance
12
+ */
13
+ function getNRAgent(){
14
+ return NRAgent;
15
+ }
16
+
17
+ /**
18
+ * API to set newrelic agent object.
19
+ * @param {*} agent
20
+ */
21
+ function setNRAgent(agent){
22
+ NRAgent = agent;
23
+ }
24
+
25
+ /**
26
+ * API to get security agent
27
+ * @returns Security Agent instanace
28
+ */
29
+ function getSecAgent(){
30
+ const Agent = require('../nr-security-agent/lib/core/agent').Agent;
31
+ const csecAgent = Agent.getAgent();
32
+ if(csecAgent){
33
+ return csecAgent;
34
+ }
35
+ }
36
+
37
+ /**
38
+ * API to get status of security agent
39
+ * @returns Security Agent status
40
+ */
41
+ function getSecAgentStatus(){
42
+ const Agent = require('../nr-security-agent/lib/core/agent').Agent;
43
+ if(Agent.getAgent()){
44
+ return Agent.getAgent().status.getStatus()
45
+ }
46
+ }
47
+
48
+ /**
49
+ * API to generate security event from the intermediate data
50
+ * @param {*} securityMetadata
51
+ * @returns security event object
52
+ */
53
+ function generateSecEvent(securityMetadata){
54
+ return require('../nr-security-agent/lib/core/sec-util').generateSecEvent(securityMetadata);
55
+ }
56
+
57
+ /**
58
+ * API to send security event
59
+ * @param {*} secEvent
60
+ */
61
+ function sendEvent(secEvent){
62
+ require('../nr-security-agent/lib/core/sec-util').sendEvent(secEvent);
63
+ }
64
+
65
+ /**
66
+ * API to get logger instance
67
+ * @returns
68
+ */
69
+ function getLogger(){
70
+ return require('../nr-security-agent/lib/core/logging').getLogger();
71
+ }
72
+ /**
73
+ * API to validate RXSS
74
+ * @param {*} secRequest
75
+ * @param {*} responseBody
76
+ * @param {*} responseHeaders
77
+ * @returns
78
+ */
79
+ function checkForReflectedXSS(secRequest, responseBody, responseHeaders){
80
+ return require('../nr-security-agent/lib/core/xss-utils').checkForReflectedXSS(secRequest, responseBody, responseHeaders);
81
+ }
82
+
83
+ /**
84
+ * API to get security agent policy
85
+ * @returns security agent policy
86
+ */
87
+ function getPolicy(){
88
+ return require('../nr-security-agent/lib/core/Policy').getInstance();
89
+ }
90
+
91
+ /**
92
+ * API to generate Exit event
93
+ * @param {*} event
94
+ */
95
+ function generateExitEvent(event){
96
+ require('../nr-security-agent/lib/core/sec-util').generateExitEvent(event);
97
+ }
98
+
99
+ module.exports = {
100
+ newrelic,
101
+ getNRAgent,
102
+ getSecAgent,
103
+ getSecAgentStatus,
104
+ generateSecEvent,
105
+ sendEvent,
106
+ getLogger,
107
+ checkForReflectedXSS,
108
+ getPolicy,
109
+ generateExitEvent,
110
+ setNRAgent
111
+ }
package/package.json ADDED
@@ -0,0 +1,95 @@
1
+ {
2
+ "name": "@newrelic/security-agent",
3
+ "version": "0.0.1",
4
+ "description": "Newrelic Security Agent for Node.js",
5
+ "main": "index.js",
6
+ "collectorVersion": "1.0.1-limited-preview",
7
+ "buildNumber": 103,
8
+ "jsonVersion": "1.0.1",
9
+ "contributors": [
10
+ {
11
+ "name": "Sumit Suthar",
12
+ "email": "ssuthar@newrelic.com",
13
+ "web": "http://newrelic.com"
14
+ },
15
+ {
16
+ "name": "Pratik Gunjetiya",
17
+ "email": "pgunjetiya@newrelic.com",
18
+ "web": "http://newrelic.com"
19
+ }
20
+ ],
21
+ "scripts": {
22
+ "test": "tap --test-regex='(\\/|^test\\/instrumentation-security\\/.*\\.test\\.js)$' --no-coverage",
23
+ "posttest": "rm -f newrelic_agent.log && rm -rf nr-security-home && rm -rf .nyc_output",
24
+ "third-party-updates": "oss third-party manifest && oss third-party notices && git add THIRD_PARTY_NOTICES.md third_party_manifest.json"
25
+ },
26
+ "keywords": [],
27
+ "author": "newrelic",
28
+ "license": "Apache-2.0",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/newrelic/csec-node-agent.git"
32
+ },
33
+ "dependencies": {
34
+ "@aws-sdk/client-lambda": "3.276.0",
35
+ "axios": "0.21.4",
36
+ "check-disk-space": "^3.1.0",
37
+ "content-type": "^1.0.4",
38
+ "fast-safe-stringify": "^2.0.7",
39
+ "find-package-json": "^1.2.0",
40
+ "hash.js": "^1.1.7",
41
+ "html-entities": "^1.2.1",
42
+ "is-invalid-path": "^1.0.2",
43
+ "js-yaml": "^4.1.0",
44
+ "jsonschema": "^1.4.0",
45
+ "lodash": "^4.17.21",
46
+ "log4js": "^6.0.0",
47
+ "pretty-bytes": "^5.6.0",
48
+ "request-ip": "^2.1.3",
49
+ "ringbufferjs": "^2.0.0",
50
+ "semver": "^6.3.0",
51
+ "sync-request": "^6.1.0",
52
+ "unescape": "^1.0.1",
53
+ "unescape-js": "^1.1.4",
54
+ "uuid": "^3.4.0",
55
+ "ws": "^7.5.9"
56
+ },
57
+ "devDependencies": {
58
+ "@hapi/hapi": "^21.3.0",
59
+ "@koa/router": "^12.0.0",
60
+ "@newrelic/newrelic-oss-cli": "^0.1.2",
61
+ "@newrelic/test-utilities": "7.2.1",
62
+ "@typescript-eslint/eslint-plugin": "^4.15.0",
63
+ "@typescript-eslint/parser": "^4.15.0",
64
+ "director": "^1.2.8",
65
+ "eslint-config-prettier": "^8.3.0",
66
+ "eslint-config-standard": "^16.0.3",
67
+ "eslint-plugin-disable": "^2.0.1",
68
+ "eslint-plugin-header": "^3.1.1",
69
+ "eslint-plugin-import": "^2.23.4",
70
+ "eslint-plugin-jsdoc": "^39.3.6",
71
+ "eslint-plugin-node": "^11.1.0",
72
+ "eslint-plugin-prettier": "^3.4.0",
73
+ "eslint-plugin-promise": "^4.3.1",
74
+ "eslint-plugin-sonarjs": "^0.15.0",
75
+ "koa": "^2.14.1",
76
+ "mongodb": "^4.13.0",
77
+ "mongodb-memory-server": "^8.11.2",
78
+ "mongodb2": "npm:mongodb@^2.2.36",
79
+ "mongodb3": "npm:mongodb@^3.7.3",
80
+ "newrelic": "^9.15.0",
81
+ "request": "^2.88.2",
82
+ "restify": "^11.1.0",
83
+ "sinon": "^15.0.0",
84
+ "tap": "^16.3.2",
85
+ "xmldom": "^0.6.0",
86
+ "xpath": "^0.0.32",
87
+ "xpath.js": "^1.1.0"
88
+ },
89
+ "files": [
90
+ "index.js",
91
+ "*.md",
92
+ "LICENSE",
93
+ "lib/"
94
+ ]
95
+ }