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

Filebeat input httpjson getRFC5988Link parsing failure #34603

Closed
sf-sharris opened this issue Feb 16, 2023 · 1 comment · Fixed by #34622
Closed

Filebeat input httpjson getRFC5988Link parsing failure #34603

sf-sharris opened this issue Feb 16, 2023 · 1 comment · Fixed by #34622
Assignees

Comments

@sf-sharris
Copy link

sf-sharris commented Feb 16, 2023

The getRFC5988Link value template function will fail to parse Link strings in which there is no whitespace between the link's elements. As far as I understand the spec, whitespace is not required and there is at least one vendor producing pagination links without any whitespace.

For confirmed bugs, please report:

  • Version: Filebeat 8.6.1 (x-pack) and prior versions
  • Operating System: Any
  • Discuss Forum URL:
  • Steps to Reproduce:

Alter an existing test case removing whitespace

$ git diff value_tpl_test.go
diff --git a/x-pack/filebeat/input/httpjson/value_tpl_test.go b/x-pack/filebeat/input/httpjson/value_tpl_test.go
index c5332a9658..b989e2128b 100644
--- a/x-pack/filebeat/input/httpjson/value_tpl_test.go
+++ b/x-pack/filebeat/input/httpjson/value_tpl_test.go
@@ -214,8 +214,8 @@ func TestValueTpl(t *testing.T) {
                                lastResponse: newTestResponse(
                                        nil,
                                        http.Header{"Link": []string{
-                                               `<https://example.com/api/v1/users?after=00ubfjQEMYBLRUWIEDKK>; title="Page 3"; rel="next"`,      
-                                               `<https://example.com/api/v1/users?before=00ubfjQEMYBLRUWIEDKK>; title="Page 1"; rel="previous"`, 
+                                               `<https://example.com/api/v1/users?after=00ubfjQEMYBLRUWIEDKK>;title="Page 3";rel="next"`,        
+                                               `<https://example.com/api/v1/users?before=00ubfjQEMYBLRUWIEDKK>;title="Page 1";rel="previous"`,   
                                        }},
                                        "",
                                ),

Run test cases

#/go/src/github.com/elastic/beats/x-pack/filebeat/input/httpjson# go test -v . -run TestValueTpl/func_getRFC5988Link_multiple_rel_as_separate_strings_matches
=== RUN   TestValueTpl
=== RUN   TestValueTpl/func_getRFC5988Link_multiple_rel_as_separate_strings_matches
    value_tpl_test.go:680:
                Error Trace:    /go/src/github.com/elastic/beats/x-pack/filebeat/input/httpjson/value_tpl_test.go:680
                Error:          Not equal:
                                expected: "https://example.com/api/v1/users?before=00ubfjQEMYBLRUWIEDKK"
                                actual  : ""

                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -https://example.com/api/v1/users?before=00ubfjQEMYBLRUWIEDKK
                                +
                Test:           TestValueTpl/func_getRFC5988Link_multiple_rel_as_separate_strings_matches
    value_tpl_test.go:682:
                Error Trace:    /go/src/github.com/elastic/beats/x-pack/filebeat/input/httpjson/value_tpl_test.go:682
                Error:          Received unexpected error:
                                the template result is empty
                Test:           TestValueTpl/func_getRFC5988Link_multiple_rel_as_separate_strings_matches
--- FAIL: TestValueTpl (0.00s)
    --- FAIL: TestValueTpl/func_getRFC5988Link_multiple_rel_as_separate_strings_matches (0.00s)
FAIL
FAIL    github.com/elastic/beats/v7/x-pack/filebeat/input/httpjson      0.008s
FAIL

Potential Fix

var regexpLinkRel = regexp.MustCompile(`<(.*)>;.*\srel\="?([^;"]*)`)

-var regexpLinkRel = regexp.MustCompile(`<(.*)>;.*\srel\="?([^;"]*)`)
+var regexpLinkRel = regexp.MustCompile(`<(.*)>;.*rel\="?([^;"]*)`)
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 16, 2023
@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Feb 20, 2023
@efd6 efd6 self-assigned this Feb 21, 2023
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 a pull request may close this issue.

4 participants