kong icon indicating copy to clipboard operation
kong copied to clipboard

fix(plugins/request-size-limiting): Check the file size when the request body buffered to a temporary file

Open yankun-li-kong opened this issue 1 year ago • 0 comments

Summary

Firstly enable request-size-limiting plugin with below config

    plugins:
    - config:
        allowed_payload_size: 512
        require_content_length: false
        size_unit: kilobytes
      enabled: true
      name: request-size-limiting

When client send request without content-length and request body chunked with Transfer-Encoding, then kong.request.get_raw_body() become nil, and request-size-limiting plugin do not work anymore and return 200 directly.

Below curl command could trigger the error:

dd if=/dev/urandom of=1m.dat bs=1m count=1
curl -v --data-binary @1m.dat http://kong:8000/test -H "Content-Length:" -H "Transfer-Encoding: chunked"

This PR will check the file size when the request body buffered to a temporary file. Then request-size-limiting plugin still able to get the request body size and work as expected.

Checklist

  • [x] The Pull Request has tests
  • [x] A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • [ ] There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Issue reference

Fix #FTI-6034

yankun-li-kong avatar Jun 26 '24 09:06 yankun-li-kong