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

Error occurs on endpoints when tags parameter is empty #13591

Open
1 task done
hutchic opened this issue Aug 29, 2024 · 2 comments · May be fixed by #13723
Open
1 task done

Error occurs on endpoints when tags parameter is empty #13591

hutchic opened this issue Aug 29, 2024 · 2 comments · May be fixed by #13723
Assignees

Comments

@hutchic
Copy link
Contributor

hutchic commented Aug 29, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Kong version ($ kong version)

Kong 2.7.1

Current Behavior

Requests with ?tags= to the admin api results in a 500 error

curl -X GET 'http://localhost:8001/ca_certificates?tags='

Kong logs

  • stringx.lua:32: argument 1 expected a 'string', got a 'userdata'
2024/08/29 05:18:38 [error] 1335#0: *10353 [lua] api_helpers.lua:540: handle_error(): /usr/local/share/lua/5.1/lapis/application.lua:440: /usr/local/share/lua/5.1/pl/stringx.lua:32: argument 1 expected a 'string', got a 'userdata'
stack traceback:
   [C]: in function 'error'
   /usr/local/share/lua/5.1/pl/utils.lua:291: in function 'assert_arg'
   /usr/local/share/lua/5.1/pl/stringx.lua:32: in function 'assert_string'
   /usr/local/share/lua/5.1/pl/stringx.lua:194: in function 'split'
   /usr/local/share/lua/5.1/kong/api/endpoints.lua:166: in function 'extract_options'
   /usr/local/share/lua/5.1/kong/api/endpoints.lua:209: in function 'page_collection'
   /usr/local/share/lua/5.1/kong/api/endpoints.lua:319: in function 'fn'
   /usr/local/share/lua/5.1/kong/api/api_helpers.lua:311: in function </usr/local/share/lua/5.1/kong/api/api_helpers.lua:289>

stack traceback:
   [C]: in function 'error'
   /usr/local/share/lua/5.1/lapis/application.lua:440: in function 'handler'
   /usr/local/share/lua/5.1/lapis/application.lua:186: in function 'resolve'
   /usr/local/share/lua/5.1/lapis/application.lua:217: in function </usr/local/share/lua/5.1/lapis/application.lua:215>
   [C]: in function 'xpcall'
   /usr/local/share/lua/5.1/lapis/application.lua:215: in function 'dispatch'
   /usr/local/share/lua/5.1/lapis/nginx.lua:231: in function 'serve'
   /usr/local/share/lua/5.1/kong/init.lua:1867: in function 'admin_content'
   content_by_lua(nginx-kong.conf:333):2: in main chunk, client: 172.19.0.1, server: kong_admin, request: "GET /ca_certificates?tags= HTTP/1.1", host: "localhost:8001"
172.19.0.1 - - [29/Aug/2024:05:18:39 +0000] "GET /ca_certificates?tags= HTTP/1.1" 500 42 "-" "curl/7.81.0"

Expected Behavior

The API should return a valid response, such as an empty list of CA certificates or a relevant error message indicating that the tags parameter is required, if applicable. The system should handle empty tags gracefully without causing an internal server error.

Steps To Reproduce

run kong
run the curl curl -X GET 'http://localhost:8001/ca_certificates?tags='

Anything else?

No response

@chobits
Copy link
Contributor

chobits commented Sep 2, 2024

For kong master, I could still reproduce it:

xc ~ $ curl -X GET 'http://localhost:8001/ca_certificates?tags=1'
{"next":null,"data":[]}

xc ~ $ curl -X GET 'http://localhost:8001/ca_certificates?tags='
{"message":"An unexpected error occurred"}

xc ~ $ curl -X GET 'http://localhost:8001/ca_certificates'
{"next":null,"data":[]}xc ~ $

and it reported the runtime error in admin error log file:

2024/09/02 10:30:14 [error] 96780#0: *647 [lua] api_helpers.lua:541: handle_error(): ...l-bin/build/kong-dev/share/lua/5.1/lapis/application.lua:440:
 ...ng/bazel-bin/build/kong-dev/share/lua/5.1/pl/stringx.lua:32: 
     argument 1 expected a 'string', got a 'userdata'
stack traceback:
        [C]: in function 'error'
        ...kong/bazel-bin/build/kong-dev/share/lua/5.1/pl/utils.lua:291: in function 'assert_arg'
        ...ng/bazel-bin/build/kong-dev/share/lua/5.1/pl/stringx.lua:32: in function 'assert_string'
        ...ng/bazel-bin/build/kong-dev/share/lua/5.1/pl/stringx.lua:194: in function 'split'
        ./kong/api/endpoints.lua:167: in function 'extract_options'
        ./kong/api/endpoints.lua:210: in function 'page_collection'
        ./kong/api/endpoints.lua:320: in function 'fn'
        ./kong/api/api_helpers.lua:312: in function <./kong/api/api_helpers.lua:290>

@chobits chobits added the bug label Sep 2, 2024
@nowNick nowNick self-assigned this Sep 2, 2024
@nowNick
Copy link
Contributor

nowNick commented Sep 30, 2024

Internal ticket tracking code: KAG-5496

nowNick added a commit that referenced this issue Sep 30, 2024
Previously Admin API crashed when tags=''. This commit
treats tags='' as empty.

KAG-5496
Fix #13591
@nowNick nowNick linked a pull request Sep 30, 2024 that will close this issue
3 tasks
nowNick added a commit that referenced this issue Sep 30, 2024
Previously Admin API crashed when tags=''. This commit
treats tags='' as empty.

KAG-5496
Fix #13591
nowNick added a commit that referenced this issue Oct 1, 2024
When querying entities that have tags assigned a user can send
a request with `tags` parameter. Previously sending `tags=''`
(empty string or explicit nil) resulted in 500 error.
This commit changes that so that it returns 400 error as empty
explicit tags are not allowed

KAG-5496
Fix #13591
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants