Skip to content

Commit b3563c9

Browse files
committed
add check scripts, improve code, add nosec tag.
1 parent 467fdd7 commit b3563c9

File tree

6 files changed

+17
-9
lines changed

6 files changed

+17
-9
lines changed

check.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
golint -set_exit_status -min_confidence 0.3 ./...
2+
gocyclo -avg -over 15 .
3+
golangci-lint run ./...
4+
gosec -quiet ./...

check.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
golint -set_exit_status -min_confidence 0.3 ./...
2+
gocyclo -avg -over 15 .
3+
golangci-lint run ./...
4+
gosec -quiet ./...

http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4040

4141
// prevent arbitrary file read
4242
path := sections[2]
43-
if strings.Index(path, "../") != -1 || strings.Index(path, "/..") != -1 {
43+
if strings.Contains(path, "../") || strings.Contains(path, "/..") {
4444
h.logger.Println("[warning]", "found slash in url:", r.RequestURI)
4545
return
4646
}

log4shell.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ func New(cfg *Config) (*Server, error) {
9898
}
9999
tlsConfig = &tls.Config{
100100
Certificates: []tls.Certificate{*cert},
101-
}
101+
} // #nosec
102102
enableTLS = true
103103
} else if enableTLS {
104104
tlsConfig = &tls.Config{
105105
Certificates: []tls.Certificate{cfg.TLSCert},
106-
}
106+
} // #nosec
107107
}
108108

109109
// generate random string and add it to the http handler

obfuscate.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Obfuscate(raw string) string {
3939
// first select section length
4040
// use 0-3 is used to prevent include special
4141
// string like "jndi", "ldap" and "http"
42-
size := rand.Intn(4)
42+
size := rand.Intn(4) // #nosec
4343
if size > remaining {
4444
size = remaining
4545
}
@@ -69,10 +69,10 @@ func Obfuscate(raw string) string {
6969

7070
// generate useless data before section
7171
obfuscated.WriteString("${")
72-
n := 1 + rand.Intn(3) // 1-3
72+
n := 1 + rand.Intn(3) // 1-3 // #nosec
7373
for i := 0; i < n; i++ {
74-
front := randString(2 + rand.Intn(5))
75-
end := randString(2 + rand.Intn(5))
74+
front := randString(2 + rand.Intn(5)) // #nosec
75+
end := randString(2 + rand.Intn(5)) // #nosec
7676

7777
obfuscated.WriteString(front)
7878
if randBool() {

rand.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ func init() {
1010
}
1111

1212
func randBool() bool {
13-
return rand.Int63()%2 == 0
13+
return rand.Int63()%2 == 0 // #nosec
1414
}
1515

1616
func randString(n int) string {
1717
str := make([]rune, n)
1818
for i := 0; i < n; i++ {
19-
s := ' ' + 1 + rand.Intn(90)
19+
s := ' ' + 1 + rand.Intn(90) // #nosec
2020
switch {
2121
case s >= '0' && s <= '9':
2222
case s >= 'A' && s <= 'Z':

0 commit comments

Comments
 (0)