Skip to content

Commit

Permalink
clean injectedValue alert log
Browse files Browse the repository at this point in the history
  • Loading branch information
TarradeMarc committed Mar 22, 2024
1 parent 91a014d commit 0441572
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Binary file modified proxy/wasm/cloud-active-defense.wasm
Binary file not shown.
19 changes: 15 additions & 4 deletions proxy/wasm/detect/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (d *detectHeader) detectCookie(alertInfos *map[string]string) (error, bool)
return nil, false
}
cookie = key+"="+cookie // for matching combined / modified
(*alertInfos)["injected"] = cookie
(*alertInfos)["injected"] = d.cookies[key]
err, keyMatch, combinedMatch := shared.KeyCombinedMatch(d.curFilter, &cookie)
if err != nil {
return fmt.Errorf("could not match: %v", err.Error()), false
Expand Down Expand Up @@ -326,7 +326,7 @@ func (d *detectHeader) detectHeader(alertInfos *map[string]string) (error, bool)
return nil, false
}
header = key+"="+header
(*alertInfos)["decoy"] = header
(*alertInfos)["injected"] = d.headers[key]
err, keyMatch, combinedMatch := shared.KeyCombinedMatch(d.curFilter, &header)
if config_proxy.Debug { proxywasm.LogWarnf("detect in header matches key %v, combined %v", keyMatch, combinedMatch ) } //debug
if err != nil {
Expand Down Expand Up @@ -370,7 +370,7 @@ func (d *detectHeader) detectUrl(alertInfos *map[string]string) (error, bool) {
} else if queryStart := strings.IndexByte(fullPath, '?'); queryStart >= 0 {
fullPath = fullPath[:queryStart] // cut query params of
}
(*alertInfos)["decoy"] = fullPath
(*alertInfos)["injected"] = fullPath
err, keyMatch, combinedMatch := shared.KeyCombinedMatch(d.curFilter, &fullPath)
if err != nil {
return fmt.Errorf("could not match: %v", err.Error()), false
Expand Down Expand Up @@ -415,7 +415,6 @@ func (d *detectHeader) detectGetParam(alertInfos *map[string]string) (error, boo
} else if queryStart := strings.IndexByte(query, '?'); queryStart >= 0 {
query = query[queryStart:] // cut path of
}
(*alertInfos)["decoy"] = query

// if key / value are regex, use them & find matches else use stringmatches
var keyMatch, combinedMatch bool
Expand Down Expand Up @@ -447,6 +446,18 @@ func (d *detectHeader) detectGetParam(alertInfos *map[string]string) (error, boo
}
}

rEValue, err := regexp.Compile(`(\?|&)` + key + `[^&]*`)
if err != nil {
return fmt.Errorf("failed to retrieve getParam value of decoy: " , err.Error()), false
}
matchesValue := rEValue.FindAllString(query, -1)
injected := strings.Join(matchesValue, ", ")
keyRm, err := regexp.Compile(`(&|\?)` + key + "=")
if err != nil {
return fmt.Errorf("failed to retrieve getParam value of decoy: " , err.Error()), false
}
(*alertInfos)["injected"] = keyRm.ReplaceAllString(injected, "")

if d.curFilter.Detect.Alert.WhenSeen && key != "" {
if keyMatch {
(*alertInfos)["alert"] = "KeySeen "
Expand Down

0 comments on commit 0441572

Please sign in to comment.