p0pr0ck5 / lua-resty-waf

High-performance WAF built on the OpenResty stack
GNU General Public License v3.0
1.28k stars 305 forks source link

Streaming multipart/form-data request body via http v2 not supported yet #166

Open eleshar opened 8 years ago

eleshar commented 8 years ago

Hi,

I'm currently running lua-resty waf on openresty-1.9.15.1 in SIMULATE mode - seeing the following error in my logs (Results in Internal Server Error on front-end).

[error] 16877#0: *1313321 lua entry thread aborted: runtime error: /etc/nginx/lualib/lua-resty-waf/inc/resty/upload.lua:60: http v2 not supported yet
stack traceback:
coroutine 0:
        [C]: in function 'req_socket'
        /etc/nginx/lualib/lua-resty-waf/inc/resty/upload.lua:60: in function 'new'
        /etc/nginx/lualib/lua-resty-waf/lib/request.lua:40: in function 'parse_request_body'
        /etc/nginx/lualib/lua-resty-waf/lib/lookup.lua:23: in function </etc/nginx/lualib/lua-resty-waf/lib/lookup.lua:18>
        /etc/nginx/lualib/lua-resty-waf/waf.lua:419: in function 'exec'
        access_by_lua(lua-waf-body.conf:5):4: in function <access_by_lua(lua-waf-body.conf:5):1>

Any ETA on HTTP/2 support?

p0pr0ck5 commented 8 years ago

Hi,

This is a limitation of the ngx lua API. See https://github.com/openresty/lua-nginx-module/issues/566 and https://groups.google.com/forum/#!topic/openresty-en/vhHYcoCmRxA. So any ETA is going to be reliant on upstream :)

As a workaround for now you can disable multipart upload parsing: https://github.com/p0pr0ck5/lua-resty-waf#process_multipart_body. Other functionality like query string args, URL-encoded for request bodies, and response data should be unaffected (let me know otherwise if they are).

I'll leave this ticket as a placeholder until http2 support is available via lua-nginx-module, so we don't get the same requests multiple times. Thanks!

p0pr0ck5 commented 8 years ago

Renaming the title of this issue for clarification.

p0pr0ck5 commented 8 years ago

Noting here for posterity, this links more closely to https://github.com/openresty/lua-resty-upload/issues/24 than other issues note above, as we leverage this library directly.

chaigon commented 7 years ago

The issue has been resolved?

p0pr0ck5 commented 7 years ago

Unless lua-resty-upload has started supporting HTTP/2, then no ;)

sjnam commented 7 years ago

I use proxy_pass to use lua-resty-upload in http2. :-)

$ curl -F "file=@sample.txt" https://localhost:8443/upload --http2 --insecure
http {

    server {
        listen        8088;
        location /upload {
            content_by_lua '
                local upload = require "resty.upload"
                local cjson = require "cjson"

                local chunk_size = 5 -- should be set to 4096 or 8192
                                     -- for real-world settings

                local form, err = upload:new(chunk_size)
                if not form then
                    ngx.log(ngx.ERR, "failed to new upload: ", err)
                    ngx.exit(500)
                end

                form:set_timeout(1000) -- 1 sec

                while true do
                    local typ, res, err = form:read()
                    if not typ then
                        ngx.say("failed to read: ", err)
                        return
                    end

                    ngx.say("read: ", cjson.encode({typ, res}))

                    if typ == "eof" then
                        break
                    end
                end

                local typ, res, err = form:read()
                ngx.say("read: ", cjson.encode({typ, res}))
            ';
        }
    }

    server {
        listen          8443 ssl http2 default_server;
        server_name     foo.com;
        ssl_certificate          server.crt;
        ssl_certificate_key  server.key;

        location / {
            proxy_pass               http://backend;
            proxy_request_buffering  off;
            proxy_set_header Host   $host;
            proxy_set_header         X-Real-IP $remote_addr;
            proxy_http_version       1.1;
            proxy_set_header         Connection "";
        }
    }

    upstream backend {
        server localhost:8088;
        keepalive 128;
    }
}