Skip to content

Refactor IP address extraction using net.SplitHostPort#574

Open
danielllek wants to merge 3 commits intoethereum-optimism:mainfrom
danielllek:ipv6-fix
Open

Refactor IP address extraction using net.SplitHostPort#574
danielllek wants to merge 3 commits intoethereum-optimism:mainfrom
danielllek:ipv6-fix

Conversation

@danielllek
Copy link

@danielllek danielllek commented Mar 20, 2026

Description

It's necessary to add X-Forwarded-For header for any request to proxyd, but looking at the code it shouldn't be needed.

Failing request:

$ curl -X POST http://localhost:8080 \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
{"jsonrpc":"2.0","error":{"code":-32600,"message":"request does not include a remote IP"},"id":null}

Request with X-Forwarded-For header works:

$curl -X POST http://localhost:8080     -H "Content-Type: application/json" -H "X-Forwarded-For: 127.0.0.1"    -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
{"jsonrpc":"2.0","result":"0x178e8e3","id":1}

It seems that's caused by ipv6 stack enabled on my machine - ipv6 can't be parsed with simple strings.Split.

Changing it to net.SplitHostPort should fix the issue.

Tests

Built locally with the change and it works:

$ curl -X POST http://localhost:8080     -H "Content-Type: application/json"     -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
{"jsonrpc":"2.0","result":"0x178e987","id":1}

Additional context

Metadata

simple split is failing on ipv6, so before change had to always set X-Forwarded-For
@danielllek danielllek requested a review from a team as a code owner March 20, 2026 20:45
@danielllek danielllek requested a review from bitwiseguy March 20, 2026 20:45
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.84%. Comparing base (ed7003d) to head (b06fe46).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #574      +/-   ##
==========================================
+ Coverage   57.83%   57.84%   +0.01%     
==========================================
  Files          96       96              
  Lines       14501    14500       -1     
==========================================
+ Hits         8386     8387       +1     
+ Misses       5597     5596       -1     
+ Partials      518      517       -1     
Flag Coverage Δ
proxyd 71.30% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
proxyd/server.go 76.54% <100.00%> (-0.03%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants