Upgrade gun to 2.4.1 to fix security vulnerabilities#547
Open
arctarus wants to merge 1 commit into
Open
Conversation
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>
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.
Code changes
Gun 2.4 introduces
invalid_request_headers(enabled by default), which rejects any header whose value contains\ror\nbytes by raising an exception. This is a deliberate security measure to prevent HTTP header injection attacks.Two tests in
server_test.exsused:erlang.term_to_binary/1to encode a{pid, ref}pair and pass it as a raw gRPC metadata header value. Erlang's external term format is a binary serialisation that routinely produces bytes0x0D(\r) and0x0A(\n) as part of its encoding — for example, the PID and reference fields in the term contain embedded node information whose serialised bytes can include these values. Gun 2.4 now correctly rejects such headers, crashing the connection process.The fix encodes the binary term as Base64 before setting the header (producing a safe ASCII string), and decodes it on the server side before deserialising:
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).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