/
types.go
386 lines (339 loc) · 10.4 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
package compliance
import (
"encoding/json"
"fmt"
"time"
"github.com/pkg/errors"
)
type Asset struct {
ID string `json:"id"`
IDfy string `json:"idfy"`
Origin string `json:"origin"`
CBundleID *string `json:"cBundleID"`
CreatedAt time.Time `json:"createdAt"`
ContactID *string `json:"contactID"`
}
type AssetPatch struct {
IDfy string `json:"idfy"`
CBundleID *string `json:"cBundleID"`
Origin string `json:"origin"`
ContactID *string `json:"contactID"`
}
type AssetPost struct {
AssetPatch
ExternalID *string `json:"externalID"`
}
type AssetFilter struct {
OnlySecurity bool `json:"onlySecurity"` // only security assets
OnlyCompliance bool `json:"onlyCompliance"` // only compliance assets
Name []string `json:"name"` // idfy
Origin []string `json:"origin"`
CreatedAt []string `json:"createdAt"`
Contact []string `json:"contact"` // contact mail
}
type DisabledAsset struct {
ID string `json:"id"`
IDfy string `json:"idfy"`
Origin string `json:"origin"`
CreatedAt time.Time `json:"createdAt"`
DisabledAt time.Time `json:"disabledAt"`
DisabledReason *string `json:"disabledReason"`
}
type DisabledAssetFilter struct {
Name []string `json:"name,omitempty"` // idfy
Origin []string `json:"origin,omitempty"`
CreatedAt []string `json:"createdAt,omitempty"`
DisabledAt []string `json:"disabledAt,omitempty"`
DisabledReason []string `json:"disabledReason,omitempty"`
}
type DisablePatch struct {
Reason string `json:"reason"`
}
type AssetTag struct {
AssetID string `json:"assetID"`
TagID string `json:"tagID"`
CreatedAt time.Time `json:"createdAt"`
}
type AssetExternal struct {
ID string `json:"id"`
AssetID string `json:"assetID"`
External string `json:"external"`
Comment *string `json:"comment"`
}
type AssetComment struct {
ID string `json:"id"`
Value string `json:"value"`
CreatedBy string `json:"createdBy"`
CreatedAt time.Time `json:"createdAt"`
ChangedAt *time.Time `json:"changedAt"`
AssetID *string `json:"assetID"`
}
type Bundle struct {
ID string `json:"id"`
Name string `json:"name"`
ComplianceScanInterval int `json:"scanInterval"`
Disabled bool `json:"disabled"`
}
type Contact struct {
ID string `json:"id"`
Email string `json:"email"`
}
type ASN int64
func (a ASN) String() string {
return fmt.Sprintf("AS%d", a)
}
type IPAS struct {
IP string `json:"ip"`
CIDR string `json:"cidr"`
ASN ASN `json:"asn"`
Organization string `json:"organization"`
CountryCode string `json:"countryCode"`
Country string `json:"country"`
IsEU bool `json:"isEU"`
}
type AssetInfoASN struct {
IPASs []IPAS `json:"ipASs"`
Nameserver []string `json:"nameserver"`
IsEU *bool `json:"isEU,omitempty"`
}
type AssetInfoValidation struct {
Redirects []Redirect `json:"redirects"`
HasBadRedirect bool `json:"hasBadRedirect"`
Scheme string `json:"scheme"`
StatusCode int `json:"statusCode"`
HasHTTP bool `json:"hasHTTP"`
HasHTTPS bool `json:"hasHTTPS"`
HostsDifferent bool `json:"hostsDifferent"`
ContentEqual bool `json:"contentEqual"`
HTTPDowngrade bool `json:"httpDowngrade"`
}
type DiscoveryInput struct {
Name string `json:"name"`
Src string `json:"src"`
Value string `json:"value"`
}
type Redirect struct {
URL string `json:"url"`
Address string `json:"address"`
StatusCode int `json:"statusCode"`
}
type AssetInfoDiscovery struct {
Sources []DiscoveryInput `json:"sources"`
Redirects []Redirect `json:"redirects"`
}
type AssetInfoApplications []AssetInfoApplication
type AssetInfoApplication struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
Path string `json:"path,omitempty"`
Category string `json:"category"`
Source string `json:"source"`
Latest bool `json:"latest"`
Vulnerable bool `json:"vulnerable"`
Consented bool `json:"consented"`
}
type AssetInfoLinks struct {
External int `json:"external"`
Internal int `json:"internal"`
BrokenExternal int `json:"brokenExternal"`
BrokenInternal int `json:"brokenInternal"`
Links []string `json:"links"`
}
type AssetInfoType string
type AssetInfo struct {
AssetID string `json:"assetID"`
Type AssetInfoType `json:"type"`
Details interface{} `json:"details"`
ChangedAt time.Time `json:"changedAt"`
}
type Metadata struct {
AssetID string `json:"assetID"`
Infos map[AssetInfoType]AssetInfo `json:"infos"`
}
type MetadataFilter struct {
Types []string `url:"type,omitempty"`
}
type IssueExternal struct {
IssueID string `json:"issueID"`
ExternalID string `json:"externalID"`
Comment *string `json:"comment"`
}
type IssueType string
type Severity int
type IssueStatus int
type Issue struct {
ID string `json:"id"`
AssetID string `json:"assetID"`
Type IssueType `json:"type"`
Severity Severity `json:"severity"`
Status IssueStatus `json:"status"`
StatusChangedAt time.Time `json:"statusChangedAt"`
CreatedAt time.Time `json:"createdAt"`
LastSeenAt time.Time `json:"lastSeenAt"`
Details interface{} `json:"details"`
CommentID *string `json:"commentID"`
}
// tempIssue is an temporary struct to work with the raw byte response from the API
type tempIssue struct {
Issue
RawDetails json.RawMessage `json:"details"`
}
// unmarshalDetails converts the given details value from the API to the correct details type
func (issue *tempIssue) unmarshalDetails() error {
switch issue.Type {
case IssueTypeComplianceContentPolicy:
d := ContentPolicyDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
case IssueTypeComplianceCookieOptIn:
d := CookieDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
case IssueTypeComplianceCookiePolicy:
d := CookiePolicyDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
case IssueTypeComplianceFormExternal,
IssueTypeComplianceFormHTTP,
IssueTypeComplianceFormSensitive:
d := FormDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
case IssueTypeComplianceStatusCode:
d := StatusCodeDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
case IssueTypeComplianceTrackerOptIn:
d := TrackerDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
case IssueTypeComplianceTrackerPolicy:
d := TrackerPolicyDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
case IssueTypeDanglingDNS:
d := DanglingDNSDetails{}
err := json.Unmarshal(issue.RawDetails, &d)
if err != nil {
return err
}
issue.Details = d
default:
return errors.Errorf("unknown issue type '%s' for id '%s'", issue.Type, issue.ID)
}
return nil
}
type IssueFilter struct {
Statuses []IssueStatus `json:"statuses"`
Externals []string `json:"externals"`
}
type TrackerCategory string
type TrackerDetails struct {
Name string `json:"name"`
Category TrackerCategory `json:"category"`
Hostname string `json:"hostname"`
Initiators [][]Initiator `json:"initiators"`
Visited bool `json:"visited"`
Consented bool `json:"consented"`
}
type TrackerPolicyDetails struct {
TrackerDetails
Rule string `json:"rule"`
}
type DanglingDNSDetails struct {
Ports string `json:"ports"`
CloudService string `json:"cloudService"`
}
// Initiator holds all information about the initiator of an request/malware issue
type Initiator struct {
InitType string `json:"type"`
URL string `json:"url"`
Line string `json:"line"`
Column string `json:"column"`
}
type StatusCodeDetails struct {
URL string `json:"url"`
StatusCode int `json:"statusCode"`
ExpectedCode int `json:"expected"`
}
type FormDetails struct {
URLs []string `json:"urls"`
Name string `json:"name"`
FormID string `json:"formID,omitempty"`
Action string `json:"action"`
Method string `json:"method"`
InputFields []InputDetails `json:"inputDetails"`
HTTPTransmit bool `json:"httpTransmit"`
ExternalTransmit bool `json:"externalTransmit"`
// if it contains input fields that violates either art 9 or 10 once
Art9 bool `json:"art9"`
Art10 bool `json:"art10"`
}
type InputDetails struct {
InputName string `json:"inputName"`
InputType string `json:"inputType"`
InputID string `json:"inputID,omitempty"`
InputAutocomplete string `json:"inputAutocomplete"`
InputPlaceholder string `json:"inputPlaceholder"`
Category string `json:"category"`
Art9 bool `json:"art9"`
Art10 bool `json:"art10"`
}
type CookieDetails struct {
Name string `json:"name"`
URLValues []URLValue `json:"urlValues"` // URLValues[value]{url,url...}
Domain string `json:"domain"`
HTTPOnly bool `json:"httpOnly"`
Lifetime int64 `json:"lifetime"`
SameSite string `json:"sameSite"`
Secure bool `json:"secure"`
ThirdParty bool `json:"thirdParty"`
InGlobalWhitelist bool `json:"inGlobalWhitelist"`
InCustomWhitelist bool `json:"inCustomWhitelist"`
InServerResponse bool `json:"inServerResponse"`
Consented bool `json:"consented"`
}
type URLValue struct {
URL string `json:"url"`
Value string `json:"value"`
}
type CookiePolicyDetails struct {
CookieDetails
}
type ContentPolicyDetails struct {
URL string `json:"url"`
Rule string `json:"rule"`
}
type IssuePatch struct {
IssueID string `json:"issueID"`
Status IssueStatus `json:"status"`
Comment *string `json:"comment"`
}
type TagType string
type Tag struct {
ID string `json:"id"`
Name string `json:"name"`
Description *string `json:"description"`
Type TagType `json:"type"`
}