@contrast/agent 4.5.1 → 4.7.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 (209) hide show
  1. package/bin/VERSION +1 -1
  2. package/bin/linux/contrast-service +0 -0
  3. package/bin/mac/contrast-service +0 -0
  4. package/bin/windows/contrast-service.exe +0 -0
  5. package/lib/assess/membrane/deserialization-membrane.js +4 -5
  6. package/lib/assess/membrane/source-membrane.js +16 -33
  7. package/lib/assess/models/call-context.js +1 -1
  8. package/lib/assess/policy/propagators.json +19 -21
  9. package/lib/assess/policy/rules.json +7 -2
  10. package/lib/assess/policy/signatures.json +42 -0
  11. package/lib/assess/policy/util.js +2 -1
  12. package/lib/assess/propagators/JSON/parse.js +1 -1
  13. package/lib/assess/propagators/JSON/stringify.js +3 -3
  14. package/lib/assess/propagators/array-prototype-join.js +7 -8
  15. package/lib/assess/propagators/common.js +7 -5
  16. package/lib/assess/propagators/dustjs/escape-html.js +22 -0
  17. package/lib/assess/propagators/dustjs/escape-js.js +22 -0
  18. package/lib/assess/propagators/encode-uri/encode-uri-component.js +22 -0
  19. package/lib/assess/propagators/encode-uri/encode-uri.js +22 -0
  20. package/lib/assess/propagators/handlebars-escape-expresssion.js +1 -1
  21. package/lib/assess/propagators/index.js +0 -2
  22. package/lib/assess/propagators/joi/boolean.js +1 -1
  23. package/lib/assess/propagators/joi/expression.js +1 -1
  24. package/lib/assess/propagators/joi/number.js +1 -1
  25. package/lib/assess/propagators/joi/string-base.js +1 -1
  26. package/lib/assess/propagators/joi/string-schema.js +12 -13
  27. package/lib/assess/propagators/joi/values.js +37 -22
  28. package/lib/assess/propagators/manager.js +12 -10
  29. package/lib/assess/propagators/mongoose/helpers.js +20 -0
  30. package/lib/assess/propagators/mongoose/index.js +18 -0
  31. package/lib/assess/propagators/mongoose/map.js +74 -0
  32. package/lib/assess/propagators/mongoose/string.js +104 -0
  33. package/lib/assess/propagators/mustache/escape.js +22 -0
  34. package/lib/assess/propagators/number.js +54 -0
  35. package/lib/assess/propagators/object.js +6 -7
  36. package/lib/assess/propagators/path/basename.js +14 -13
  37. package/lib/assess/propagators/path/common.js +156 -47
  38. package/lib/assess/propagators/path/dirname.js +14 -13
  39. package/lib/assess/propagators/path/extname.js +14 -13
  40. package/lib/assess/propagators/path/join.js +5 -1
  41. package/lib/assess/propagators/path/normalize.js +1 -2
  42. package/lib/assess/propagators/path/parse.js +1 -1
  43. package/lib/assess/propagators/path/relative.js +7 -5
  44. package/lib/assess/propagators/path/resolve.js +11 -2
  45. package/lib/assess/propagators/querystring/escape.js +20 -18
  46. package/lib/assess/propagators/querystring/parse.js +7 -5
  47. package/lib/assess/propagators/querystring/stringify.js +25 -24
  48. package/lib/assess/propagators/querystring/unescape.js +20 -18
  49. package/lib/assess/propagators/sequelize/sql-string-escape.js +1 -1
  50. package/lib/assess/propagators/sequelize/sql-string-format-named-parameters.js +1 -1
  51. package/lib/assess/propagators/sequelize/sql-string-format.js +3 -3
  52. package/lib/assess/propagators/sequelize/utils.js +2 -2
  53. package/lib/assess/propagators/string-prototype-replace.js +30 -28
  54. package/lib/assess/propagators/string-prototype-split.js +36 -36
  55. package/lib/assess/propagators/string-prototype-trim.js +15 -17
  56. package/lib/assess/propagators/string.js +12 -16
  57. package/lib/assess/propagators/template-escape.js +87 -0
  58. package/lib/assess/propagators/templates.js +10 -11
  59. package/lib/assess/propagators/url/url-prototype-parse.js +5 -6
  60. package/lib/assess/propagators/url/url-url.js +51 -43
  61. package/lib/assess/propagators/util/format.js +1 -1
  62. package/lib/assess/propagators/v8/init-hooks.js +3 -3
  63. package/lib/assess/propagators/validator/init-hooks.js +22 -22
  64. package/lib/assess/sinks/common.js +10 -5
  65. package/lib/assess/sinks/dustjs-linkedin-xss.js +131 -0
  66. package/lib/assess/sinks/libxmljs-xxe.js +1 -1
  67. package/lib/assess/sinks/mongodb.js +2 -1
  68. package/lib/assess/sinks/ssrf-url.js +1 -1
  69. package/lib/constants.js +4 -1
  70. package/lib/core/arch-components/dynamodb.js +1 -2
  71. package/lib/core/arch-components/dynamodbv3.js +44 -0
  72. package/lib/core/arch-components/index.js +1 -0
  73. package/lib/core/arch-components/rethinkdb.js +53 -0
  74. package/lib/core/config/options.js +3 -2
  75. package/lib/core/rewrite/injections.js +8 -0
  76. package/lib/core/stacktrace.js +2 -1
  77. package/lib/feature-set.js +1 -1
  78. package/lib/hooks/frameworks/base.js +8 -2
  79. package/lib/hooks/frameworks/http.js +23 -16
  80. package/lib/hooks/frameworks/http2.js +73 -0
  81. package/lib/hooks/frameworks/index.js +8 -3
  82. package/lib/hooks/http.js +112 -128
  83. package/lib/hooks/object-to-primitive.js +6 -7
  84. package/lib/hooks/patcher.js +75 -44
  85. package/lib/hooks/require.js +16 -22
  86. package/lib/instrumentation.js +0 -3
  87. package/lib/protect/rules/nosqli/nosql-injection-rule.js +228 -0
  88. package/lib/protect/rules/rule-factory.js +2 -2
  89. package/lib/protect/service.js +23 -11
  90. package/lib/protect/sinks/mongodb.js +56 -55
  91. package/lib/reporter/translations/to-protobuf/dtm/index.js +1 -1
  92. package/lib/reporter/translations/to-protobuf/dtm/ip-denylist-details.js +1 -1
  93. package/lib/reporter/translations/to-protobuf/dtm/rasp-rule-sample.js +1 -1
  94. package/lib/reporter/translations/to-protobuf/settings/defend-features.js +8 -6
  95. package/lib/reporter/translations/to-protobuf/settings/exclusions.js +5 -4
  96. package/lib/tracker.js +13 -65
  97. package/lib/util/some.js +27 -0
  98. package/lib/util/source-map.js +1 -1
  99. package/package.json +15 -16
  100. package/lib/hooks/frameworks/https.js +0 -42
  101. package/lib/protect/rules/nosqli/no-sql-injection-rule.js +0 -109
  102. package/node_modules/bindings/LICENSE.md +0 -22
  103. package/node_modules/bindings/README.md +0 -98
  104. package/node_modules/bindings/bindings.js +0 -221
  105. package/node_modules/bindings/package.json +0 -32
  106. package/node_modules/file-uri-to-path/.npmignore +0 -1
  107. package/node_modules/file-uri-to-path/.travis.yml +0 -30
  108. package/node_modules/file-uri-to-path/History.md +0 -21
  109. package/node_modules/file-uri-to-path/LICENSE +0 -20
  110. package/node_modules/file-uri-to-path/README.md +0 -74
  111. package/node_modules/file-uri-to-path/index.d.ts +0 -2
  112. package/node_modules/file-uri-to-path/index.js +0 -66
  113. package/node_modules/file-uri-to-path/package.json +0 -36
  114. package/node_modules/file-uri-to-path/test/test.js +0 -24
  115. package/node_modules/file-uri-to-path/test/tests.json +0 -13
  116. package/node_modules/glossy/LICENSE +0 -19
  117. package/node_modules/glossy/README.md +0 -129
  118. package/node_modules/glossy/index.js +0 -12
  119. package/node_modules/glossy/lib/glossy/parse.js +0 -520
  120. package/node_modules/glossy/lib/glossy/produce.js +0 -459
  121. package/node_modules/glossy/package.json +0 -47
  122. package/node_modules/glossy/test/decide.js +0 -7
  123. package/node_modules/glossy/test/decode_pri.js +0 -24
  124. package/node_modules/glossy/test/parse_3164.js +0 -104
  125. package/node_modules/glossy/test/parse_5424.js +0 -106
  126. package/node_modules/glossy/test/parse_5848.js +0 -40
  127. package/node_modules/glossy/test/parse_8601.js +0 -14
  128. package/node_modules/glossy/test/parse_rfc3339.js +0 -9
  129. package/node_modules/glossy/test/produce.js +0 -162
  130. package/node_modules/glossy/test/runner.js +0 -40
  131. package/node_modules/glossy/test/structure_data.js +0 -24
  132. package/node_modules/nan/CHANGELOG.md +0 -537
  133. package/node_modules/nan/LICENSE.md +0 -13
  134. package/node_modules/nan/README.md +0 -455
  135. package/node_modules/nan/doc/asyncworker.md +0 -146
  136. package/node_modules/nan/doc/buffers.md +0 -54
  137. package/node_modules/nan/doc/callback.md +0 -76
  138. package/node_modules/nan/doc/converters.md +0 -41
  139. package/node_modules/nan/doc/errors.md +0 -226
  140. package/node_modules/nan/doc/json.md +0 -62
  141. package/node_modules/nan/doc/maybe_types.md +0 -583
  142. package/node_modules/nan/doc/methods.md +0 -664
  143. package/node_modules/nan/doc/new.md +0 -147
  144. package/node_modules/nan/doc/node_misc.md +0 -123
  145. package/node_modules/nan/doc/object_wrappers.md +0 -263
  146. package/node_modules/nan/doc/persistent.md +0 -296
  147. package/node_modules/nan/doc/scopes.md +0 -73
  148. package/node_modules/nan/doc/script.md +0 -38
  149. package/node_modules/nan/doc/string_bytes.md +0 -62
  150. package/node_modules/nan/doc/v8_internals.md +0 -199
  151. package/node_modules/nan/doc/v8_misc.md +0 -85
  152. package/node_modules/nan/include_dirs.js +0 -1
  153. package/node_modules/nan/nan.h +0 -2898
  154. package/node_modules/nan/nan_callbacks.h +0 -88
  155. package/node_modules/nan/nan_callbacks_12_inl.h +0 -514
  156. package/node_modules/nan/nan_callbacks_pre_12_inl.h +0 -520
  157. package/node_modules/nan/nan_converters.h +0 -72
  158. package/node_modules/nan/nan_converters_43_inl.h +0 -68
  159. package/node_modules/nan/nan_converters_pre_43_inl.h +0 -42
  160. package/node_modules/nan/nan_define_own_property_helper.h +0 -29
  161. package/node_modules/nan/nan_implementation_12_inl.h +0 -430
  162. package/node_modules/nan/nan_implementation_pre_12_inl.h +0 -263
  163. package/node_modules/nan/nan_json.h +0 -166
  164. package/node_modules/nan/nan_maybe_43_inl.h +0 -356
  165. package/node_modules/nan/nan_maybe_pre_43_inl.h +0 -268
  166. package/node_modules/nan/nan_new.h +0 -340
  167. package/node_modules/nan/nan_object_wrap.h +0 -156
  168. package/node_modules/nan/nan_persistent_12_inl.h +0 -132
  169. package/node_modules/nan/nan_persistent_pre_12_inl.h +0 -242
  170. package/node_modules/nan/nan_private.h +0 -73
  171. package/node_modules/nan/nan_string_bytes.h +0 -305
  172. package/node_modules/nan/nan_typedarray_contents.h +0 -96
  173. package/node_modules/nan/nan_weak.h +0 -437
  174. package/node_modules/nan/package.json +0 -41
  175. package/node_modules/nan/tools/1to2.js +0 -412
  176. package/node_modules/nan/tools/README.md +0 -14
  177. package/node_modules/nan/tools/package.json +0 -19
  178. package/node_modules/unix-dgram/LICENSE +0 -13
  179. package/node_modules/unix-dgram/README.md +0 -107
  180. package/node_modules/unix-dgram/binding.gyp +0 -20
  181. package/node_modules/unix-dgram/build/Makefile +0 -324
  182. package/node_modules/unix-dgram/build/Release/.deps/Release/obj.target/unix_dgram/src/unix_dgram.o.d +0 -58
  183. package/node_modules/unix-dgram/build/Release/.deps/Release/obj.target/unix_dgram.node.d +0 -1
  184. package/node_modules/unix-dgram/build/Release/.deps/Release/unix_dgram.node.d +0 -1
  185. package/node_modules/unix-dgram/build/Release/obj.target/unix_dgram/src/unix_dgram.o +0 -0
  186. package/node_modules/unix-dgram/build/Release/obj.target/unix_dgram.node +0 -0
  187. package/node_modules/unix-dgram/build/Release/unix_dgram.node +0 -0
  188. package/node_modules/unix-dgram/build/binding.Makefile +0 -6
  189. package/node_modules/unix-dgram/build/config.gypi +0 -213
  190. package/node_modules/unix-dgram/build/unix_dgram.target.mk +0 -159
  191. package/node_modules/unix-dgram/lib/unix_dgram.js +0 -168
  192. package/node_modules/unix-dgram/package.json +0 -36
  193. package/node_modules/unix-dgram/src/unix_dgram.cc +0 -404
  194. package/node_modules/unix-dgram/src/win_dummy.cc +0 -7
  195. package/node_modules/unix-dgram/test/test-connect-callback.js +0 -68
  196. package/node_modules/unix-dgram/test/test-connect.js +0 -53
  197. package/node_modules/unix-dgram/test/test-dgram-unix.js +0 -58
  198. package/node_modules/unix-dgram/test/test-send-error.js +0 -26
  199. package/node_modules/winston-syslog/.eslintrc +0 -7
  200. package/node_modules/winston-syslog/.travis.yml +0 -14
  201. package/node_modules/winston-syslog/CHANGELOG.md +0 -9
  202. package/node_modules/winston-syslog/LICENSE +0 -20
  203. package/node_modules/winston-syslog/README.md +0 -135
  204. package/node_modules/winston-syslog/lib/utils.js +0 -26
  205. package/node_modules/winston-syslog/lib/winston-syslog.js +0 -385
  206. package/node_modules/winston-syslog/package.json +0 -56
  207. package/node_modules/winston-syslog/test/format-test.js +0 -122
  208. package/node_modules/winston-syslog/test/syslog-test.js +0 -95
  209. package/node_modules/winston-syslog/test/unix-connect-test.js +0 -133
