Skip to content

v2.7.14

Latest

Choose a tag to compare

@matsumotory matsumotory released this 25 Nov 18:33
cde3fac

Behavior changes: read before upgrading

A Content-Length set through Nginx::Headers_out is no longer sent as a response header line

  • Before: Nginx::Headers_out#[]= with the name Content-Length added a Content-Length response header line next to the one that nginx writes from the length of the response body, so a response could carry two Content-Length lines with different values.
  • Now: a Content-Length that a script sets through Nginx::Headers_out is not sent; nginx sends its own Content-Length for the response, as it does when the script sets none.
  • Why it changed:
    • The defect: the second Content-Length line that a script's value added next to the one nginx writes. A response with two differing Content-Length lines has no single body length. On a response that nginx sends with Transfer-Encoding: chunked, the script's line was added next to the Transfer-Encoding, which leaves no single body length either; GHSA-2cf7-qh69-j29q has the details.
    • Why the old behavior could not be kept: the line a script set could not be made to agree with the body in every case, so the fix sends only the length that nginx frames the body by.
    • What the documentation promised: docs/class_and_method/ on the 2.x line did not describe setting Content-Length through Nginx::Headers_out.
  • Affected: a configuration whose Ruby code sets Content-Length through Nginx::Headers_out in a content handler, a phase handler or an output header filter. Reading Content-Length with Nginx::Headers_out#[] and removing it with #delete are unchanged.
  • What to do: remove the Nginx::Headers_out#[]= of Content-Length; nginx sends the length of the response. A response of a fixed length is sent by writing that many bytes with Nginx.rputs, whose total nginx sends as the Content-Length.

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

Nginx::Headers_outで設定したContent-Lengthを、応答のヘッダ行として送らなくなりました

  • 変更前:Nginx::Headers_out#[]=のキーにContent-Lengthを指定すると、nginxが応答の本文の長さをもとに出力するContent-Lengthとは別に、もう1つのContent-Lengthの行が応答に追加されていました。そのため、値の異なる2つのContent-Lengthの行を持つ応答になることがありました。
  • 変更後:Nginx::Headers_outで設定したContent-Lengthは送られなくなりました。スクリプトが設定しないときと同じく、nginx自身が応答のContent-Lengthを出力します。
  • 変更の理由:
    • 不具合:Nginx::Headers_outで設定したContent-Lengthが、nginxが出力する行とは別に、2つ目のContent-Lengthの行として追加されていました。値の違う2つのContent-Lengthの行を持つ応答は、本文の長さが1つに定まりません。nginxがTransfer-Encoding: chunkedで送る応答では、スクリプトの行がTransfer-Encodingと並んで追加され、この場合も本文の長さが1つに定まりませんでした。詳細はGHSA-2cf7-qh69-j29qにあります。
    • 前の挙動を残せなかった理由:スクリプトが設定した行を、常に本文と一致させることはできないため、nginxが本文を区切るのに使う長さだけを送ります。
    • ドキュメントが示していた挙動:2.x系のdocs/class_and_method/は、Nginx::Headers_outでContent-Lengthを設定したときの動作を説明していませんでした。
  • 影響の範囲:content handler、フェーズのハンドラ、output header filterのいずれかで、RubyのコードがNginx::Headers_outを通じてContent-Lengthを設定している構成。Nginx::Headers_out#[]によるContent-Lengthの読み取りと、#deleteによる削除は変わりません。
  • 必要な対応:スクリプトから、Content-LengthへのNginx::Headers_out#[]=による代入を削除してください。nginxが応答の長さを出力します。固定長の応答を返すには、その長さのバイト列をNginx.rputsで出力すれば、その合計をnginxがContent-Lengthとして送ります。