This repository has been archived by the owner on May 21, 2020. It is now read-only.
forked from skbkontur/frontreport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontreport.go
124 lines (107 loc) · 4.05 KB
/
frontreport.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
package frontreport
import "strings"
// Reportable structs can be saved to Elastic
// - their Type and Service defines index to save to;
// - they can hold Timestamp for Elastic to sort on.
type Reportable interface {
GetType() string
GetService() string
SetTimestamp(string)
SetHost(string)
}
// Report is a generic report type (they don't have much in common)
type Report struct {
Timestamp string `json:"@timestamp"`
Host string `json:"frontreport-host"`
Service string `json:"service"`
}
// SetTimestamp sets timestamp for Elastic default sorting
func (r *Report) SetTimestamp(ts string) {
r.Timestamp = ts
}
// SetHost sets hostname to tell apart reports from different sites
func (r *Report) SetHost(h string) {
r.Host = h
}
// GetService returns service to tell apart reports from different sites
func (r *Report) GetService() string {
return strings.ToLower(r.Service)
}
// CSPReport is a Content Security Policy report as per http://www.w3.org/TR/CSP/
type CSPReport struct {
Report
Body struct {
DocumentURI string `json:"document-uri"`
Referrer string `json:"referrer"`
BlockedURI string `json:"blocked-uri"`
ViolatedDirective string `json:"violated-directive"`
EffectiveDirective string `json:"effective-directive"`
OriginalPolicy string `json:"original-policy"`
} `json:"csp-report"`
}
// GetType returns report type
func (c CSPReport) GetType() string {
return "csp"
}
// PKPReport is a Public Key Pinning report as per https://tools.ietf.org/html/draft-ietf-websec-key-pinning-21
type PKPReport struct {
Report
DateTime string `json:"date-time"`
Hostname string `json:"hostname"`
Port int `json:"port"`
EffectiveExpirationDate string `json:"effective-expiration-date"`
IncludeSubdomains bool `json:"include-subdomains"`
NotedHostname string `json:"noted-hostname"`
ServedCertificateChain []string `json:"served-certificate-chain"`
ValidatedCertificateChain []string `json:"validated-certificate-chain"`
KnownPins []string `json:"known-pins"`
}
// GetType returns report type
func (p PKPReport) GetType() string {
return "pkp"
}
// StacktraceJSStackframe is a single stack frame representation
type StacktraceJSStackframe struct {
FunctionName string `json:"functionName"`
FileName string `json:"fileName"`
LineNumber int `json:"lineNumber"`
ColumnNumber int `json:"columnNumber"`
}
// StacktraceJSReport is a universal browser stacktrace format as per https://github.com/stacktracejs/stacktrace.js#stacktracereportstackframes-url-message--promisestring
type StacktraceJSReport struct {
Report
Message string `json:"message"`
Stack []StacktraceJSStackframe `json:"stack"`
// These fields are not a part of StacktraceJS specification, but are useful for error reports
Browser *struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
} `json:"browser,omitempty"`
OS *struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
} `json:"os,omitempty"`
URL string `json:"url,omitempty"`
SourceURL string `json:"sourceUrl,omitempty"`
UserID string `json:"userId,omitempty"`
StackHash string `json:"stackHash,omitempty"`
ScriptURL string `json:"scriptUrl,omitempty"`
// These fields are experimental and can disappear in the future
PartyID string `json:"partyId,omitempty"`
DepartmentID string `json:"departmentId,omitempty"`
SalesPointID string `json:"salesPointId,omitempty"`
RetailUIVersion string `json:"retailUiVersion,omitempty"`
AppVersion string `json:"appVersion,omitempty"`
}
// GetType returns report type
func (s StacktraceJSReport) GetType() string {
return "stacktracejs"
}
// ReportStorage is a way to store incoming reports
type ReportStorage interface {
AddReport(Reportable)
}
// SourcemapProcessor converts stacktrace to readable format using sourcemaps
type SourcemapProcessor interface {
ProcessStack([]StacktraceJSStackframe) []StacktraceJSStackframe
}