Skip to content

Commit

Permalink
fix whenTrue/False checking in payload
Browse files Browse the repository at this point in the history
  • Loading branch information
TarradeMarc committed Apr 2, 2024
1 parent 43c0792 commit 9e9ccb8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Binary file modified proxy/wasm/cloud-active-defense.wasm
Binary file not shown.
8 changes: 4 additions & 4 deletions proxy/wasm/config_parser/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func (v *validator) validateWhenTrue(obj ConditionType) {
if obj == EmptyCondition() {
return
}
if breaksRequired(obj.Key) {
v.addError(v.currentPlace+".key", "is required and can not be empty")
if breaksRequired(obj.Key) && (obj.In == "header" || obj.In == "cookie" || obj.In == "getParam" || obj.In == "postParam") {
v.addError(v.currentPlace+".key", "is required and can not be empty for header, cookie, getParam and postParams")
}
if breaksRequired(obj.Value) {
v.addError(v.currentPlace+".value", "is required and can not be empty")
Expand All @@ -185,8 +185,8 @@ func (v *validator) validateWhenFalse(obj ConditionType) {
if obj == EmptyCondition() {
return
}
if breaksRequired(obj.Key) {
v.addError(v.currentPlace+".key", "is required and can not be empty")
if breaksRequired(obj.Key) && (obj.In == "header" || obj.In == "cookie" || obj.In == "getParam" || obj.In == "postParam") {
v.addError(v.currentPlace+".key", "is required and can not be empty for header, cookie, getParam and postParams")
}
if breaksRequired(obj.Value) {
v.addError(v.currentPlace+".value", "is required and can not be empty")
Expand Down
4 changes: 2 additions & 2 deletions proxy/wasm/inject/body.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (i *injecterBody) checkConditionsResponse() (error, bool) {
}

for _, condition := range i.curFilter.Inject.WhenTrue {
err, applies := WhenTrue(i.request, &condition)
err, applies := WhenTrue(&shared.HttpRequest{Body: &i.responseBody, Headers: i.request.Headers, Cookies: i.request.Cookies}, &condition)
if err != nil {
return err, false
}
Expand All @@ -148,7 +148,7 @@ func (i *injecterBody) checkConditionsResponse() (error, bool) {
}
}
for _, condition := range i.curFilter.Inject.WhenFalse {
err, applies := WhenFalse(i.request, &condition)
err, applies := WhenFalse(&shared.HttpRequest{Body: &i.responseBody, Headers: i.request.Headers, Cookies: i.request.Cookies}, &condition)
if err != nil {
return err, false
}
Expand Down
7 changes: 6 additions & 1 deletion proxy/wasm/inject/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ func checkBody(request *shared.HttpRequest, condition *config_parser.ConditionTy
if request.Body == nil {
return fmt.Errorf("can not check body conditions in header injection"), false
}
value := condition.Key+"="+condition.Value
value := ""
if condition.Key != "" {
value = condition.Key+"="+condition.Value
} else {
value = condition.Value
}
if value == "" {
return nil, false
}
Expand Down

0 comments on commit 9e9ccb8

Please sign in to comment.