-
-
Notifications
You must be signed in to change notification settings - Fork 337
Fill ARGS_POST variable even if body bytes were invalid JSON when JSON body processor is running #1615
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
Open
HusseinKabbout
wants to merge
11
commits into
corazawaf:main
Choose a base branch
from
HusseinKabbout:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+99
−9
Open
Fill ARGS_POST variable even if body bytes were invalid JSON when JSON body processor is running #1615
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4c44f4f
Fill ARGS_POST variable even if body bytes were invalid JSON when JSO…
4915775
Add e2e test to check if process ProcessPartial and JSON body process…
5533954
Typo
HusseinKabbout b192bf7
Merge branch 'main' into main
HusseinKabbout 01e87f5
Merge branch 'main' into main
HusseinKabbout 879cd8d
Return gjson error instead of silently dropping it
cb392d5
Add comments for more clearance
daff6e7
Fix wrong author
b59a645
Uncomment rule because we expect REQBODY_ERROR AND ARGS_POST to be set
ae69035
Merge remote-tracking branch 'upstream/main'
d454321
Remove obsolete comment
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,12 +30,13 @@ func (js *jsonBodyProcessor) ProcessRequest(reader io.Reader, v plugintypes.Tran | |
| // Process with recursion limit | ||
| col := v.ArgsPost() | ||
| data, err := readJSON(ss, bpo.RequestBodyRecursionLimit) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // The collection is populated before checking the error to still perform a best effort inspection of the payload | ||
| for key, value := range data { | ||
| col.SetIndex(key, 0, value) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Store the raw JSON in the TX variable for validateSchema | ||
| // This is needed because RequestBody is a Single interface without a Set method | ||
|
|
@@ -59,12 +60,13 @@ func (js *jsonBodyProcessor) ProcessResponse(reader io.Reader, v plugintypes.Tra | |
| // Process with no recursion limit as we don't have a directive for response body | ||
| col := v.ResponseArgs() | ||
| data, err := readJSON(ss, ignoreJSONRecursionLimit) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| // The collection is populated before checking the error to still perform a best effort inspection of the payload | ||
| for key, value := range data { | ||
|
M4tteoP marked this conversation as resolved.
|
||
| col.SetIndex(key, 0, value) | ||
| } | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Store the raw JSON in the TX variable for validateSchema | ||
| // This is needed because ResponseBody is a Single interface without a Set method | ||
|
|
@@ -80,12 +82,15 @@ func readJSON(s string, maxRecursion int) (map[string]string, error) { | |
| res := make(map[string]string) | ||
| key := []byte("json") | ||
|
|
||
| json := gjson.Parse(s) | ||
| err := readItems(json, key, maxRecursion, res) | ||
| if err != nil { | ||
| return res, err | ||
| } | ||
| if !gjson.Valid(s) { | ||
|
Member
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. Could you please explain why are we parsing the json before verifying out is valid? |
||
| return res, errors.New("invalid JSON") | ||
| } | ||
| json := gjson.Parse(s) | ||
| err := readItems(json, key, maxRecursion, res) | ||
| return res, err | ||
| return res, nil | ||
| } | ||
|
|
||
| // Transform JSON to a map[string]string | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.