@@ -1,109 +0,0 @@
1
- /**
2
- Copyright: 2021 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
- const _ = require('lodash');
16
-
17
- const logger = require('../../../core/logger')('contrast:rules:protect');
18
- const { INPUT_TYPES, SINK_TYPES } = require('../common');
19
-
20
- const MONGODB = 'mongodb';
21
-
22
- const ScannerKit = new Map([
23
- [MONGODB, () => require('../nosqli/nosql-scanner').create('MongoDB')]
24
- ]);
25
-
26
- class NoSqlInjectionRule extends require('../') {
27
- constructor(policy = {}) {
28
- policy.inputParseDepth = 3;
29
- super(policy);
30
-
31
- this._scanners = new Map();
32
-
33
- this.id = 'nosql-injection';
34
- this.name = 'NoSQL Injection';
35
- this.applicableInputs = [
36
- INPUT_TYPES.BODY,
37
- INPUT_TYPES.JSON_VALUE,
38
- INPUT_TYPES.JSON_ARRAYED_VALUE,
39
- INPUT_TYPES.PARAMETER_NAME,
40
- INPUT_TYPES.PARAMETER_VALUE,
41
- INPUT_TYPES.QUERYSTRING,
42
- INPUT_TYPES.XML_VALUE,
43
- INPUT_TYPES.URI,
44
- INPUT_TYPES.URL_PARAMETER
45
- ];
46
- this.applicableSinks = [SINK_TYPES.NOSQL_QUERY];
47
- }
48
-
49
- evaluateAtSink({ event, applicableSamples }) {
50
- if (_.isEmpty(applicableSamples)) {
51
- return;
52
- }
53
-
54
- const scanner = this.getScanner(event.id);
55
-
56
- for (const sample of applicableSamples) {
57
- const injection = scanner.findInjection(sample.input.value, event.data);
58
-
59
- if (injection) {
60
- this.appendAttackDetails(sample, injection);
61
- sample.captureAppContext(event);
62
- logger.warn(`EFFECTIVE - rule: ${this.id}, mode: ${this.mode} `);
63
- this.blockRequest(sample);
64
- }
65
- }
66
- }
67
-
68
- getScanner(id) {
69
- if (!ScannerKit.has(id)) {
70
- throw new Error(`Unknown NoSQL scanner: ${id}`);
71
- }
72
-
73
- if (!this._scanners.has(id)) {
74
- this._scanners.set(id, ScannerKit.get(id)());
75
- }
76
-
77
- return this._scanners.get(id);
78
- }
79
-
80
- /**
81
- * Builds details for Sql Injection Attack.
82
- * @param {UserInput} inputDtm The user input that resulted in attack
83
- * @param {String} query The query that was analyzed
84
- * @param {Object} results The repsults of the sql-scanner
85
- * @returns {Object} The details
86
- */
87
- buildDetails(sample, findings) {
88
- if (!findings) {
89
- return null;
90
- }
91
-
92
- const { boundary, location, query } = findings;
93
-
94
- const inputBoundaryIndex = boundary.previous
95
- ? boundary.previous.start
96
- : boundary.start;
97
-
98
- return {
99
- start: location[0],
100
- end: location[1] + 1,
101
- input: sample.input.toSerializable(),
102
- boundaryOverrunIndex: boundary.stop + 1,
103
- inputBoundaryIndex,
104
- query
105
- };
106
- }
107
- }
108
-
109
- module.exports = NoSqlInjectionRule;
@@ -1,22 +0,0 @@
1
- (The MIT License)
2
-
3
- Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- 'Software'), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,98 +0,0 @@
1
- node-bindings
2
- =============
3
- ### Helper module for loading your native module's `.node` file
4
-
5
- This is a helper module for authors of Node.js native addon modules.
6
- It is basically the "swiss army knife" of `require()`ing your native module's
7
- `.node` file.
8
-
9
- Throughout the course of Node's native addon history, addons have ended up being
10
- compiled in a variety of different places, depending on which build tool and which
11
- version of node was used. To make matters worse, now the `gyp` build tool can
12
- produce either a __Release__ or __Debug__ build, each being built into different
13
- locations.
14
-
15
- This module checks _all_ the possible locations that a native addon would be built
16
- at, and returns the first one that loads successfully.
17
-
18
-
19
- Installation
20
- ------------
21
-
22
- Install with `npm`:
23
-
24
- ``` bash
25
- $ npm install --save bindings
26
- ```
27
-
28
- Or add it to the `"dependencies"` section of your `package.json` file.
29
-
30
-
31
- Example
32
- -------
33
-
34
- `require()`ing the proper bindings file for the current node version, platform
35
- and architecture is as simple as:
36
-
37
- ``` js
38
- var bindings = require('bindings')('binding.node')
39
-
40
- // Use your bindings defined in your C files
41
- bindings.your_c_function()
42
- ```
43
-
44
-
45
- Nice Error Output
46
- -----------------
47
-
48
- When the `.node` file could not be loaded, `node-bindings` throws an Error with
49
- a nice error message telling you exactly what was tried. You can also check the
50
- `err.tries` Array property.
51
-
52
- ```
53
- Error: Could not load the bindings file. Tried:
54
- → /Users/nrajlich/ref/build/binding.node
55
- → /Users/nrajlich/ref/build/Debug/binding.node
56
- → /Users/nrajlich/ref/build/Release/binding.node
57
- → /Users/nrajlich/ref/out/Debug/binding.node
58
- → /Users/nrajlich/ref/Debug/binding.node
59
- → /Users/nrajlich/ref/out/Release/binding.node
60
- → /Users/nrajlich/ref/Release/binding.node
61
- → /Users/nrajlich/ref/build/default/binding.node
62
- → /Users/nrajlich/ref/compiled/0.8.2/darwin/x64/binding.node
63
- at bindings (/Users/nrajlich/ref/node_modules/bindings/bindings.js:84:13)
64
- at Object.<anonymous> (/Users/nrajlich/ref/lib/ref.js:5:47)
65
- at Module._compile (module.js:449:26)
66
- at Object.Module._extensions..js (module.js:467:10)
67
- at Module.load (module.js:356:32)
68
- at Function.Module._load (module.js:312:12)
69
- ...
70
- ```
71
-
72
- The searching for the `.node` file will originate from the first directory in which has a `package.json` file is found.
73
-
74
- License
75
- -------
76
-
77
- (The MIT License)
78
-
79
- Copyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;
80
-
81
- Permission is hereby granted, free of charge, to any person obtaining
82
- a copy of this software and associated documentation files (the
83
- 'Software'), to deal in the Software without restriction, including
84
- without limitation the rights to use, copy, modify, merge, publish,
85
- distribute, sublicense, and/or sell copies of the Software, and to
86
- permit persons to whom the Software is furnished to do so, subject to
87
- the following conditions:
88
-
89
- The above copyright notice and this permission notice shall be
90
- included in all copies or substantial portions of the Software.
91
-
92
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
93
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
94
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
95
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
96
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
97
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
98
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,221 +0,0 @@
1
- /**
2
- * Module dependencies.
3
- */
4
-
5
- var fs = require('fs'),
6
- path = require('path'),
7
- fileURLToPath = require('file-uri-to-path'),
8
- join = path.join,
9
- dirname = path.dirname,
10
- exists =
11
- (fs.accessSync &&
12
- function(path) {
13
- try {
14
- fs.accessSync(path);
15
- } catch (e) {
16
- return false;
17
- }
18
- return true;
19
- }) ||
20
- fs.existsSync ||
21
- path.existsSync,
22
- defaults = {
23
- arrow: process.env.NODE_BINDINGS_ARROW || ' → ',
24
- compiled: process.env.NODE_BINDINGS_COMPILED_DIR || 'compiled',
25
- platform: process.platform,
26
- arch: process.arch,
27
- nodePreGyp:
28
- 'node-v' +
29
- process.versions.modules +
30
- '-' +
31
- process.platform +
32
- '-' +
33
- process.arch,
34
- version: process.versions.node,
35
- bindings: 'bindings.node',
36
- try: [
37
- // node-gyp's linked version in the "build" dir
38
- ['module_root', 'build', 'bindings'],
39
- // node-waf and gyp_addon (a.k.a node-gyp)
40
- ['module_root', 'build', 'Debug', 'bindings'],
41
- ['module_root', 'build', 'Release', 'bindings'],
42
- // Debug files, for development (legacy behavior, remove for node v0.9)
43
- ['module_root', 'out', 'Debug', 'bindings'],
44
- ['module_root', 'Debug', 'bindings'],
45
- // Release files, but manually compiled (legacy behavior, remove for node v0.9)
46
- ['module_root', 'out', 'Release', 'bindings'],
47
- ['module_root', 'Release', 'bindings'],
48
- // Legacy from node-waf, node <= 0.4.x
49
- ['module_root', 'build', 'default', 'bindings'],
50
- // Production "Release" buildtype binary (meh...)
51
- ['module_root', 'compiled', 'version', 'platform', 'arch', 'bindings'],
52
- // node-qbs builds
53
- ['module_root', 'addon-build', 'release', 'install-root', 'bindings'],
54
- ['module_root', 'addon-build', 'debug', 'install-root', 'bindings'],
55
- ['module_root', 'addon-build', 'default', 'install-root', 'bindings'],
56
- // node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
57
- ['module_root', 'lib', 'binding', 'nodePreGyp', 'bindings']
58
- ]
59
- };
60
-
61
- /**
62
- * The main `bindings()` function loads the compiled bindings for a given module.
63
- * It uses V8's Error API to determine the parent filename that this function is
64
- * being invoked from, which is then used to find the root directory.
65
- */
66
-
67
- function bindings(opts) {
68
- // Argument surgery
69
- if (typeof opts == 'string') {
70
- opts = { bindings: opts };
71
- } else if (!opts) {
72
- opts = {};
73
- }
74
-
75
- // maps `defaults` onto `opts` object
76
- Object.keys(defaults).map(function(i) {
77
- if (!(i in opts)) opts[i] = defaults[i];
78
- });
79
-
80
- // Get the module root
81
- if (!opts.module_root) {
82
- opts.module_root = exports.getRoot(exports.getFileName());
83
- }
84
-
85
- // Ensure the given bindings name ends with .node
86
- if (path.extname(opts.bindings) != '.node') {
87
- opts.bindings += '.node';
88
- }
89
-
90
- // https://github.com/webpack/webpack/issues/4175#issuecomment-342931035
91
- var requireFunc =
92
- typeof __webpack_require__ === 'function'
93
- ? __non_webpack_require__
94
- : require;
95
-
96
- var tries = [],
97
- i = 0,
98
- l = opts.try.length,
99
- n,
100
- b,
101
- err;
102
-
103
- for (; i < l; i++) {
104
- n = join.apply(
105
- null,
106
- opts.try[i].map(function(p) {
107
- return opts[p] || p;
108
- })
109
- );
110
- tries.push(n);
111
- try {
112
- b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
113
- if (!opts.path) {
114
- b.path = n;
115
- }
116
- return b;
117
- } catch (e) {
118
- if (e.code !== 'MODULE_NOT_FOUND' &&
119
- e.code !== 'QUALIFIED_PATH_RESOLUTION_FAILED' &&
120
- !/not find/i.test(e.message)) {
121
- throw e;
122
- }
123
- }
124
- }
125
-
126
- err = new Error(
127
- 'Could not locate the bindings file. Tried:\n' +
128
- tries
129
- .map(function(a) {
130
- return opts.arrow + a;
131
- })
132
- .join('\n')
133
- );
134
- err.tries = tries;
135
- throw err;
136
- }
137
- module.exports = exports = bindings;
138
-
139
- /**
140
- * Gets the filename of the JavaScript file that invokes this function.
141
- * Used to help find the root directory of a module.
142
- * Optionally accepts an filename argument to skip when searching for the invoking filename
143
- */
144
-
145
- exports.getFileName = function getFileName(calling_file) {
146
- var origPST = Error.prepareStackTrace,
147
- origSTL = Error.stackTraceLimit,
148
- dummy = {},
149
- fileName;
150
-
151
- Error.stackTraceLimit = 10;
152
-
153
- Error.prepareStackTrace = function(e, st) {
154
- for (var i = 0, l = st.length; i < l; i++) {
155
- fileName = st[i].getFileName();
156
- if (fileName !== __filename) {
157
- if (calling_file) {
158
- if (fileName !== calling_file) {
159
- return;
160
- }
161
- } else {
162
- return;
163
- }
164
- }
165
- }
166
- };
167
-
168
- // run the 'prepareStackTrace' function above
169
- Error.captureStackTrace(dummy);
170
- dummy.stack;
171
-
172
- // cleanup
173
- Error.prepareStackTrace = origPST;
174
- Error.stackTraceLimit = origSTL;
175
-
176
- // handle filename that starts with "file://"
177
- var fileSchema = 'file://';
178
- if (fileName.indexOf(fileSchema) === 0) {
179
- fileName = fileURLToPath(fileName);
180
- }
181
-
182
- return fileName;
183
- };
184
-
185
- /**
186
- * Gets the root directory of a module, given an arbitrary filename
187
- * somewhere in the module tree. The "root directory" is the directory
188
- * containing the `package.json` file.
189
- *
190
- * In: /home/nate/node-native-module/lib/index.js
191
- * Out: /home/nate/node-native-module
192
- */
193
-
194
- exports.getRoot = function getRoot(file) {
195
- var dir = dirname(file),
196
- prev;
197
- while (true) {
198
- if (dir === '.') {
199
- // Avoids an infinite loop in rare cases, like the REPL
200
- dir = process.cwd();
201
- }
202
- if (
203
- exists(join(dir, 'package.json')) ||
204
- exists(join(dir, 'node_modules'))
205
- ) {
206
- // Found the 'package.json' file or 'node_modules' dir; we're done
207
- return dir;
208
- }
209
- if (prev === dir) {
210
- // Got to the top
211
- throw new Error(
212
- 'Could not find module root given file: "' +
213
- file +
214
- '". Do you have a `package.json` file? '
215
- );
216
- }
217
- // Try the parent dir next
218
- prev = dir;
219
- dir = join(dir, '..');
220
- }
221
- };
@@ -1,32 +0,0 @@
1
- {
2
- "name": "bindings",
3
- "description": "Helper module for loading your native module's .node file",
4
- "keywords": [
5
- "native",
6
- "addon",
7
- "bindings",
8
- "gyp",
9
- "waf",
10
- "c",
11
- "c++"
12
- ],
13
- "version": "1.5.0",
14
- "author": "Nathan Rajlich <nathan@tootallnate.net> (http://tootallnate.net)",
15
- "repository": {
16
- "type": "git",
17
- "url": "git://github.com/TooTallNate/node-bindings.git"
18
- },
19
- "main": "./bindings.js",
20
- "bugs": {
21
- "url": "https://github.com/TooTallNate/node-bindings/issues"
22
- },
23
- "homepage": "https://github.com/TooTallNate/node-bindings",
24
- "license": "MIT",
25
- "dependencies": {
26
- "file-uri-to-path": "1.0.0"
27
- }
28
-
29
- ,"_resolved": "https://registry.npmjs.org/bindings/-/bindings-1.5.0.tgz"
30
- ,"_integrity": "sha512-p2q/t/mhvuOj/UeLlV6566GD/guowlr0hHxClI0W9m7MWYkL1F0hLo+0Aexs9HSPCtR1SXQ0TD3MMKrXZajbiQ=="
31
- ,"_from": "bindings@1.5.0"
32
- }
@@ -1 +0,0 @@
1
- /node_modules
@@ -1,30 +0,0 @@
1
- sudo: false
2
-
3
- language: node_js
4
-
5
- node_js:
6
- - "0.8"
7
- - "0.10"
8
- - "0.12"
9
- - "1"
10
- - "2"
11
- - "3"
12
- - "4"
13
- - "5"
14
- - "6"
15
- - "7"
16
- - "8"
17
-
18
- install:
19
- - PATH="`npm bin`:`npm bin -g`:$PATH"
20
- # Node 0.8 comes with a too obsolete npm
21
- - if [[ "`node --version`" =~ ^v0\.8\. ]]; then npm install -g npm@1.4.28 ; fi
22
- # Install dependencies and build
23
- - npm install
24
-
25
- script:
26
- # Output useful info for debugging
27
- - node --version
28
- - npm --version
29
- # Run tests
30
- - npm test
@@ -1,21 +0,0 @@
1
-
2
- 1.0.0 / 2017-07-06
3
- ==================
4
-
5
- * update "mocha" to v3
6
- * fixed unicode URI decoding (#6)
7
- * add typings for Typescript
8
- * README: use SVG Travis-CI badge
9
- * add LICENSE file (MIT)
10
- * add .travis.yml file (testing Node.js 0.8 through 8 currently)
11
- * add README.md file
12
-
13
- 0.0.2 / 2014-01-27
14
- ==================
15
-
16
- * index: invert the path separators on Windows
17
-
18
- 0.0.1 / 2014-01-27
19
- ==================
20
-
21
- * initial commit
@@ -1,20 +0,0 @@
1
- Copyright (c) 2014 Nathan Rajlich <nathan@tootallnate.net>
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- 'Software'), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,74 +0,0 @@
1
- file-uri-to-path
2
- ================
3
- ### Convert a `file:` URI to a file path
4
- [![Build Status](https://travis-ci.org/TooTallNate/file-uri-to-path.svg?branch=master)](https://travis-ci.org/TooTallNate/file-uri-to-path)
5
-
6
- Accepts a `file:` URI and returns a regular file path suitable for use with the
7
- `fs` module functions.
8
-
9
-
10
- Installation
11
- ------------
12
-
13
- Install with `npm`:
14
-
15
- ``` bash
16
- $ npm install file-uri-to-path
17
- ```
18
-
19
-
20
- Example
21
- -------
22
-
23
- ``` js
24
- var uri2path = require('file-uri-to-path');
25
-
26
- uri2path('file://localhost/c|/WINDOWS/clock.avi');
27
- // "c:\\WINDOWS\\clock.avi"
28
-
29
- uri2path('file:///c|/WINDOWS/clock.avi');
30
- // "c:\\WINDOWS\\clock.avi"
31
-
32
- uri2path('file://localhost/c:/WINDOWS/clock.avi');
33
- // "c:\\WINDOWS\\clock.avi"
34
-
35
- uri2path('file://hostname/path/to/the%20file.txt');
36
- // "\\\\hostname\\path\\to\\the file.txt"
37
-
38
- uri2path('file:///c:/path/to/the%20file.txt');
39
- // "c:\\path\\to\\the file.txt"
40
- ```
41
-
42
-
43
- API
44
- ---
45
-
46
- ### fileUriToPath(String uri) → String
47
-
48
-
49
-
50
- License
51
- -------
52
-
53
- (The MIT License)
54
-
55
- Copyright (c) 2014 Nathan Rajlich &lt;nathan@tootallnate.net&gt;
56
-
57
- Permission is hereby granted, free of charge, to any person obtaining
58
- a copy of this software and associated documentation files (the
59
- 'Software'), to deal in the Software without restriction, including
60
- without limitation the rights to use, copy, modify, merge, publish,
61
- distribute, sublicense, and/or sell copies of the Software, and to
62
- permit persons to whom the Software is furnished to do so, subject to
63
- the following conditions:
64
-
65
- The above copyright notice and this permission notice shall be
66
- included in all copies or substantial portions of the Software.
67
-
68
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
69
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
70
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
71
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
72
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
73
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
74
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,2 +0,0 @@
1
- declare function fileUriToPath(uri: string): string;
2
- export = fileUriToPath;