Skip to content
This repository has been archived by the owner on Aug 23, 2019. It is now read-only.

Commit

Permalink
fix: src/dst addrs validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dryajov authored and jacobheun committed Feb 15, 2019
1 parent 08d976a commit 68cccbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
27 changes: 24 additions & 3 deletions src/circuit/hop.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,36 @@ class Hop extends EE {
}

// This is a relay request - validate and create a circuit
const srcPeerId = PeerId.createFromBytes(message.dstPeer.id).toB58String()
if (srcPeerId === this.peerInfo.id.toB58String()) {
let srcPeerId = null
let dstPeerId = null
try {
srcPeerId = PeerId.createFromBytes(message.srcPeer.id).toB58String()
dstPeerId = PeerId.createFromBytes(message.dstPeer.id).toB58String()
} catch (err) {
log.err(err)

if (!srcPeerId) {
this.utils.writeResponse(
sh,
proto.Status.HOP_SRC_MULTIADDR_INVALID)
return sh.close()
}

if (!dstPeerId) {
this.utils.writeResponse(
sh,
proto.Status.HOP_DST_MULTIADDR_INVALID)
return sh.close()
}
}

if (srcPeerId === dstPeerId) {
this.utils.writeResponse(
sh,
proto.Status.HOP_CANT_RELAY_TO_SELF)
return sh.close()
}

const dstPeerId = PeerId.createFromBytes(message.dstPeer.id).toB58String()
if (!message.dstPeer.addrs.length) {
// TODO: use encapsulate here
const addr = multiaddr(`/p2p-circuit/ipfs/${dstPeerId}`).buffer
Expand Down
4 changes: 2 additions & 2 deletions test/hop.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ describe('relay', () => {
addrs: [multiaddr(`/ipfs/QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`).buffer]
},
dstPeer: {
id: PeerId.createFromB58String(`QmQvM2mpqkjyXWbTHSUidUAWN26GgdMphTh9iGDdjgVXCy`).id,
addrs: [multiaddr(`/ipfs/QmQvM2mpqkjyXWbTHSUidUAWN26GgdMphTh9iGDdjgVXCy`).buffer]
id: PeerId.createFromB58String(`QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`).id,
addrs: [multiaddr(`/ipfs/QmSswe1dCFRepmhjAMR5VfHeokGLcvVggkuDJm7RMfJSrE`).buffer]
}
}

Expand Down

0 comments on commit 68cccbe

Please sign in to comment.