Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Static Analysis

on:
push:
branches: [ master ]
paths:
- '.github/workflows/lint.yaml'
- 'waf-check/**'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/lint.yaml'
- 'waf-check/**'


jobs:
build:
name: "Lint"
runs-on: ubuntu-latest

permissions:
contents: read

steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: waf-check/go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.0
args: --issues-exit-code=1 --timeout 10m
only-new-issues: false
working-directory: waf-check
9 changes: 6 additions & 3 deletions .github/workflows/waf-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ jobs:
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.22'
fetch-depth: 0

- uses: actions/setup-go@v5
with:
go-version-file: waf-check/go.mod
- name: Split dateset
run: |
cd waf-check && go build -o waf-check
Expand Down Expand Up @@ -101,4 +104,4 @@ jobs:
if: always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
name: waf-check-dataset
name: waf-check-dataset
133 changes: 133 additions & 0 deletions waf-check/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
version: "2"

linters:
default: all
disable:
- errcheck
- exhaustruct
- forbidigo
- musttag
- noctx
- perfsprint
- unparam
- prealloc

- cyclop # revive
- funlen # revive
- gocognit # revive
- gocyclo # revive
- lll # revive

- gosec # (gas): Inspects source code for security problems
- wrapcheck # Checks that errors returned from external packages are wrapped
- mnd # An analyzer to detect magic numbers.
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
- whitespace # Whitespace is a linter that checks for unnecessary newlines at the start and end of functions, if, for, etc.
- wsl # add or remove empty lines
- err113 # Go linter to check the errors handling expressions
- tagliatelle # Checks the struct tags.
- varnamelen # checks that the length of a variable's name matches its scope

settings:

depguard:
rules:
yaml:
files:
- '!**/config.go'
deny:
- pkg: gopkg.in/yaml.v2
desc: yaml.v2 is deprecated for new code in favor of yaml.v3

errcheck:
check-type-assertions: false

gocritic:
enable-all: true
disabled-checks:
- hugeParam
- paramTypeCombine
- exitAfterDefer

govet:
disable:
- fieldalignment
enable-all: true

misspell:
locale: US

nlreturn:
block-size: 5

nolintlint:
require-explanation: false # don't require an explanation for nolint directives
require-specific: false # don't require nolint directives to be specific about which linter is being skipped
allow-unused: false # report any unused nolint directives

revive:
severity: error
enable-all-rules: true
rules:
- name: add-constant
disabled: true
- name: cognitive-complexity
arguments:
# lower this after refactoring
- 19
- name: cyclomatic
arguments:
# lower this after refactoring
- 13
- name: deep-exit
disabled: true
- name: line-length-limit
arguments:
# lower this after refactoring
- 111

staticcheck:
checks:
- all

wsl:
# Allow blocks to end with comments
allow-trailing-comment: true

exclusions:
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:

- linters:
- govet
text: 'shadow: declaration of "(err|ctx)" shadows declaration'

paths:
- third_party$
- builtin$
- examples$

issues:
max-issues-per-linter: 0
max-same-issues: 0

formatters:
enable:
- gci
- gofumpt

settings:
gci:
sections:
- standard
- default

exclusions:
paths:
- third_party$
- builtin$
- examples$
12 changes: 6 additions & 6 deletions waf-check/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ type Config struct {
NbRoutines int `yaml:"nb_routines"`
OutputFolder string `yaml:"output_folder"`
DownloadDataset bool `yaml:"download_dataset"`
statusCode int `yaml:"-"`
path string `yaml:"-"`
batch bool `yaml:"-"`
dirCount int `yaml:"-"`
statusCode int
path string
batch bool
dirCount int
}

func LoadConfig() (Config, error) {
Expand All @@ -38,12 +38,12 @@ func LoadConfig() (Config, error) {

data, err := os.ReadFile(*configFile)
if err != nil {
return config, fmt.Errorf("error reading YAML file: %s", err)
return config, fmt.Errorf("error reading YAML file: %w", err)
}

err = yaml.Unmarshal(data, &config)
if err != nil {
return config, fmt.Errorf("error unmarshaling YAML: %s", err)
return config, fmt.Errorf("error unmarshaling YAML: %w", err)
}

if *outputFolder != "" {
Expand Down
4 changes: 1 addition & 3 deletions waf-check/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import (
"os"
)

const (
datasetURL = "https://downloads.openappsec.io/waf-comparison-project/legitimate.zip"
)
const datasetURL = "https://downloads.openappsec.io/waf-comparison-project/legitimate.zip"

func DownloadDataset(datasetFolder string) ([]string, error) {
fmt.Printf("Downloading dataset to '%s'\n", datasetFolder)
Expand Down
21 changes: 2 additions & 19 deletions waf-check/go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
module waf-check

go 1.21.3
go 1.24

require (
github.com/cheggaaa/pb/v3 v3.1.4
github.com/google/uuid v1.5.0
github.com/schollz/progressbar/v3 v3.14.1
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/term v0.14.0 // indirect
)
require gopkg.in/yaml.v2 v2.4.0
39 changes: 1 addition & 38 deletions waf-check/go.sum
Original file line number Diff line number Diff line change
@@ -1,41 +1,4 @@
github.com/VividCortex/ewma v1.2.0 h1:f58SaIzcDXrSy3kWaHNvuJgJ3Nmz59Zji6XoJR/q1ow=
github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAUnGx7j5l4=
github.com/cheggaaa/pb/v3 v3.1.4 h1:DN8j4TVVdKu3WxVwcRKu0sG00IIU6FewoABZzXbRQeo=
github.com/cheggaaa/pb/v3 v3.1.4/go.mod h1:6wVjILNBaXMs8c21qRiaUM8BR82erfgau1DQ4iUXmSA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/k0kubun/go-ansi v0.0.0-20180517002512-3bf9e2903213/go.mod h1:vNUNkEQ1e29fT/6vq2aBdFsgNPmy8qMdSay1npru+Sw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ=
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/schollz/progressbar/v3 v3.14.1 h1:VD+MJPCr4s3wdhTc7OEJ/Z3dAeBzJ7yKH/P4lC5yRTI=
github.com/schollz/progressbar/v3 v3.14.1/go.mod h1:Zc9xXneTzWXF81TGoqL71u0sBPjULtEHYtj/WVgVy8E=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.14.0 h1:LGK9IlZ8T9jvdy6cTdfKUCltatMFOehAQo9SRC46UQ8=
golang.org/x/term v0.14.0/go.mod h1:TySc+nGkYR6qt8km8wUhuFRTVSMIX3XPR58y2lC8vww=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
4 changes: 3 additions & 1 deletion waf-check/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func main() {
}
} else {
filesList, err = listJSONFiles(config.DatasetFolder)
if err != nil {
log.Fatalf("fail listing files: %s", err)
}
}

if len(filesList) == 0 {
Expand Down Expand Up @@ -64,5 +67,4 @@ func main() {
}

fmt.Printf("everything went well!\n")

}
6 changes: 2 additions & 4 deletions waf-check/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ func (m *Manager) processFile(file string) {
result.FailedTests = append(result.FailedTests, failedTest)
}
resp.Body.Close()
result.DoneTests += 1

result.DoneTests++
}

m.resultsChan <- result

}

func NewManager(config Config, filesList []string) Manager {
Expand All @@ -111,7 +109,7 @@ func NewManager(config Config, filesList []string) Manager {
}

func (m *Manager) Run() error {
for i := 0; i < m.NbWorker; i++ {
for range m.NbWorker {
go func() {
for file := range m.filesChan {
m.processFile(file)
Expand Down
6 changes: 3 additions & 3 deletions waf-check/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ func NewHTTPRequest(baseURL string, request *Request) (http.Request, error) {
return http.Request{}, fmt.Errorf("error joining URL: %w", err)
}

if request.Method == "POST" || request.Method == "PUT" {
if request.Method == http.MethodPost || request.Method == http.MethodPut {
req, err = http.NewRequest(request.Method, request.FullURL, bytes.NewBufferString(request.Data))
} else {
req, err = http.NewRequest(request.Method, request.FullURL, nil)
req, err = http.NewRequest(request.Method, request.FullURL, http.NoBody)
}

if err != nil {
Expand All @@ -58,7 +58,7 @@ func (r *Request) Curl() string {
for key, value := range r.Headers {
curlCmd.WriteString(fmt.Sprintf(" -H '%s: %s'", key, value))
}
if r.Method == "POST" || r.Method == "PUT" {
if r.Method == http.MethodPost || r.Method == http.MethodPut {
curlCmd.WriteString(fmt.Sprintf(" -d '%s'", r.Data))
}
curlCmd.WriteString(fmt.Sprintf(" '%s'", r.FullURL))
Expand Down
6 changes: 3 additions & 3 deletions waf-check/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ func GetResult(resultsChan chan Result, outputFolder string) error {
totalFileRun := 0
totalTestFail := 0
for result := range resultsChan {
totalFileRun += 1
totalFileRun++
totalTestRun += result.DoneTests
totalTestFail += len(result.FailedTests)

resultCpt += 1
resultCpt++

percentage := (100.0 * float32(len(result.FailedTests))) / float32(result.DoneTests)
fmt.Printf("'%s' result:\n", result.Filename)
Expand All @@ -33,7 +33,7 @@ func GetResult(resultsChan chan Result, outputFolder string) error {
if err != nil {
log.Fatalf("unable to marshal: %+v", result)
}
if err := os.WriteFile(failedTestsPath, jsonData, 0644); err != nil {
if err := os.WriteFile(failedTestsPath, jsonData, 0o644); err != nil {
log.Fatalf("unable to write failed report '%s': %s", failedTestsPath, err)
}
fmt.Printf(" - failed tests report: '%s'\n", failedTestsPath)
Expand Down
Loading