Skip to content
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

Requester: Invalid JSON from dict references #648

Open
ppcad opened this issue Aug 15, 2024 · 2 comments
Open

Requester: Invalid JSON from dict references #648

ppcad opened this issue Aug 15, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@ppcad
Copy link
Collaborator

ppcad commented Aug 15, 2024

The requester can send JSON data and it is able to reference data from the event:

json:
    field: ${message}

This works as expected if message is a string.

However, the reference is not converted into valid JSON if the referenced data from the event is a dict:

json:
    field: ${some_dict}

some_dict = {"foo": "bar"} is converted to "{'foo': 'bar'}". This string can not be parsed to JSON without preprocessing it or using ast_eval.

Do you think this could be changed so that dict references are sent as valid JSON?

@ppcad ppcad added the enhancement New feature or request label Aug 15, 2024
@ekneg54 ekneg54 removed their assignment Dec 9, 2024
@ekneg54
Copy link
Collaborator

ekneg54 commented Jan 4, 2025

please have a look at https://github.com/fkie-cad/Logprep/pull/737/files#diff-207cfdd2f5456565a514652362fbe7aa6979e350e65170021d92499aadc6023eR280

does this solves the problem?`

if not. please provide a complete example what kind of feature you want to have in gherkin syntax to make things more clear.

@ppcad
Copy link
Collaborator Author

ppcad commented Jan 6, 2025

No it doesn't solve the problem.
The template replacement in the requester does not produce valid JSON.

Feature: Replace value with JSON via template

The requester doesn't properly replace values that contain JSON via template.

Scenario: Replace field in requester
Given a requester rule with the following configuration for the json parameter:

json:
    field: ${<Value>}

When running the processor with an event matching the rule
Then the result of the _template method is <Result>
Examples:
| Value | Result |
| {"foo": "bar"} | "{'foo': 'bar'}" |
| "foo_bar" | "foo_bar" |

The result "{'foo': 'bar'}" is then loaded as json (json.loads(<Result>)).
However, this is not valid JSON, so it fails.
The problem are the single quotes.
ast_eval is able to parse this as json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants