@contrast/common 1.1.2 → 1.1.3

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.
@@ -24,9 +24,9 @@ export declare enum Rule {
24
24
  REFLECTED_XSS = "reflected-xss",
25
25
  SQL_INJECTION = "sql-injection",
26
26
  SSJS_INJECTION = "ssjs-injection",
27
- VIRTUAL_PATCH = "virtual-patch",
28
- UNTRUSTED_DESERIALIZATION = "untrusted-deserialization",
29
27
  UNSAFE_FILE_UPLOAD = "unsafe-file-upload",
28
+ UNTRUSTED_DESERIALIZATION = "untrusted-deserialization",
29
+ VIRTUAL_PATCH = "virtual-patch",
30
30
  XXE = "xxe"
31
31
  }
32
32
  export declare enum InputType {
package/lib/constants.js CHANGED
@@ -44,9 +44,9 @@ var Rule;
44
44
  Rule["REFLECTED_XSS"] = "reflected-xss";
45
45
  Rule["SQL_INJECTION"] = "sql-injection";
46
46
  Rule["SSJS_INJECTION"] = "ssjs-injection";
47
- Rule["VIRTUAL_PATCH"] = "virtual-patch";
48
- Rule["UNTRUSTED_DESERIALIZATION"] = "untrusted-deserialization";
49
47
  Rule["UNSAFE_FILE_UPLOAD"] = "unsafe-file-upload";
48
+ Rule["UNTRUSTED_DESERIALIZATION"] = "untrusted-deserialization";
49
+ Rule["VIRTUAL_PATCH"] = "virtual-patch";
50
50
  Rule["XXE"] = "xxe";
51
51
  })(Rule = exports.Rule || (exports.Rule = {}));
52
52
  var InputType;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAEH,IAAY,KAIX;AAJD,WAAY,KAAK;IACf,0BAAiB,CAAA;IACjB,4BAAmB,CAAA;IACnB,0DAAiD,CAAA;AACnD,CAAC,EAJW,KAAK,GAAL,aAAK,KAAL,aAAK,QAIhB;AACD,IAAY,eAKX;AALD,WAAY,eAAe;IACzB,8BAAW,CAAA;IACX,sCAA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oCAAuB,CAAA;IACvB,8BAAiB,CAAA;IACjB,gCAAmB,CAAA;IACnB,4CAA+B,CAAA;IAC/B,gCAAmB,CAAA;AACrB,CAAC,EAvBW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAuBpB;AAEY,QAAA,cAAc,GAAG,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC"}
package/lib/types.d.ts CHANGED
@@ -1,18 +1,39 @@
1
1
  /// <reference types="node" />
2
2
  import { Event, Rule, ProtectRuleMode } from './constants';
3
3
  import { EventEmitter } from 'events';
4
+ export interface AppInfo {
5
+ os: {
6
+ type: string;
7
+ platform: string;
8
+ architecture: string;
9
+ release: string;
10
+ };
11
+ hostname: string;
12
+ version: string;
13
+ name: string;
14
+ pkg: object;
15
+ agentVersion: string;
16
+ app_dir: string;
17
+ serverVersion: string;
18
+ node_version: string;
19
+ appPath: string;
20
+ indexFile: string;
21
+ serverName: string;
22
+ serverEnvironment: string;
23
+ }
4
24
  export declare type SemanticAnalysisRules = Rule.CMD_INJECTION_SEMANTIC_CHAINED_COMMANDS | Rule.CMD_INJECTION_COMMAND_BACKDOORS | Rule.CMD_INJECTION_SEMANTIC_DANGEROUS_PATHS;
5
25
  export interface Result {
6
26
  blocked: boolean;
7
- ruleId: Rule;
27
+ details?: any[];
28
+ idsList?: string[];
8
29
  inputType: string;
9
- path?: string[];
10
30
  key?: string;
11
- value: string;
12
- score: number;
13
- details?: any[];
31
+ mappedId: string;
14
32
  mongoExpansionResult?: boolean;
15
- idsList?: string[];
33
+ path?: string[];
34
+ ruleId: Rule;
35
+ score: number;
36
+ value: string;
16
37
  }
17
38
  export interface SemanticAnalysisResult extends Result {
18
39
  findings?: {
@@ -49,18 +70,15 @@ export interface Findings {
49
70
  trackRequest: boolean;
50
71
  securityException?: [mode: ProtectRuleMode, ruleId: string];
51
72
  bodyType?: 'json' | 'urlencoded';
52
- resultsMap: Record<Rule, Result[]>;
53
- semanticResultsMap: Record<Rule, SemanticAnalysisResult[]>;
54
- serverFeaturesResultsMap: Record<Rule, ServerFeaturePreliminaryResult[]>;
55
- hardeningResultsMap: Record<Rule, HardeningResult[]>;
56
- }
57
- export interface RequestStore {
58
- protect?: ProtectMessage;
73
+ resultsMap: Partial<Record<Rule, Result[]>>;
74
+ semanticResultsMap: Partial<Record<Rule, SemanticAnalysisResult[]>>;
75
+ serverFeaturesResultsMap: Partial<Record<Rule, ServerFeaturePreliminaryResult[]>>;
76
+ hardeningResultsMap: Partial<Record<Rule, HardeningResult[]>>;
59
77
  }
60
78
  export interface ProtectMessage {
61
79
  reqData: ReqData;
62
80
  block: (mode: string, ruleId: string) => void;
63
- policy: any;
81
+ policy: Partial<Record<Rule, ProtectRuleMode>>;
64
82
  exclusions: any[];
65
83
  virtualPatches: any[];
66
84
  findings: Findings;
@@ -69,16 +87,26 @@ export interface ProtectMessage {
69
87
  parsedParams: any;
70
88
  parsedQuery: any;
71
89
  }
90
+ /**
91
+ * this is known as RequestStore even though, in the future, instrumentation
92
+ * will exist for message buses or sources other than HTTP requests. "request"
93
+ * seems generic enough that it's not hard to understand that request can mean
94
+ * an amqp message or other request to perform work that might get user input.
95
+ * additionally, at this time, the only things instrumented are HTTP requests,
96
+ * and other things are only possible extensions to the core facility. it seems
97
+ * reasonable that they will fit into the primary concept that the agent deals
98
+ * with, requests, whether from HTTP or elsewhere.
99
+ */
100
+ export interface RequestStore {
101
+ protect?: ProtectMessage;
102
+ }
72
103
  export interface Messages extends EventEmitter {
73
104
  addListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
105
+ addListener(event: Event.SERVER_SETTINGS_UPDATE, listener: (msg: Record<string, any>) => void): this;
74
106
  emit(event: Event.PROTECT, msg: RequestStore): boolean;
75
- emit(event: Event.SERVER_SETTINGS_UPDATE, msg: {
76
- [key: string]: any;
77
- }): boolean;
107
+ emit(event: Event.SERVER_SETTINGS_UPDATE, msg: Record<string, any>): boolean;
78
108
  on(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
79
- on(event: Event.SERVER_SETTINGS_UPDATE, listener: (msg: {
80
- [key: string]: any;
81
- }) => void): this;
109
+ on(event: Event.SERVER_SETTINGS_UPDATE, listener: (msg: Record<string, any>) => void): this;
82
110
  prependListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
83
111
  prependOnceListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
84
112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrast/common",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
4
4
  "description": "Shared constants and utilities for all Contrast Agent modules",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Contrast Security <nodejs@contrastsecurity.com> (https://www.contrastsecurity.com)",
package/src/constants.ts CHANGED
@@ -40,9 +40,9 @@ export enum Rule {
40
40
  REFLECTED_XSS = 'reflected-xss',
41
41
  SQL_INJECTION = 'sql-injection',
42
42
  SSJS_INJECTION = 'ssjs-injection',
43
- VIRTUAL_PATCH = 'virtual-patch',
44
- UNTRUSTED_DESERIALIZATION = 'untrusted-deserialization',
45
43
  UNSAFE_FILE_UPLOAD = 'unsafe-file-upload',
44
+ UNTRUSTED_DESERIALIZATION = 'untrusted-deserialization',
45
+ VIRTUAL_PATCH = 'virtual-patch',
46
46
  XXE = 'xxe',
47
47
  }
48
48
 
@@ -72,4 +72,3 @@ export enum InputType {
72
72
  }
73
73
 
74
74
  export const BLOCKING_MODES = ['block', 'block_at_perimeter'];
75
-
package/src/types.ts CHANGED
@@ -16,44 +16,69 @@
16
16
  import { Event, Rule, ProtectRuleMode } from './constants';
17
17
  import { EventEmitter } from 'events';
18
18
 
19
- export type SemanticAnalysisRules = Rule.CMD_INJECTION_SEMANTIC_CHAINED_COMMANDS | Rule.CMD_INJECTION_COMMAND_BACKDOORS | Rule.CMD_INJECTION_SEMANTIC_DANGEROUS_PATHS;
19
+ export interface AppInfo {
20
+ os: {
21
+ type: string;
22
+ platform: string;
23
+ architecture: string;
24
+ release: string;
25
+ };
26
+ hostname: string;
27
+ version: string;
28
+ name: string;
29
+ pkg: object; // package.json
30
+ agentVersion: string;
31
+ app_dir: string;
32
+ serverVersion: string;
33
+ node_version: string;
34
+ appPath: string;
35
+ indexFile: string;
36
+ serverName: string;
37
+ serverEnvironment: string;
38
+ }
39
+
40
+ export type SemanticAnalysisRules =
41
+ | Rule.CMD_INJECTION_SEMANTIC_CHAINED_COMMANDS
42
+ | Rule.CMD_INJECTION_COMMAND_BACKDOORS
43
+ | Rule.CMD_INJECTION_SEMANTIC_DANGEROUS_PATHS;
20
44
 
21
45
  export interface Result {
22
46
  blocked: boolean;
23
- ruleId: Rule,
24
- inputType: string, // TODO
25
- path?: string[],
26
- key?: string,
27
- value: string,
28
- score: number,
29
- details?: any[], // TODO
30
- mongoExpansionResult?: boolean,
31
- idsList?: string[],
47
+ details?: any[]; // TODO
48
+ idsList?: string[];
49
+ inputType: string; // TODO
50
+ key?: string;
51
+ mappedId: string;
52
+ mongoExpansionResult?: boolean;
53
+ path?: string[];
54
+ ruleId: Rule;
55
+ score: number;
56
+ value: string;
32
57
  }
33
58
 
34
59
  export interface SemanticAnalysisResult extends Result {
35
60
  findings?: {
36
- command?: string
37
- }
38
- sinkContext?: any
61
+ command?: string;
62
+ };
63
+ sinkContext?: any;
39
64
  }
40
65
 
41
66
  export interface HardeningResult extends Result {
42
67
  findings?: {
43
- command?: boolean,
44
- deserializer?: string
45
- }
46
- sinkContext?: any
68
+ command?: boolean;
69
+ deserializer?: string;
70
+ };
71
+ sinkContext?: any;
47
72
  }
48
73
 
49
74
  export interface ServerFeaturePreliminaryResult {
50
- name?: string,
51
- uuid: string,
52
- ip?: string
75
+ name?: string;
76
+ uuid: string;
77
+ ip?: string;
53
78
  }
54
79
 
55
80
  export interface ServerFeatureResult extends Result {
56
- details?: ServerFeaturePreliminaryResult[]
81
+ details?: ServerFeaturePreliminaryResult[];
57
82
  }
58
83
 
59
84
  export interface ReqData {
@@ -64,38 +89,23 @@ export interface ReqData {
64
89
  contentType?: string;
65
90
  standardUrlParsing: boolean;
66
91
  ip: string;
67
- httpVersion: string,
92
+ httpVersion: string;
68
93
  }
69
94
 
70
95
  export interface Findings {
71
96
  trackRequest: boolean;
72
97
  securityException?: [mode: ProtectRuleMode, ruleId: string];
73
98
  bodyType?: 'json' | 'urlencoded';
74
- resultsMap: Record<Rule, Result[]>;
75
- semanticResultsMap: Record<Rule, SemanticAnalysisResult[]>;
76
- serverFeaturesResultsMap: Record<Rule, ServerFeaturePreliminaryResult[]>;
77
- hardeningResultsMap: Record<Rule, HardeningResult[]>;
78
- }
79
-
80
- //
81
- // this is known as RequestStore even though, in the future, instrumentation
82
- // will exist for message buses or sources other than HTTP requests. "request"
83
- // seems generic enough that it's not hard to understand that request can mean
84
- // an amqp message or other request to perform work that might get user input.
85
- // additionally, at this time, the only things instrumented are HTTP requests,
86
- // and other things are only possible extensions to the core facility. it seems
87
- // reasonable that they will fit into the primary concept that the agent deals
88
- // with, requests, whether from HTTP or elsewhere.
89
- //
90
- export interface RequestStore {
91
- // TODO: from protect/lib/make-source-context
92
- protect?: ProtectMessage;
99
+ resultsMap: Partial<Record<Rule, Result[]>>;
100
+ semanticResultsMap: Partial<Record<Rule, SemanticAnalysisResult[]>>;
101
+ serverFeaturesResultsMap: Partial<Record<Rule, ServerFeaturePreliminaryResult[]>>;
102
+ hardeningResultsMap: Partial<Record<Rule, HardeningResult[]>>;
93
103
  }
94
104
 
95
105
  export interface ProtectMessage {
96
106
  reqData: ReqData;
97
107
  block: (mode: string, ruleId: string) => void;
98
- policy: any;
108
+ policy: Partial<Record<Rule, ProtectRuleMode>>;
99
109
  exclusions: any[]; // TODO
100
110
  virtualPatches: any[]; // TODO
101
111
  findings: Findings;
@@ -105,12 +115,44 @@ export interface ProtectMessage {
105
115
  parsedQuery: any;
106
116
  }
107
117
 
118
+ /**
119
+ * this is known as RequestStore even though, in the future, instrumentation
120
+ * will exist for message buses or sources other than HTTP requests. "request"
121
+ * seems generic enough that it's not hard to understand that request can mean
122
+ * an amqp message or other request to perform work that might get user input.
123
+ * additionally, at this time, the only things instrumented are HTTP requests,
124
+ * and other things are only possible extensions to the core facility. it seems
125
+ * reasonable that they will fit into the primary concept that the agent deals
126
+ * with, requests, whether from HTTP or elsewhere.
127
+ */
128
+ export interface RequestStore {
129
+ protect?: ProtectMessage; // from protect/lib/make-source-context
130
+ }
131
+
108
132
  export interface Messages extends EventEmitter {
109
- addListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
133
+ addListener(event: Event.PROTECT,
134
+ listener: (msg: RequestStore) => void,
135
+ ): this;
136
+ addListener(
137
+ event: Event.SERVER_SETTINGS_UPDATE,
138
+ listener: (msg: Record<string, any>) => void,
139
+ ): this;
140
+
110
141
  emit(event: Event.PROTECT, msg: RequestStore): boolean;
111
- emit(event: Event.SERVER_SETTINGS_UPDATE, msg: { [key: string]: any }): boolean;
142
+ emit(event: Event.SERVER_SETTINGS_UPDATE, msg: Record<string, any>): boolean;
143
+
112
144
  on(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
113
- on(event: Event.SERVER_SETTINGS_UPDATE, listener: (msg: { [key: string]: any }) => void): this;
114
- prependListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
115
- prependOnceListener(event: Event.PROTECT, listener: (msg: RequestStore) => void): this;
145
+ on(
146
+ event: Event.SERVER_SETTINGS_UPDATE,
147
+ listener: (msg: Record<string, any>) => void,
148
+ ): this;
149
+
150
+ prependListener(
151
+ event: Event.PROTECT,
152
+ listener: (msg: RequestStore) => void,
153
+ ): this;
154
+ prependOnceListener(
155
+ event: Event.PROTECT,
156
+ listener: (msg: RequestStore) => void,
157
+ ): this;
116
158
  }