-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecureheaders.go
60 lines (46 loc) · 1.18 KB
/
secureheaders.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
package headlysis
import "net/http"
type SecureHeader struct {
Name string
}
func (s SecureHeader) GetUrl() string {
return "https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/" + s.Name
}
//https://www.researchgate.net/publication/326280169_HTTP_security_headers_analysis_of_top_one_million_websites
var secureHeaders = []SecureHeader{
{"X-Frame-Options"},
{"Content-Security-Policy"},
{"X-Xss-Protection"},
{"X-Content-Type-Options"},
{"Strict-Transport-Security"},
{"Cache-Control"},
{"Clear-Site-Data"},
{"Referrer-Policy"},
{"Expect-CT"},
}
func isPresent(what string, in []string) bool {
var out = false
for _, k := range in {
if k == what {
out = true
break
}
}
return out
}
func GetMissingHeaders(reqHeaders http.Header) ([]SecureHeader, []SecureHeader) {
var responseHeadersNames []string
for key, _ := range reqHeaders {
responseHeadersNames = append(responseHeadersNames, key)
}
var notPresent []SecureHeader
var present []SecureHeader
for _, sh := range secureHeaders {
if !isPresent(sh.Name, responseHeadersNames) {
notPresent = append(notPresent, sh)
} else {
present = append(present, sh)
}
}
return notPresent, present
}