Upgrade gun to 2.4.1 to fix security vulnerabilities#547
Merged
Conversation
polvalente
approved these changes
Jun 30, 2026
Contributor
|
@arctarus can you handle the failing CI test? |
Gun 2.3 and 2.4 fix several security vulnerabilities present in 2.2: - Reject HTTP/1.1 101 responses when no upgrade was requested (protocol_error) - Restrict push promises to the original request's authority - Fix keepalive_tolerance with unrequested pings Gun 2.4 also introduces `invalid_request_headers` (enabled by default), which rejects header values containing CR/LF bytes to prevent header injection attacks. Updated tests to Base64-encode binary Erlang terms passed as header metadata, as raw term binaries can contain these bytes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
b7c68fe to
e095418
Compare
When Connection.disconnect/1 terminates with reason :normal, Erlang does not propagate the exit signal through links — only non-normal reasons do. DNSResolver was started with start_link inside the resolver's init callback, so the link pointed to the Connection process. After a normal disconnect, the worker kept running, continued calling resolve/1, and in tests hit Mox with no expectation defined. Fix DNS.shutdown/1 to explicitly stop the worker via GenServer.stop/1 wrapped in a try/catch to handle the :noproc race where the process dies between when shutdown is called and when stop is delivered. Update the Mox shutdown stubs in dns_resolver_test.exs to mirror the same behaviour so disconnect_and_wait/1 actually drains the worker before the test process exits and Mox clears its stubs. Scope the capture_log in the graceful-shutdown integration test to :error level: server_test.exs is async: true and can run concurrently with dns_resolver_test.exs (async: false); the DNS tests intentionally emit empty-address warnings during their own assertions, and those warnings were leaking into the capture_log window of the unrelated shutdown test. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
@polvalente I added a couple of more fixes for some tests that were failing. Do you mind review them? Thanks! |
sleipnir
approved these changes
Jun 30, 2026
Collaborator
|
Thank you @arctarus |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Gun 2.2 and 2.3 contain several security vulnerabilities that are addressed in 2.4. This PR upgrades the dependency from
~> 2.2.0to~> 2.4.0(resolved to 2.4.1).Security fixes in gun 2.3 and 2.4
protocol_errorconnection error, preventing unexpected protocol switches.keepalive_tolerancewith unrequested pings — Unrequested pings no longer incorrectly consume the keepalive tolerance, which could be exploited to keep connections alive unexpectedly.Gun 2.4 also updates Cowlib to 2.17.0, which includes its own security fixes.
Commit 1 — gun upgrade + header injection fix (
server_test.exs)Gun 2.4 introduces
invalid_request_headers(enabled by default), which raises an exception when a header value contains\ror\nbytes. This is a security measure against HTTP header injection.Two tests in
server_test.exspassed a raw Erlang binary term as a gRPC metadata header value:Erlang's external term format routinely produces bytes
0x0D(\r) and0x0A(\n) — PID and reference fields embed node information whose serialised form includes these values. Gun 2.4 rejects such headers, crashing theConnectionProcessGenServer before the request ever reaches the server.The fix Base64-encodes the value at the sending side and decodes it on the receiving side:
This also aligns with the gRPC spec, which requires binary metadata values to be Base64-encoded (and conventionally uses header names ending in
-binfor binary metadata).Commit 2 — orphaned
DNSResolverworker fix (production bug)Why the worker was leaking
In Erlang/OTP, when a linked process exits with reason
:normal, the exit signal is not propagated to the other end of the link — only non-normal reasons are.DNSResolveris started withstart_linkinside the resolver'sinitcallback, which runs inside theConnectionGenServer process, so the link points fromDNSResolvertoConnection. WhenConnection.disconnect/1stops the GenServer (reason::normal),DNSResolvernever receives a kill signal and keeps running indefinitely, continuing to callresolve/1on its timer.The previous
DNS.shutdown/1was a no-op (def shutdown(_state), do: :ok), so theConnectionhad no mechanism to explicitly stop the worker on disconnect either.dns.ex—shutdown/1now stops the workerConnection.handle_call({:disconnect, ...})callsresolver.shutdown(resolver_state)before stopping. Makingshutdown/1stop the worker here is the correct place to clean up, both in production and in tests:The
try/catchhandles the TOCTOU race: the worker could die between whenshutdown/1is called and whenGenServer.stop/1delivers its message.dns_resolver_test.exs— Mox shutdown stubs updatedThe tests use a
MockResolverwhoseshutdownstub was also a no-op. Sincedisconnect_and_wait/1relies on the resolver dying before returning, andGenServer.stopis now the mechanism, the stub must mirror the real implementation:Without this,
disconnect_and_wait/1would time out waiting for a worker that was never stopped, and the worker would fire one moreresolve/1cycle after the test process exited — hitting Mox with no expectation defined.server_test.exs—capture_logscoped to:errorserver_test.exsisasync: trueand runs concurrently withdns_resolver_test.exs(which isasync: false). The DNS tests intentionally drive the resolver into empty-address cycles and assert on the resulting warning — that warning is correct and expected within those tests. However,ExUnit.CaptureLogcaptures logs from all processes, so the warning was leaking into thecapture_logwindow of the unrelated"gracefully handles server shutdown disconnects"test, causingassert logs == ""to fail.Scoping the capture to
:errorlevel is the right fix: the intent of that assertion is to verify that a graceful server shutdown produces no errors, not that it produces zero log output from every process in the VM.Test plan
mix testpasses ingrpc(301 tests, 0 failures)mix testpasses ingrpc_core(94 tests, 0 failures)mix testpasses ingrpc_server(206 tests, 0 failures)🤖 Generated with Claude Code