Skip to content

Commit

Permalink
fix: use MaxBodySize value inside Modsecurity struct (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
acouvreur authored Aug 8, 2022
1 parent bf893e0 commit 602b53e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions modsecurity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ var httpClient = &http.Client{
// Config the plugin configuration.
type Config struct {
ModSecurityUrl string `json:"modSecurityUrl,omitempty"`
MaxBodySize int64 `json:"maxBodySize,omitempty"`
MaxBodySize int64 `json:"maxBodySize"`
}

// CreateConfig creates the default plugin configuration.
func CreateConfig() *Config {
return &Config{}
return &Config{
// Safe default: if the max body size was not specified, use 10MB
// Note that this will break any file upload with files > 10MB. Hopefully
// the user will configure this parameter during the installation.
MaxBodySize: 10 * 1024 * 1024,
}
}

// Modsecurity a Modsecurity plugin.
Expand All @@ -44,15 +49,9 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
return nil, fmt.Errorf("modSecurityUrl cannot be empty")
}

// Safe default: if the max body size was not specified, use 10MB
// Note that this will break any file upload with files > 10MB. Hopefully
// the user will configure this parameter during the installation.
if config.MaxBodySize == 0 {
config.MaxBodySize = 10 * 1024 * 1024
}

return &Modsecurity{
modSecurityUrl: config.ModSecurityUrl,
maxBodySize: config.MaxBodySize,
next: next,
name: name,
logger: log.New(os.Stdout, "", log.LstdFlags),
Expand Down

0 comments on commit 602b53e

Please sign in to comment.