Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CRS 4.0.0 rc2 adding a cleanup phase #9

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"fmt"

"github.com/corazawaf/coraza-coreruleset"
coreruleset "github.com/corazawaf/coraza-coreruleset"
"github.com/corazawaf/coraza/v3"
)
Expand Down
32 changes: 30 additions & 2 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,18 @@ import (
func DownloadCRS() error {
rulesDir := "rules"
rulesDstDir := rulesDir + "/@owasp_crs"
if err := os.MkdirAll(rulesDstDir, os.ModePerm); err != nil {
testsDir := "tests"

// Before downloading, we need to remove:
// - old rules under rules/@owasp_crs
// - all the related tests
if err := cleanupOldCRS(rulesDstDir, testsDir); err != nil {
return err
}

testsDir := "tests"
if err := os.MkdirAll(rulesDstDir, os.ModePerm); err != nil {
return err
}

uri := fmt.Sprintf("https://github.com/coreruleset/coreruleset/archive/%s.zip", crsVersion)

Expand Down Expand Up @@ -158,6 +165,27 @@ func copyFile(f *zip.File, dstPath string) error {
return nil
}

func cleanupOldCRS(rulesDstDir, testsDir string) error {
if err := os.RemoveAll(rulesDstDir); err != nil {
return err
}
if err := filepath.WalkDir(testsDir, func(path string, d os.DirEntry, err error) error {
if err != nil {
return err
}
if strings.HasPrefix(d.Name(), "REQUEST-") || strings.HasPrefix(d.Name(), "RESPONSE-") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wonder about this, shall we just remove everything? Otherwise could you add a comment on why this condition?

Copy link
Member Author

@M4tteoP M4tteoP Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to make it more explicit. The goal is to not delete .go files that belong to this repo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am lost now, do we iterate over root files in this repo? Can't we just delete rules folder and tests folder?

if err := os.RemoveAll(path); err != nil {
return err
}
return filepath.SkipDir
}
return nil
}); err != nil {
return err
}
return nil
}

func Test() error {
return sh.RunV("go", "test", "./...")
}
34 changes: 0 additions & 34 deletions rules/@owasp_crs/crawlers-user-agents.data

This file was deleted.

8 changes: 0 additions & 8 deletions rules/@owasp_crs/scanners-headers.data

This file was deleted.

17 changes: 0 additions & 17 deletions rules/@owasp_crs/scanners-urls.data

This file was deleted.

27 changes: 0 additions & 27 deletions rules/@owasp_crs/scripting-user-agents.data

This file was deleted.

39 changes: 0 additions & 39 deletions tests/REQUEST-913-SCANNER-DETECTION/913101.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions tests/REQUEST-913-SCANNER-DETECTION/913102.yaml

This file was deleted.

44 changes: 0 additions & 44 deletions tests/REQUEST-913-SCANNER-DETECTION/913110.yaml

This file was deleted.

57 changes: 0 additions & 57 deletions tests/REQUEST-913-SCANNER-DETECTION/913120.yaml

This file was deleted.

Loading