Skip to content

Fixed crashing when request body is not a JSON object #24

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

Merged

Conversation

edmocosta
Copy link
Contributor

@edmocosta edmocosta commented Dec 21, 2022

What does this PR do?

The JSON specification defines single values as valid JSON, it can be a string in double quotes, a number, true or false, or null. When the body is parsed, those values are transformed into their corresponding types. When those types aren't a Hash (aka JSON object), it breaks the LogStash::Event constructor, and Logstash crashes and exits.

After this PR, any request in which the body payload is a minimal JSON value, will be processed and an extra tag (_invalidjsonobject) will be added to the event:

LogStash::Event.new("message" => body, "tags" => "_invalidjsonobject")

Related issues

Closes #21

@edmocosta edmocosta force-pushed the fix/crashing-when-body-isnt-object branch from 3c0c46e to 5a9c8e4 Compare December 21, 2022 16:00
@edmocosta edmocosta changed the title Fixed crashing when request payload body is not a JSON object Fixed crashing when request body is not a JSON object Dec 21, 2022
@edmocosta edmocosta marked this pull request as ready for review December 21, 2022 16:32
@edmocosta edmocosta requested review from andsel and robbavey December 21, 2022 16:33
Copy link

@andsel andsel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


Tested with

curl -L -H "Content-Type: application/json" -XGET "http://localhost:5010" -d '1'

pipeline:

input {
  github {
    codec => "json"
    port => 5010
  }
}

output {
  stdout{}

@edmocosta edmocosta merged commit 0910a86 into logstash-plugins:main Dec 22, 2022
@edmocosta edmocosta deleted the fix/crashing-when-body-isnt-object branch December 22, 2022 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logstash Crashing Due to Error from GitHub Input
2 participants