libp2p / libp2p/js-libp2p

Non-strict Protocol Negotiation in js-libp2p's multistream-select

Open
#2,161 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

kind/bug
Dominant language
TypeScript
Stars
2.6k
Forks
546
Avg merge
8h 18m
Merged PRs (30d)
16

Description

- **Version**:
"js-libp2p":"js-libp2p-v0.46.14"
"@libp2p/multistream-select",:"4.0.3"

- **Platform**:
Ubuntu20.04

- **Subsystem**:
multistream-select

#### Severity:
Very Low

#### Description:
I find bug in the select function in multistream-select that does not strictly adhere to the libp2p specification for [Protocol Negotiation](https://github.com/libp2p/specs/blob/master/connections/README.md#protocol-negotiation).

As per the specification, if either side receives anything other than the multistream protocol id as the first message, they should abort the negotiation process. However, the implementation does not enforce this. The implementation https://github.com/libp2p/js-libp2p/blob/master/packages/multistream-select/src/select.ts#L86. If the first message does not contain the PROTOCOL_ID, it is ignored.

Additionally, according to the specification, if the protocol is not supported, the Responder should respond with the string "na" to indicate that the requested protocol is Not Available. The implementation https://github.com/libp2p/js-libp2p/blob/master/packages/multistream-select/src/select.ts#L104. If the current node does not support the received protocol, it directly closes the connection without notifying the remote peer with "na".

#### Steps to reproduce the error:
None

```[tasklist]
### Tasks
```

Contributor guide

Open the contributing guide

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 by reading packages/multistream-select/src/select.ts at the referenced lines and compare its negotiation behavior with the libp2p Protocol Negotiation specification. Verify that an unexpected first message aborts negotiation and that an unsupported protocol receives "na" before considering the work complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.