Skip to content

Commit

Permalink
fixup! feat(ibc): validate remoteAddr string before making outbound c…
Browse files Browse the repository at this point in the history
…onnection
  • Loading branch information
0xpatrickdev committed Apr 25, 2024
1 parent 6068f14 commit e36559e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 27 deletions.
6 changes: 1 addition & 5 deletions packages/network/src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,15 +497,11 @@ const preparePort = (zone, powers) => {
makeIncapable()
),
) {
const { revoked, localAddr, protocolImpl, protocolHandler } =
this.state;
const { revoked, localAddr, protocolImpl } = this.state;

!revoked || Fail`Port ${localAddr} is revoked`;
/** @type {Endpoint} */
const dst = harden(remotePort);
await E(
/** @type {Remote<Required<ProtocolHandler>>} */ (protocolHandler),
).validateRemoteAddr(dst);
return watch(
E(protocolImpl).outbound(this.facets.port, dst, connectionHandler),
this.facets.portConnectWatcher,
Expand Down
8 changes: 0 additions & 8 deletions packages/vats/src/ibc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
decodeRemoteIbcAddress,
encodeLocalIbcAddress,
encodeRemoteIbcAddress,
validateRemoteIbcAddress,
} from '../tools/ibc-utils.js';

/** @import {LocalIbcAddress, RemoteIbcAddress} from '../tools/ibc-utils.js' */
Expand Down Expand Up @@ -244,13 +243,6 @@ export const prepareIBCProtocol = (zone, powers) => {
this.state.lastPortID += 1n;
return `port-${this.state.lastPortID}`;
},
/**
* @param {string} remoteAddr
* @returns {Promise<boolean>}
*/
async validateRemoteAddr(remoteAddr) {
return validateRemoteIbcAddress(remoteAddr);
},
/** @type {Required<ProtocolHandler>['onBind']} */
async onBind(_port, localAddr) {
const { util } = this.facets;
Expand Down
14 changes: 0 additions & 14 deletions packages/vats/test/test-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,6 @@ test('network - ibc', async t => {

await testEcho();

const testInvalidRemoteAddr = async () => {
await E(p).addListener(makeIBCListener({ publisher }));
t.log('Connecting to a invalid remoteAddr throws');
await t.throwsAsync(
when(E(p).connect('/ibc-port/port-1/unordered/foo/f/f/f/f')),
{
message:
/must be '\(\/ibc-hop\/CONNECTION\)\*\/ibc-port\/PORT\/\(ordered\|unordered\)\/VERSION'/,
},
);
};

await testInvalidRemoteAddr();

const testIBCOutbound = async () => {
t.log('Connecting to a Remote Port');
const [hopName, portName, version] = ['connection-11', 'port-98', 'bar'];
Expand Down

0 comments on commit e36559e

Please sign in to comment.