Skip to content

Commit

Permalink
chore: reverts corazawaf#86. (corazawaf#88)
Browse files Browse the repository at this point in the history
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
  • Loading branch information
jcchavezs and anuraaga authored Nov 17, 2022
1 parent 5d9a67b commit 9df6348
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 92 deletions.
27 changes: 1 addition & 26 deletions rules/fs.go → fs.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
// Copyright The OWASP Coraza contributors
// SPDX-License-Identifier: Apache-2.0

package rules
package main

import (
"embed"
"fmt"
"io/fs"
"strings"
)

var (
//go:embed crs/* *.conf *.example
rules embed.FS
// FS is the filesystem that contains the embedded rule set and recommended
// configurations
FS fs.FS
)

func init() {
FS = &rulesFS{
rules,
map[string]string{
"@recommended-conf": "coraza.conf-recommended.conf",
"@demo-conf": "coraza-demo.conf",
"@crs-setup-demo-conf": "crs-setup-demo.conf",
"@ftw-conf": "ftw-config.conf",
"@crs-setup-conf": "crs-setup.conf.example",
},
map[string]string{
"@owasp_crs": "crs",
},
}
}

type rulesFS struct {
fs fs.FS
filesMapping map[string]string
Expand Down
24 changes: 22 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package main

import (
"bytes"
"embed"
"io/fs"
"strconv"
"strings"

Expand All @@ -15,9 +17,11 @@ import (

"github.com/corazawaf/coraza-proxy-wasm/internal/bodyprocessors"
"github.com/corazawaf/coraza-proxy-wasm/internal/operators"
"github.com/corazawaf/coraza-proxy-wasm/rules"
)

//go:embed rules
var crs embed.FS

func main() {
bodyprocessors.Register()
operators.Register()
Expand Down Expand Up @@ -58,6 +62,22 @@ func (ctx *corazaPlugin) OnPluginStart(pluginConfigurationSize int) types.OnPlug
return types.OnPluginStartStatusFailed
}

root, _ := fs.Sub(crs, "rules")

root = &rulesFS{
root,
map[string]string{
"@recommended-conf": "coraza.conf-recommended.conf",
"@demo-conf": "coraza-demo.conf",
"@crs-setup-demo-conf": "crs-setup-demo.conf",
"@ftw-conf": "ftw-config.conf",
"@crs-setup-conf": "crs-setup.conf.example",
},
map[string]string{
"@owasp_crs": "crs",
},
}

// First we initialize our waf and our seclang parser
conf := coraza.NewWAFConfig().
WithErrorLogger(logError).
Expand All @@ -67,7 +87,7 @@ func (ctx *corazaPlugin) OnPluginStart(pluginConfigurationSize int) types.OnPlug
// TinyGo compilation will prevent buffering request body to files anyways.
// TODO(anuraaga): Make this configurable in plugin configuration.
WithInMemoryLimit(1024 * 1024 * 1024)).
WithRootFS(rules.FS)
WithRootFS(root)

waf, err := coraza.NewWAF(conf.WithDirectives(strings.Join(config.rules, "\n")))
if err != nil {
Expand Down
64 changes: 0 additions & 64 deletions rules/fs_test.go

This file was deleted.

0 comments on commit 9df6348

Please sign in to comment.