Skip to content

fix: sanitize erc20 token metadata - #1480

Merged
phdargen merged 1 commit into
mainfrom
fix/sanitize-erc20-token-metadata
Sep 3, 2026
Merged

phdargen merged 1 commit into
mainfrom
fix/sanitize-erc20-token-metadata

Conversation

@CarsonRoscoe

@CarsonRoscoe CarsonRoscoe commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes indirect prompt injection via malicious ERC20 token metadata. Anyone can deploy an ERC20 contract with an arbitrary name()/symbol() string, and that string was being passed straight through into text returned to the agent; a malicious token could embed prompt-injection payloads (e.g. zero-width characters, bidi overrides, control characters) that get interpreted as part of the agent's context.

The fix adds a shared sanitizeOnchainMetadata / sanitize_onchain_metadata helper that strips unsafe Unicode categories (control, format/zero-width/ bidi-override, private-use, surrogate) and truncates to 50 characters. On a match, the value is sanitized and truncated silently rather than rejecting the call; this is metadata display, not something that should fail an otherwise-valid transaction.

Length-capping alone was considered and rejected: short injection payloads still fit under a length cap, and it doesn't address the underlying issue of untrusted bytes being treated as trusted context.

Applied at every call site where onchain name/symbol data flows into agent-facing text:

  • erc20 (TS + Python) — arbitrary token address
  • cdp/swapUtils.ts, zeroX/utils.ts — arbitrary swap token addresses
  • flaunch (buy/sell) — arbitrary permissionless-launched coin address
  • compound/utils.ts, compound/utils.py, aave/utils.py — allowlisted asset addresses, fixed for defense-in-depth

Tests

Added Typescript and Python unit tests

Checklist

A couple of things to include in your PR for completeness:

  • Added documentation to all relevant README.md files
  • Added a changelog entry

@cb-heimdall

cb-heimdall commented Sep 3, 2026 •

Copy link
Copy Markdown

✅ Heimdall Review Status

Requirement Status More Info
Reviews ✅ 1/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@github-actions github-actions Bot added documentation Improvements or additions to documentation action provider New action provider python typescript labels Sep 3, 2026
@cb-heimdall

Copy link
Copy Markdown

Review Error for phdargen @ 2026-09-03 16:00:47 UTC
User failed mfa authentication, see go/mfa-help

@phdargen
phdargen merged commit 2e6dbaf into main Sep 3, 2026
31 checks passed
@phdargen
phdargen deleted the fix/sanitize-erc20-token-metadata branch September 3, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action provider New action provider documentation Improvements or additions to documentation python typescript

Development

Successfully merging this pull request may close these issues.

3 participants