gosec

This commit is contained in:
naiba 2021-09-04 12:42:51 +08:00
parent 67faa7a63d
commit e40026f6cc
8 changed files with 13 additions and 14 deletions

View File

@ -23,4 +23,4 @@ jobs:
- name: Run Gosec Security Scanner - name: Run Gosec Security Scanner
uses: securego/gosec@master uses: securego/gosec@master
with: with:
args: ./... args: -exclude=G104 ./...

View File

@ -290,9 +290,9 @@ func handleCommandTask(task *pb.Task, result *pb.TaskResult) {
} }
timeout := time.NewTimer(time.Hour * 2) timeout := time.NewTimer(time.Hour * 2)
if utils.IsWindows() { if utils.IsWindows() {
cmd = exec.Command("cmd", "/c", task.GetData()) cmd = exec.Command("cmd", "/c", task.GetData()) // #nosec
} else { } else {
cmd = exec.Command("sh", "-c", task.GetData()) cmd = exec.Command("sh", "-c", task.GetData()) // #nosec
} }
cmd.Env = os.Environ() cmd.Env = os.Environ()
pg.AddProcess(cmd) pg.AddProcess(cmd)

View File

@ -32,7 +32,7 @@ func Start() (*Pty, error) {
if shellPath == "" { if shellPath == "" {
return nil, errors.New("没有可用终端") return nil, errors.New("没有可用终端")
} }
cmd := exec.Command(shellPath) cmd := exec.Command(shellPath) // #nosec
cmd.Env = append(os.Environ(), "TERM=xterm") cmd.Env = append(os.Environ(), "TERM=xterm")
tty, err := opty.Start(cmd) tty, err := opty.Start(cmd)
return &Pty{tty: tty, cmd: cmd}, err return &Pty{tty: tty, cmd: cmd}, err

View File

@ -29,10 +29,10 @@ func ServeWeb(port uint) *http.Server {
return t.Format("2006年1月2号 15:04:05") return t.Format("2006年1月2号 15:04:05")
}, },
"safe": func(s string) template.HTML { "safe": func(s string) template.HTML {
return template.HTML(s) return template.HTML(s) // #nosec
}, },
"tag": func(s string) template.HTML { "tag": func(s string) template.HTML {
return template.HTML(`<` + s + `>`) return template.HTML(`<` + s + `>`) // #nosec
}, },
"stf": func(s uint64) string { "stf": func(s uint64) string {
return time.Unix(int64(s), 0).Format("2006年1月2号 15:04") return time.Unix(int64(s), 0).Format("2006年1月2号 15:04")

View File

@ -81,7 +81,7 @@ func (n *Notification) Send(message string) error {
} }
transCfg := &http.Transport{ transCfg := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: verifySSL}, TLSClientConfig: &tls.Config{InsecureSkipVerify: verifySSL}, // #nosec
} }
client := &http.Client{Transport: transCfg, Timeout: time.Minute * 10} client := &http.Client{Transport: transCfg, Timeout: time.Minute * 10}

View File

@ -43,6 +43,5 @@ func (s Server) Marshal() template.JS {
tag, _ := json.Marshal(s.Tag) tag, _ := json.Marshal(s.Tag)
note, _ := json.Marshal(s.Note) note, _ := json.Marshal(s.Note)
secret, _ := json.Marshal(s.Secret) secret, _ := json.Marshal(s.Secret)
return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s}`, return template.JS(fmt.Sprintf(`{"ID":%d,"Name":%s,"Secret":%s,"DisplayIndex":%d,"Tag":%s,"Note":%s}`, s.ID, name, secret, s.DisplayIndex, tag, note)) // #nosec
s.ID, name, secret, s.DisplayIndex, tag, note))
} }

View File

@ -1,7 +1,7 @@
package utils package utils
import ( import (
"crypto/md5" "crypto/md5" // #nosec
"encoding/hex" "encoding/hex"
"math/rand" "math/rand"
"os" "os"
@ -34,11 +34,11 @@ func RandStringBytesMaskImprSrcUnsafe(n int) string {
remain-- remain--
} }
return *(*string)(unsafe.Pointer(&b)) return *(*string)(unsafe.Pointer(&b)) //#nosec
} }
func MD5(plantext string) string { func MD5(plantext string) string {
hash := md5.New() hash := md5.New() // #nosec
hash.Write([]byte(plantext)) hash.Write([]byte(plantext))
return hex.EncodeToString(hash.Sum(nil)) return hex.EncodeToString(hash.Sum(nil))
} }

View File

@ -1,7 +1,7 @@
package dao package dao
import ( import (
"crypto/md5" "crypto/md5" // #nosec
"encoding/hex" "encoding/hex"
"log" "log"
"sync" "sync"
@ -45,7 +45,7 @@ func OnDeleteNotification(id uint64) {
func SendNotification(desc string, muteable bool) { func SendNotification(desc string, muteable bool) {
if muteable { if muteable {
// 通知防骚扰策略 // 通知防骚扰策略
nID := hex.EncodeToString(md5.New().Sum([]byte(desc))) nID := hex.EncodeToString(md5.New().Sum([]byte(desc))) // #nosec
var flag bool var flag bool
if cacheN, has := Cache.Get(nID); has { if cacheN, has := Cache.Get(nID); has {
nHistory := cacheN.(NotificationHistory) nHistory := cacheN.(NotificationHistory)