Skip to content

ngx.exit(415) during read() loop does *not* cleanly exit - binary data spewed in log files #52

@braider

Description

@braider
            local upname = nil
            while true do
                local typ, res, err = form:read()
-- bla bla do something
                
                if typ == "header" then
                    for k,v in pairs(res) do
                        local ext = string.match(v,'.+(%.7z.*)"') -- say we only want to permit files with this extension
                        if ext then
                            upname = ext
                        end
                    end
                end

               -- crude but we found our extension, if we didn't then 
                if not upname then
                    -- cleanup()
                    ngx.status = 415
                    ngx.exit(415) -- makes nginx dump binary fuzz into the error.log 
                end

-- sample bad output in error.log  after connnection RST issued

09:17:16 [info] 6461#6461: *511 client sent invalid method while readin                                                                 g client request line, client: 127.0.0.1, server: xxxxx, request: ▒▒"▒▒  ▒▒f

^^^ that kind of rubbish dumped in the error.log

HOWEVER - the Correct behaviour occurs if the file upload is small (<300-400k) - presumably all read into a single buffer.. by correct i mean the upload is terminated with a redirect to the configured error_page 415 /415.html and the content of the error page is duly served.

If the file is larger than that (500k+) ngx.exit(415) totally fails and spews bad output into error.log

What's going on here? Pipes not emptying properly? Request line disappearing? This is easily reproducible on the latest openresty+debian buster

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions