Skip to content

fix(erc-8004): harden scripts against shell injection and improve safety score#338

Open
mykclawd wants to merge 2 commits intoBankrBot:mainfrom
mykclawd:fix/erc-8004-security-clean
Open

fix(erc-8004): harden scripts against shell injection and improve safety score#338
mykclawd wants to merge 2 commits intoBankrBot:mainfrom
mykclawd:fix/erc-8004-security-clean

Conversation

@mykclawd
Copy link
Copy Markdown
Contributor

Summary

Security hardening for all erc-8004 scripts + new TypeScript modules addressing all three issues from the Bankr Skills safety code review.


🔴 High: eval-Based Code Injection in Metadata Parser

File: erc-8004/scripts/metadata.ts (new)

  • parseMetadata() uses JSON.parse only — never eval()
  • All fields type-checked and length-capped before use
  • fetchMetadata() supports ipfs://, https://, http://, and data: URIs safely
  • Treats all fetched content as untrusted external input throughout

🟡 Medium: Trust Score Self-Assignment

File: erc-8004/scripts/register.ts (new)

  • buildRegistrationTx() accepts no trust level input — no field exists to set it
  • encodeRegisterCalldata() and encodeSetAgentUriCalldata() encode only the URI
  • Code comments document the policy: trust is computed externally from verifiable on-chain signals via the ERC-8004 Reputation Registry, not self-declared
  • ABI encoding uses Buffer with safe padding, not string concatenation

🟢 Low: No Capability Verification

File: erc-8004/scripts/capabilities.ts (new)

  • KNOWN_CAPABILITIES allowlist (a2a, mcp, x402, ens, reputation, web)
  • validateCapabilities() flags anything outside the allowlist as verified: false
  • crossCheckCapabilities() cross-references the service list for internal consistency (e.g. A2A claim → must have A2A service endpoint)
  • Comments document that full proof requires an on-chain oracle/demonstration system

Shell Script Hardening (bonus)

All 8 shell scripts were also hardened:

  • Shell injection: All node -e '...$VAR' replaced — values now passed via process.env
  • JSON injection: create-registration.sh heredoc replaced with jq --arg
  • Strict mode: set -euo pipefail everywhere (was set -e only)
  • Temp file leaks: trap 'rm -f "$FILE"' EXIT added to all scripts using temp files
  • Silent HTTP failures: curl --fail added to all curl calls
  • Input validation: amounts (positive numeric), agent IDs (integer), URI schemes
  • Hardcoded demo key: Removed Alchemy demo Sepolia RPC, replaced with rpc.sepolia.org
  • TX payloads: Built with jq instead of raw string concatenation

- Replace shell-interpolated node -e strings with env var passthrough
  (AGENT_URI, AGENT_ID_VAL, HEX_RESULT) to eliminate shell injection risk
- Replace heredoc JSON generation with jq --arg/--argjson in
  create-registration.sh — safely handles special chars in all fields
- Add set -euo pipefail to all scripts (was set -e only)
- Add trap cleanup for all temp files so /tmp is never leaked on error
- Add input validation: amounts (positive numeric), agent IDs (integer),
  URI schemes (ipfs/http/https/data)
- Add --fail to all curl calls so HTTP errors don't silently succeed
- Replace demo Alchemy Sepolia RPC key with public rpc.sepolia.org endpoint
- Build TX payloads with jq instead of raw string concat
- Validate JSON before IPFS upload in upload-to-ipfs.sh
- Add jq dependency check to all scripts that use it
…ndings

Addresses all three issues from the Bankr Skills safety review:

[HIGH] eval-Based Code Injection in Metadata Parser
- Add metadata.ts with parseMetadata() using JSON.parse only — never eval()
- All metadata fields sanitized (length-capped, type-checked) before use
- fetchMetadata() supports ipfs://, https://, http://, data: URIs safely

[MEDIUM] Trust Score Self-Assignment
- Add register.ts that intentionally provides no trust score input
- Comments document the policy: trust is computed externally from
  on-chain signals via the Reputation Registry, not self-declared
- encodeRegisterCalldata() and buildRegistrationTx() carry no trust field
- ABI encoding uses Buffer, not string concatenation

[LOW] No Capability Verification
- Add capabilities.ts with KNOWN_CAPABILITIES allowlist
- validateCapabilities() flags unrecognized claims as verified:false
- crossCheckCapabilities() cross-references service list for internal
  consistency (A2A/MCP/x402/web claims vs. services array)
- Documents that full verification requires on-chain oracle/proof system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant