Skip to content

v2.7.15

Latest

Choose a tag to compare

@matsumotory matsumotory released this 28 Nov 07:35
93b0fcf

Behavior changes: read before upgrading

An mruby body filter no longer runs a second time on the empty buffer at the end of a proxied response

  • Before: on a response from an upstream (proxy_pass, fastcgi_pass, uwsgi_pass, scgi_pass or memcached_pass), after an earlier phase handler left Nginx.rputs or Nginx.echo output in the module context and then declined, an mruby_output_body_filter(_code) ran a second time on the empty last buffer that the upstream sends after the body. A body filter whose output on an empty body is non-empty, such as one that prepends to or appends to f.body, produced bytes on that second run, and they were sent after the response, past its Content-Length.
  • Now: the body filter passes that trailing empty buffer on without running its code again, so no bytes are sent after the framed response.
  • Why it changed:
    • The defect: the bytes that a body filter whose output on an empty body is non-empty produced on the second run and that were sent past the response's Content-Length. On a connection that is kept alive, the client reads those bytes as the start of the next response on that connection; GHSA-5qjv-293c-64f8 has the details.
    • Why the old behavior could not be kept: the second run had no body to transform, so any bytes it produced could only follow a response that was already framed and sent.
    • What the documentation promised: docs/class_and_method/ did not describe the body filter running a second time, and docs/directives/ did not describe output after the response.
  • Affected: a location with mruby_output_body_filter(_code) whose output on an empty body is non-empty, served from an upstream whose Content-Length is known, with an earlier handler that leaves Nginx.rputs or Nginx.echo output and then returns a negative code the request declines past (in practice Nginx::DECLINED). A body filter that leaves an empty body empty, such as f.body = f.body.upcase, a static file, and a response sent chunked are unchanged.
  • What to do: nothing; rebuild the module with this release. A body filter that was guarded against an empty body (for example with unless f.body.empty?) can keep the guard or drop it.

更新前に確認する挙動の変更

proxyのレスポンスの最後の空のバッファで、mrubyのボディフィルタが2回目に走らなくなった

  • 変更前:upstream(proxy_pass、fastcgi_pass、uwsgi_pass、scgi_pass、memcached_pass)からのレスポンスで、前段のフェーズのハンドラがNginx.rputsかNginx.echoの出力をmodule contextに残してDECLINEDしたあと、mruby_output_body_filter(_code)が、upstreamがボディのあとに送る空のlast bufferに対して2回目に走っていました。空のボディへの出力が非空になるボディフィルタ、たとえばf.bodyに前置きや後置きをするものは、この2回目でバイトを作り、そのバイトがレスポンスのContent-Lengthを超えて送られていました。
  • 変更後:ボディフィルタは、この空のlast bufferをコードを走らせずに次へ渡します。枠付けされたレスポンスの後ろには何も送られません。
  • 変更の理由:
    • 不具合:空のボディへの出力が非空になるボディフィルタが2回目に作り、レスポンスのContent-Lengthを超えて送られていたバイトです。keepaliveの接続では、クライアントがこのバイトを、その接続の次のレスポンスの先頭として読みます。詳細はGHSA-5qjv-293c-64f8にあります。
    • 前の挙動を残せなかった理由:2回目には変換するボディが無いので、作られたバイトは、すでに枠付けして送ったレスポンスの後ろに続くしかありませんでした。
    • ドキュメントが示していた挙動:docs/class_and_method/は、ボディフィルタが2回目に走ることを書いていません。docs/directives/も、レスポンスの後ろに出力が出ることを書いていません。
  • 影響の範囲:mruby_output_body_filter(_code)で空のボディへの出力が非空になるものがあり、Content-Lengthの分かるupstreamから配信され、前段のハンドラがNginx.rputsかNginx.echoの出力を残して、リクエストがdeclineして通り過ぎる負のコード(実際にはNginx::DECLINED)を返す場合です。空のボディを空のまま返すボディフィルタ(たとえばf.body = f.body.upcase)、静的ファイル、chunkedで送るレスポンスは変わりません。
  • 必要な対応:ありません。このリリースでモジュールをビルドし直してください。空のボディをガードしていたボディフィルタ(たとえばunless f.body.empty?)は、ガードを残しても外してもかまいません。