@contrast/common 1.7.0 → 1.9.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.
@@ -0,0 +1,46 @@
1
+ /*
2
+ * Copyright: 2022 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
+ const collectionSignatures: [string, any][] = [
17
+ 'find',
18
+ 'findOne',
19
+ 'findAndModify',
20
+ 'findOneAndDelete',
21
+ 'findOneAndReplace',
22
+ 'findOneAndUpdate',
23
+ 'remove',
24
+ 'removeOne',
25
+ 'replaceOne',
26
+ 'removeMany',
27
+ 'save',
28
+ 'update',
29
+ 'updateOne',
30
+ 'updateMany',
31
+ 'deleteOne',
32
+ 'deleteMany',
33
+ ].map((method) => [
34
+ `mongodb.Collection.prototype.${method}`,
35
+ {
36
+ moduleName: 'mongodb',
37
+ methodName: `Collection.prototype.${method}`,
38
+ isModule: true,
39
+ }
40
+ ]);
41
+
42
+ const mongodb: Map<string, any> = new Map([
43
+ ...collectionSignatures,
44
+ ]);
45
+
46
+ export default mongodb;
@@ -0,0 +1,52 @@
1
+ /*
2
+ * Copyright: 2022 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
+ import { Signature } from '../types';
17
+
18
+
19
+ const mssql = new Map<string, Signature>([
20
+ [
21
+ 'mssql/lib/base/prepared-statement.prototype.prepare',
22
+ {
23
+ moduleName: 'mssql',
24
+ version: '>=6.4.0',
25
+ fileName: 'lib/base/prepared-statement.js',
26
+ methodName: 'PreparedStatement.prototype.prepare',
27
+ isModule: true,
28
+ },
29
+ ],
30
+ [
31
+ 'mssql/lib/base/request.prototype.batch',
32
+ {
33
+ moduleName: 'mssql',
34
+ version: '>=6.4.0',
35
+ fileName: 'lib/base/request.js',
36
+ methodName: 'Request.prototype.batch',
37
+ isModule: true,
38
+ },
39
+ ],
40
+ [
41
+ 'mssql/lib/base/request.prototype.query',
42
+ {
43
+ moduleName: 'mssql',
44
+ version: '>=6.4.0',
45
+ fileName: 'lib/base/request.js',
46
+ methodName: 'Request.prototype.query',
47
+ isModule: true,
48
+ },
49
+ ],
50
+ ] as [string, Signature][]);
51
+
52
+ export default mssql;
package/src/types.ts CHANGED
@@ -13,8 +13,24 @@
13
13
  * way not consistent with the End User License Agreement.
14
14
  */
15
15
 
16
- import { Event, Rule, ProtectRuleMode } from './constants';
17
16
  import { EventEmitter } from 'events';
17
+ import { Event, ProtectRuleMode, Rule } from './constants';
18
+
19
+ export interface Installable {
20
+ install(): void | Promise<void>;
21
+ uninstall?(): void | Promise<void>;
22
+ }
23
+
24
+ export interface Signature {
25
+ moduleName: string;
26
+ methodName: string;
27
+ fileName?: string;
28
+ version?: string;
29
+ isModule: boolean;
30
+ isConstructor?: boolean;
31
+ source?: 'O' | 'P' | 'R';
32
+ target?: 'O' | 'P' | 'R';
33
+ }
18
34
 
