---
title: "ngx_mruby v2.7.8"
language: "en"
documentation_version: "3.x"
channel: "development"
release_context: null
source_revision: "2072a900b0d0eae8e61fafb06e4c0129bc43c245"
working_tree_clean: true
source_path: "docs/releases/v2.7.8.md"
source_sha256: "5f687d544d9919ad6e7ee7ef8f29ba3e089d0094473d59b0e693f55fa1de9a79"
source_at_revision: true
source_url: "https://github.com/matsumotory/ngx_mruby/blob/2072a900b0d0eae8e61fafb06e4c0129bc43c245/docs/releases/v2.7.8.md"
html_url: "https://ngx.mruby.org/releases/v2.7.8/"
markdown_url: "https://ngx.mruby.org/markdown/releases/v2.7.8.md"
last_updated: "2026-11-15"
---

# ngx_mruby v2.7.8

## Behavior changes: read before upgrading

### Nginx.redirect raises TypeError for a status code that is not an Integer, and add_listener for an :address that is not a String (#813)

Security advisory (the status code of `Nginx.redirect` to a URL): [GHSA-8j8w-mcp5-xp3h](https://github.com/matsumotory/ngx_mruby/security/advisories/GHSA-8j8w-mcp5-xp3h).

- Before: `Nginx.redirect` read its second argument, the status code of a redirect to a URL, as an Integer without checking its type. With a String or a Float, the response had the `Location` header and a status line with a number that is not a status code and no reason phrase. With `nil`, the client got no response, and the connection was closed. `Nginx::Server#add_listener` and `Nginx::Stream.add_listener` read the `:address` of their Hash as a String without checking its type. With a missing `:address`, `nil` or a value that is not a String, such as an Integer, nginx ended with a segmentation fault while it read the configuration, also with `nginx -t`.
- Now: for a redirect to a URL, `Nginx.redirect` raises `TypeError` (`String cannot be converted to Integer`, with the class of the value, or `nil cannot be converted to Integer`) when the status code is not an Integer. The exception ends the handler like any other exception of the script: a `rescue` in the script catches it, and otherwise ngx_mruby logs it and the request gets 500. No redirect is made and no `Location` header is set. An internal redirect has no status code and still ignores the second argument. `add_listener` raises `TypeError` (`Integer cannot be converted to String`, with the class of the value, or `nil cannot be converted to String` for a missing or `nil` `:address`). The exception reaches the code of `mruby_server_context_handler_code` or `mruby_stream_server_context_code`, and nginx stops reading the configuration: `nginx -t` fails and prints the exception after `mrb_run failed`.
- Why it changed:
  - The defect: these methods read an argument without checking its type, and a value of another type gave a response without a valid status, no response, or the end of the nginx process. For a redirect to a URL, a heap-allocated status code such as a String put a heap address of the worker process into the status line, which weakens ASLR; the advisory linked above has the details, and the `add_listener` check in this entry is operator-facing hardening from the same review that a client cannot reach. The Request setters, `Nginx::Async::HTTP.sub_request` and `Nginx::Headers_in/out#[]=` got the same check in 2.7.7, and `Nginx.redirect` checks its first argument since 2.7.6 (#775).
  - Why the old behavior could not be kept: a value that is not an Integer has no status code, and a value that is not a String has no address, so reading them that way has no defined result. Converting them would accept types that these methods did not accept before, which the 2.x line does not do.
  - What the documentation promised: [Nginx.redirect](https://github.com/matsumotory/ngx_mruby/blob/v2.7.7/docs/class_and_method/README.md#nginxredirecturl_or_internal_location-http_statusnginxhttp_moved_temporarily) in 2.7.7 named the second argument `http_status` with an Integer constant as its default, and said nothing about other values. [Nginx::Server#add_listener](https://github.com/matsumotory/ngx_mruby/blob/v2.7.7/docs/class_and_method/README.md#nginxserveradd_listenerhash) and [Nginx::Stream.add_listener](https://github.com/matsumotory/ngx_mruby/blob/v2.7.7/docs/class_and_method/README.md#nginxstreamadd_listener) showed a String `:address` in every example, and said nothing about other values.
- Affected: calls of `Nginx.redirect` to a URL with a second argument that is not an Integer, and calls of `Nginx::Server#add_listener` and `Nginx::Stream.add_listener` whose Hash has no `:address` or an `:address` that is not a String. An internal redirect, a status code that is an Integer and an `:address` that is a String behave as before.
- What to do: pass an Integer status code to `Nginx.redirect`, for example `Nginx::HTTP_MOVED_PERMANENTLY`, or leave it out for 302, and pass the `:address` of `add_listener` as a String, for example `port.to_s`. Code that passed other values did not work on 2.7.7 either.

### Nginx.redirect raises ArgumentError for a third argument (#813)

- Before: `Nginx.redirect` takes a URL or an internal location and an optional status code, but a call with three arguments raised no error. The format of the arguments that it gave mruby allowed three, and it passed two variables to receive them, so the format and the number of variables did not match, and the result of a call with three arguments was not defined. A call with four or more arguments raised `ArgumentError`, as it does now.
- Now: a call with three arguments raises `ArgumentError` (`wrong number of arguments (given 3, expected 1..2)`) before it does anything, for a URL and for an internal location. The exception ends the handler like any other exception of the script: a `rescue` in the script catches it, and otherwise ngx_mruby logs it and the request gets 500. No redirect is made.
- Why it changed:
  - The defect: the format of the arguments of `ngx_mrb_redirect` named three arguments, and the function passed two variables to receive them (#813).
  - Why the old behavior could not be kept: the result of a call with three arguments was not defined, so it could not be kept as it was. The method has no third argument to give a meaning to, and mruby raises `ArgumentError` when a method gets more arguments than it takes.
  - What the documentation promised: the heading of [Nginx.redirect](https://github.com/matsumotory/ngx_mruby/blob/v2.7.7/docs/class_and_method/README.md#nginxredirecturl_or_internal_location-http_statusnginxhttp_moved_temporarily) in 2.7.7 names two arguments, and the documentation said nothing about a third.
- Affected: calls of `Nginx.redirect` with three arguments.
- What to do: pass one or two arguments to `Nginx.redirect`: the URL or the internal location, and for a URL the status code if it is not 302.

## New features

None.

## Fixes

- `Nginx.redirect` to a URL checks that its status code is an Integer, and `Nginx::Server#add_listener` and `Nginx::Stream.add_listener` check that the `:address` is a String; a value of another type raises `TypeError`. Before, a status code of another type gave a response without a valid status or no response, and an `:address` of another type, or none, ended nginx while it read the configuration (#813)
- `Nginx.redirect` takes one or two arguments, and a third raises `ArgumentError`. Before, the format of its arguments did not match the number of variables that received them, and the result of a call with three arguments was not defined (#813)

## Build and test changes

- New test case: `test/t/cases/argument_types.rb`, with the server of `test/conf/conf.d/96-argument-types.conf` on port 18200 (#813)

## Upgrading

- No directive was added, renamed or removed. Rebuild the module with this
  release the way you built 2.7.7, and replace the binary or the dynamic
  module as usual.

Check these before upgrading. Each line is the "What to do" of its entry
above.

- Calls of `Nginx.redirect` to a URL with a status code that is not an
  Integer, and calls of `add_listener` without a String `:address`: pass an
  Integer status code, or leave it out for 302, and a String `:address`.
- Calls of `Nginx.redirect` with three arguments: pass one or two.
