-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
feat(middleware): v4 experimental middleware #986
base: main
Are you sure you want to change the base?
Changes from 1 commit
f2556e5
7d69e57
9784368
c9180ed
25c73e4
b96d2b7
d0cdc0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,33 @@ | |
package experimental | ||
|
||
import ( | ||
"embed" | ||
"net/http" | ||
|
||
"github.com/corazawaf/coraza/v3" | ||
) | ||
|
||
//go:embed error_template.html error_template.html | ||
var embededTemplates embed.FS | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So... are these going to be In summary:
If we use static html, maybe removing the "_template" in the name will make more sense, and use "default_error.html" and "default_interruption.html" instead? |
||
|
||
var ( | ||
errorTemplate []byte | ||
interruptionTemplate []byte | ||
) | ||
|
||
func init() { | ||
var err error | ||
errorTemplate, err = embededTemplates.ReadFile("error_template.html") | ||
if err != nil { | ||
panic(err) | ||
} | ||
interruptionTemplate, err = embededTemplates.ReadFile("interruption_template.html") | ||
if err != nil { | ||
panic(err) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't we avoid error handling at the |
||
|
||
} | ||
|
||
// Options represents the options for the experimental middleware | ||
type Options struct { | ||
// EnforceBlocking enables the blocking of requests that are interrupted | ||
|
@@ -41,6 +63,21 @@ | |
// If the rate is 0, the middleware will not sample | ||
// If the rate is 100, the middleware will sample all requests | ||
SamplingRate int | ||
|
||
// CustomInterruptionTemplate represents the custom interruption template | ||
// If the interruption is not processed, the middleware will use a default | ||
// Interruption template supports variables in macro expansion format: %{var} | ||
// Variables are: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Macro expansion as in SecRule macro expansion? |
||
// - transaction_id | ||
CustomInterruptionTemplate []byte | ||
|
||
// CustomErrorTemplate represents the custom error template | ||
// If the middleware fails to process the request, it will use a default | ||
// Error template supports variables in macro expansion format: %{var} | ||
// Variables are: | ||
// - transaction_id | ||
// - error | ||
CustomErrorTemplate []byte | ||
} | ||
|
||
// DefaultOptions returns the default options for the middleware | ||
|
@@ -64,6 +101,11 @@ | |
// Keys are: | ||
// - coraza_transaction: types.Transaction | ||
// - coraza_interruption: types.Interruption | ||
// - coraza_error: error | ||
// | ||
// If Coraza fails to process the request, the middleware will return a generic error. | ||
// The next handler will not be executed and coraza_error will be available under | ||
// the request context. | ||
// | ||
// The middleware will flush the request body and it will consume | ||
// the response in case ProcessResponse Option is enabled. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just to fix this. But I suggest changing to "default_error.html" and "default_interruption.html", pending on the next comment.