19
35
  export interface AppInfo {
20
36
  os: {
@@ -147,6 +163,13 @@ export interface ProtectMessage {
147
163
  parsedQuery: any;
148
164
  }
149
165
 
166
+ export interface SourceInfo {
167
+ serverType: string;
168
+ port: number;
169
+ protocol: string;
170
+ time: number;
171
+ }
172
+
150
173
  /**
151
174
  * this is known as RequestStore even though, in the future, instrumentation
152
175
  * will exist for message buses or sources other than HTTP requests. "request"
@@ -158,22 +181,150 @@ export interface ProtectMessage {
158
181
  * with, requests, whether from HTTP or elsewhere.
159
182
  */
160
183
  export interface RequestStore {
184
+ // TODO: this shouldn't be optional but blows up
185
+ sourceInfo?: SourceInfo;
161
186
  protect?: ProtectMessage; // from protect/lib/make-source-context
162
- assess?: any // TODO
187
+ assess?: any;
188
+ route?: any;
163
189
  }
164
190
 
165
- export interface Messages extends EventEmitter {
166
- addListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
167
- addListener(event: Event.SERVER_SETTINGS_UPDATE, listener: (msg: Record<string, any>) => void): this;
191
+ /**
192
+ * Architecture Component registration event payload.
193
+ */
194
+ export interface ArchitectureComponent {
195
+ /** The type of this component: database, ldap, or web server connection. */
196
+ type: 'db' | 'ldap' | 'ws',
197
+ /**
198
+ * The URL to which this component responds.
199
+ * @example "mysql://host:3306"
200
+ */
201
+ url: string;
202
+ /**
203
+ * Some indication of the subtype of the connection.
204
+ * @example "MySQL"
205
+ */
206
+ vendor?: string;
207
+ }
208
+
209
+ /**
210
+ * Library discovery event payload.
211
+ */
212
+ export interface Library {
213
+ /**
214
+ * The time, in ms, that the library was last modified on the filesystem.
215
+ * Must be greater than 0 and less than 32503679999000 (Tuesday, 31 December 2999 23:59:59).
216
+ * @todo
217
+ */
218
+ externalDate: number;
219
+ /**
220
+ * The time, in ms, that the library was last modified on the filesystem.
221
+ * Must be greater than 0 and less than 32503679999000 (Tuesday, 31 December 2999 23:59:59).
222
+ * @todo
223
+ */
224
+ internalDate: number;
225
+ /**
226
+ * The version of the library.
227
+ * @example "2.18.1"
228
+ */
229
+ version: string;
230
+ /**
231
+ * Hash of the library. uses the provided SHA sum when present, or a generated
232
+ * identifer otherwise.
233
+ * @example "2254143855c5a8c73825e4522baf2ea021766717"
234
+ * @example "mysql:2.18.1"
235
+ */
236
+ hash: string;
237
+ /**
238
+ * Name of the library with version data
239
+ * @example "mysql-2.18.1"
240
+ */
241
+ file: string;
242
+ /**
243
+ * Homepage or source of the library.
244
+ * @example "https://github.com/mysqljs/mysql#readme"
245
+ * @example "https://registry.npmjs.org/mysql/-/mysql-2.18.1.tgz"
246
+ */
247
+ url?: string;
248
+ /**
249
+ * String describing the library, including name, description, license,
250
+ * dependencies and dependents.
251
+ */
252
+ manifest: string;
253
+ /**
254
+ * Library tags provided by the user to the agent.
255
+ */
256
+ tags: string;
257
+ }
168
258
 
259
+ /**
260
+ * Library usage update event payload.
261
+ */
262
+ export interface LibraryUsage {
263
+ id: string;
264
+ names: string[];
265
+ }
266
+
267
+ /**
268
+ * Route discovery or observation event payload.
269
+ */
270
+ export interface RouteInfo {
271
+ /**
272
+ * Language specific signature of the controller method.
273
+ * @example "Router.get('prefix/route/path', [Function])"
274
+ */
275
+ signature: string;
276
+ /**
277
+ * The HTTP method supported by the discovered route url, if one is reported.
278
+ * @example "get"
279
+ */
280
+ method?: string;
281
+ /**
282
+ * Normalized URL for a route.
283
+ * @example "prefix/route/path"
284
+ */
285
+ url: string;
286
+ }
287
+
288
+ /**
289
+ * Agent event emitter for messaging to/from external systems. Use cases are
290
+ * reporting agent findings and broadcasting settings updates.
291
+ *
292
+ * The final, generic, overloads for emit/on matches any calls that don't match
293
+ * one of the more specific definitions.
294
+ */
295
+ export interface Messages extends EventEmitter {
296
+ emit(event: Event.ARCHITECTURE_COMPONENT, msg: ArchitectureComponent): boolean;
297
+ emit(event: Event.ASSESS_DATAFLOW_FINDING, msg: any): boolean;
298
+ emit(event: Event.LIBRARY, msg: Library): boolean;
299
+ emit(event: Event.LIBRARY_USAGE, msg: LibraryUsage): boolean;
169
300
  emit(event: Event.PROTECT, msg: RequestStore): boolean;
301
+ emit(event: Event.ROUTE_COVERAGE_DISCOVERY, route: RouteInfo): boolean;
302
+ emit(event: Event.ROUTE_COVERAGE_DISCOVERY_FINISHED, routes: RouteInfo[]): boolean;
303
+ emit(event: Event.ROUTE_COVERAGE_OBSERVATION, route: RouteInfo): boolean;
170
304
  emit(event: Event.SERVER_SETTINGS_UPDATE, msg: Record<string, any>): boolean;
305
+ emit(event: Event, ...args: any[]): boolean;
171
306
 
172
- on(event: Event.ARCHITECTURE_COMPONENT, listener: (msg: Record<string, any>) => void): this;
307
+ on(event: Event.ARCHITECTURE_COMPONENT, listener: (msg: ArchitectureComponent) => void): this;
308
+ on(event: Event.ASSESS_DATAFLOW_FINDING, listenter: (msg: any) => void): this;
309
+ on(event: Event.LIBRARY, listener: (msg: Library) => void): this;
310
+ on(event: Event.LIBRARY_USAGE, listener: (msg: LibraryUsage) => void): this;
173
311
  on(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
174
- on(event: Event.LIBRARY_USAGE, listener: (msg: Record<string, any>) => void): this
312
+ on(event: Event.ROUTE_COVERAGE_DISCOVERY, listener: (route: RouteInfo) => void): this;
313
+ on(event: Event.ROUTE_COVERAGE_DISCOVERY_FINISHED, listener: (routes: RouteInfo[]) => void): this;
314
+ on(event: Event.ROUTE_COVERAGE_OBSERVATION, listener: (route: RouteInfo) => void): this;
175
315
  on(event: Event.SERVER_SETTINGS_UPDATE, listener: (msg: Record<string, any>) => void): this;
316
+ on(event: Event, listener: (...args: any[]) => void): this;
317
+ }
318
+
319
+ /**
320
+ * Agent event emitter for broadcasting internal lifecycle events.
321
+ *
322
+ * The final, generic, overloads for emit/on matches any calls that don't match
323
+ * one of the more specific definitions.
324
+ */
325
+ export interface Lifecycle extends EventEmitter {
326
+ emit(event: Event, ...args: any[]): boolean;
176
327
 
177
- prependListener(event: Event.PROTECT, listener: (msg: RequestStore) => void,): this;
178
- prependOnceListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
328
+ on(event: Event.RESPONSE_FINISH, listener: (msg: RequestStore) => void): this;
329
+ on(event: Event, listener: (...args: any[]) => void): this;
179
330
  }