Skip to content

Commit b98307b

Browse files
sirtimidclaude
andcommitted
fix(evm-wallet-experiment): use node -e for COMMS_PARAMS and ENTROPY JSON construction
Replace ad-hoc shell string interpolation for COMMS_PARAMS (relay address, allowedWsHosts) and ENTROPY with node -e + env vars. The old pattern was vulnerable to JSON injection if RELAY_ADDR contained double-quote characters, and was inconsistent with the rest of the scripts' JSON construction discipline. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 19942b9 commit b98307b

2 files changed

Lines changed: 24 additions & 31 deletions

File tree

packages/evm-wallet-experiment/scripts/setup-away.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,21 +234,16 @@ if [[ -n "$RELAY_ADDR" ]]; then
234234
else
235235
info "Initializing remote comms (direct QUIC on port $QUIC_PORT)..."
236236
fi
237-
COMMS_PARAMS="{\"directListenAddresses\":[\"/ip4/0.0.0.0/udp/${QUIC_PORT}/quic-v1\"]"
238-
if [[ -n "$RELAY_ADDR" ]]; then
239-
COMMS_PARAMS="${COMMS_PARAMS},\"relays\":[\"${RELAY_ADDR}\"]"
240-
# Extract the relay host (IP or hostname) for the ws:// allowlist.
241-
# Plain ws:// to public IPs is denied by default; allowedWsHosts permits it.
242-
RELAY_HOST=$(echo "$RELAY_ADDR" | node -e "
243-
const addr = require('fs').readFileSync('/dev/stdin','utf8').trim();
244-
const m = addr.match(/\\/(?:ip4|ip6|dns4|dns6)\\/([^\\/]+)/);
245-
if (m) process.stdout.write(m[1]);
246-
")
247-
if [[ -n "$RELAY_HOST" ]]; then
248-
COMMS_PARAMS="${COMMS_PARAMS},\"allowedWsHosts\":[\"${RELAY_HOST}\"]"
249-
fi
250-
fi
251-
COMMS_PARAMS="${COMMS_PARAMS}}"
237+
COMMS_PARAMS=$(QUIC="$QUIC_PORT" RELAY="$RELAY_ADDR" node -e "
238+
const p = { directListenAddresses: ['/ip4/0.0.0.0/udp/' + process.env.QUIC + '/quic-v1'] };
239+
const relay = process.env.RELAY;
240+
if (relay) {
241+
p.relays = [relay];
242+
const m = relay.match(/\\/(?:ip4|ip6|dns4|dns6)\\/([^\\/]+)/);
243+
if (m) p.allowedWsHosts = [m[1]];
244+
}
245+
process.stdout.write(JSON.stringify(p));
246+
")
252247
daemon_exec initRemoteComms "$COMMS_PARAMS" >/dev/null
253248
ok "Remote comms initialized"
254249

@@ -415,7 +410,10 @@ info "Initializing throwaway keyring..."
415410
# is unavailable inside vats). The entropy is passed to the keyring vat which uses
416411
# it as the private key for the throwaway account.
417412
ENTROPY="0x$(node -e "process.stdout.write(require('crypto').randomBytes(32).toString('hex'))")"
418-
daemon_qm --quiet "$ROOT_KREF" initializeKeyring "[{\"type\":\"throwaway\",\"entropy\":\"$ENTROPY\"}]" >/dev/null
413+
INIT_ARGS=$(ENTROPY="$ENTROPY" node -e "
414+
process.stdout.write(JSON.stringify([{ type: 'throwaway', entropy: process.env.ENTROPY }]));
415+
")
416+
daemon_qm --quiet "$ROOT_KREF" initializeKeyring "$INIT_ARGS" >/dev/null
419417
ok "Throwaway keyring initialized"
420418

421419
info "Verifying accounts..."

packages/evm-wallet-experiment/scripts/setup-home.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -253,21 +253,16 @@ if [[ -n "$RELAY_ADDR" ]]; then
253253
else
254254
info "Initializing remote comms (direct QUIC on port $QUIC_PORT)..."
255255
fi
256-
COMMS_PARAMS="{\"directListenAddresses\":[\"/ip4/0.0.0.0/udp/${QUIC_PORT}/quic-v1\"]"
257-
if [[ -n "$RELAY_ADDR" ]]; then
258-
COMMS_PARAMS="${COMMS_PARAMS},\"relays\":[\"${RELAY_ADDR}\"]"
259-
# Extract the relay host (IP or hostname) for the ws:// allowlist.
260-
# Plain ws:// to public IPs is denied by default; allowedWsHosts permits it.
261-
RELAY_HOST=$(echo "$RELAY_ADDR" | node -e "
262-
const addr = require('fs').readFileSync('/dev/stdin','utf8').trim();
263-
const m = addr.match(/\\/(?:ip4|ip6|dns4|dns6)\\/([^\\/]+)/);
264-
if (m) process.stdout.write(m[1]);
265-
")
266-
if [[ -n "$RELAY_HOST" ]]; then
267-
COMMS_PARAMS="${COMMS_PARAMS},\"allowedWsHosts\":[\"${RELAY_HOST}\"]"
268-
fi
269-
fi
270-
COMMS_PARAMS="${COMMS_PARAMS}}"
256+
COMMS_PARAMS=$(QUIC="$QUIC_PORT" RELAY="$RELAY_ADDR" node -e "
257+
const p = { directListenAddresses: ['/ip4/0.0.0.0/udp/' + process.env.QUIC + '/quic-v1'] };
258+
const relay = process.env.RELAY;
259+
if (relay) {
260+
p.relays = [relay];
261+
const m = relay.match(/\\/(?:ip4|ip6|dns4|dns6)\\/([^\\/]+)/);
262+
if (m) p.allowedWsHosts = [m[1]];
263+
}
264+
process.stdout.write(JSON.stringify(p));
265+
")
271266
daemon_exec initRemoteComms "$COMMS_PARAMS" >/dev/null
272267
ok "Remote comms initialized"
273268

0 commit comments

Comments
 (0)