SocketCluster / SocketCluster/scc-state

Bug: using FORWARDED_FOR_HEADER treats IP as IPv6

Open
#19 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
16
Forks
12
PR merge metrics
No merged PRs in 30d

Description

There seems to be a bug when using FORWARDED_FOR_HEADER.

I have scc-state behind a AWS ALB load balancer, which add "X-Forwarded-For" header to HTTP request to inform about the callers IP address. I added FORWARDED_FOR_HEADER="x-forwarded-for" to scc-state, and based on the logs from scc-state, it is reporting correctly the IP address of scc-worker and scc-broker processes connection to scc-state via the ALB.

But when scc-state calls getSCCBrokerClusterState, it will return an URI with brackets [] : https://github.com/SocketCluster/scc-state/blob/master/server.js#L79-L85, causing the workers to throw an parse error since ws://[10.150.34.147]:50020/socketcluster is not a valid URI.

It will only return a non-bracket (IPv4) URI if instanceIp is provided : https://github.com/SocketCluster/scc-state/blob/68b1b861d98cc8b3b995b47d23f07c85d9a8f2c6/server.js#L193

I'm not sure if this is considered a bug, but I expected scc-state to be able to detect what instanceIpFamily should be when using FORWARDED_FOR_HEADER.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in server.js around lines 79-85 and compare with the instanceIp handling around line 193. Trace how FORWARDED_FOR_HEADER affects the returned broker-cluster URI, then verify that an IPv4 address from the forwarded header is emitted without IPv6 brackets so workers can parse the resulting WebSocket URI.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript
Domain
backend, networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.