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