fix: sanitize erc20 token metadata - #1480
Merged
Merged
Conversation
✅ Heimdall Review Status
|
phdargen
approved these changes
Sep 3, 2026
|
Review Error for phdargen @ 2026-09-03 16:00:47 UTC |
phdargen
approved these changes
Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_metadatahelper 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 addresscdp/swapUtils.ts,zeroX/utils.ts— arbitrary swap token addressesflaunch(buy/sell) — arbitrary permissionless-launched coin addresscompound/utils.ts,compound/utils.py,aave/utils.py— allowlisted asset addresses, fixed for defense-in-depthTests
Added Typescript and Python unit tests
Checklist
A couple of things to include in your PR for completeness: