Skip to content

V2/json empty #2363

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

Closed
wants to merge 2 commits into from
Closed

V2/json empty #2363

wants to merge 2 commits into from

Conversation

marcstern
Copy link

This accepts a valid JSON request with only a number or a string, nothing else.
Example:
--29000000-B--
POST /test/json/test.html HTTP/1.1
content-type: application/json
Host: test
Content-Length: 2
User-Agent: Mozilla 4.0
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2

--29000000-C--
25
--29000000-F--

I added a test, so I hope it'll be accepted this time.
I had to create the complete (minimal) test for JSON parsing, so I hope it's correct.

@marcstern
Copy link
Author

Is it sufficient to have it reviewed?

@zimmerle
Copy link
Contributor

The discussion on how to handle the elements of a JSON into collections - ARGS, in this specific case - was placed for version 3 a while ago. There, it was established a pattern to navigate under the elements giving a flat structure (compatible with collection keys).

The flat structure allows one to select the elements of JSON inside the args; A powerful feature. Within this patch pinpoint, an element does not sound to be feasible. Am I right? Why not adopt the schema presented in ModSecurity version 3?

@zimmerle zimmerle self-requested a review July 23, 2020 15:01
@zimmerle zimmerle self-assigned this Jul 23, 2020
@zimmerle zimmerle added the 2.x Related to ModSecurity version 2.x label Jul 23, 2020
@marcstern
Copy link
Author

I didn't follow the discussion in v3. I can have a look at it if you can point me to it.
Anyway, I imagine that it's a big change. In the meantime (although I'm not sure that you'll invest a lot of time for major changes in v2), it would worth to fix the current situation, no? I don't see any problem with that fix.
If I understood your question, you're wondering if we can access the empty ARG? Indeed: ARGS:/^$/ or ARGS_NAMES "@rx ^$".
So, can we accept this trivial fix?
Thanks

@marcstern
Copy link
Author

Any chance to have this merged? Thanks

@marcstern
Copy link
Author

Hello guys. Any reason to not review this one-line fix?
I implemented the test, so what's missing?

@martinhsv
Copy link
Contributor

martinhsv commented Apr 27, 2022

I don't have any concerns with the 1-line fix; I think we can proceed with that.

The only minor caveat I would draw attention to here is that, with this solution, there's no way to tell apart these request bodies (i.e. to ModSecurity they will be considered equivalent):

1

and

{ "" : 1 }

I don't think that's a serious impediment though.

The test, though, I don't think is quite right. For example, it passes even without the 1-line fix to msc_json.c

I'll either fix it up, or omit the test file for now. ( Anyway we probably want to include any such test in the pre-existing file .../rule/15-json.t )

@martinhsv
Copy link
Contributor

This change was committed via substitute pull request #2735

@martinhsv martinhsv closed this May 3, 2022
@marcstern marcstern deleted the v2/json_empty branch August 11, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Related to ModSecurity version 2.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants