A gifted ens name with a crafted label injects persistent attacker controlled markdown into a victim s real telegram expiry alert notifications
The Telegram expiry-alert template inserts an ENS name into a legacy Markdown message without escaping, so a crafted label can close the code span and inject bold text and a clickable phishing link. An attacker can register such a label on-chain and gift the name token to a victim, who then receives the injected message from ENS's real bot.
- Disclosed after under an hour
92719 w a insight a gifted ens name with a crafted label injects persistent attacker controlled markdown into a victim s real telegram expiry alert notifications
Submitted on Sep 11th 2026 at 20:05:56 UTC by @legat for Audit Competition | ENS
- Report ID: #92719
- Report Type: Websites & Apps
- Report severity: Insight
- Target: https://github.com/immunefi-team/audit-comp-ens/tree/audit-comp-ready/workers
- Impacts:
- Injecting/modifying the static content on the target application without JavaScript (persistent), such as:
- HTML injection without JavaScript
- Replacing existing text with arbitrary text
- Arbitrary file uploads, etc.
Description
Summary
workers/api-worker/src/services/delivery/templates/telegram.ts builds the outbound text for the name-expiry Telegram notification by interpolating payload.name — an ENS name — directly into a template literal, with zero escaping, inside a message whose parse_mode is Telegram's legacy Markdown (V1):
const ownerText = payload.isOwner
? `Your domain \`${payload.name}\` will expire in *${daysLeft} days*.\n\nDon't forget to renew your domain!`
: `The domain \`${payload.name}\` you're watching will expire in *${daysLeft} days*.`
Nothing in the call chain from there to Telegram's sendMessage API — services/delivery/telegram.ts, services/telegram/utils.ts — escapes or sanitizes this string. Because legacy Markdown pairs each opening special character (`, *, [) with the next unescaped occurrence of the same character, an ENS label containing those characters lets an attacker close the template's own code span early and inject arbitrary bold text and a clickable link with attacker-chosen display text into a message the victim receives from ENS's own real Telegram bot chat.
The ENS on-chain registrar contracts enforce no ENSIP-15 / character-class validation on a label (only client UIs do), so an attacker can register an arbitrary raw-byte label directly on-chain, then gift the resulting ERC-1155 name token straight to a victim's wallet address — an ordinary safeTransferFrom that requires zero interaction or consent from the recipient. workers/api-worker's hourly expiry-discovery cron resolves the owned-notification recipient for a name via a raw address lookup (event-ingestion.ts's collectRecipientsForEvent) that never touches any Manager frontend validation code, so it is completely unaffected by the client-side character filters that gate other parts of the app (see "Root Cause" for why the alternative "victim favorites the name" path is dead and this gift/owner path is the one that actually fires). If the victim already has a verified Telegram channel and the shipped owned_name_expiry notification toggle enabled — a real, opt-in setting that the app's own post-registration onboarding screen defaults on for any user who has just registered or renewed a name of their own — the victim receives, with zero further action from anyone, a message in the same bot chat they already trust for legitimate ENS alerts, carrying attacker-controlled bold "official-looking" text and a phishing link with deceptive display text.
The same template also builds the message's inline-keyboard "Renew Now" button from the identical raw payload.name, so the resulting button url field contains the same backticks/asterisks/brackets/newlines as the message text. I confirmed from Telegram's own published server source (see Finding Description step 7) that this does not cause the whole sendMessage call to be rejected — Telegram's real URL validator only restricts the scheme and host of a button URL and silently percent-encodes control bytes/spaces in the path, so the message is delivered regardless; only the button's own destination becomes a non-functional, garbled URL, which does not weaken the primary text-injection finding.
I built a real, non-mocked, end-to-end proof of this exact mechanism (see "Proof of Concept"). It registers a crafted label directly against the real deployed V2 ETHRegistrar on a local Anvil fork of Sepolia (register() succeeded, tx 0x18b9f8d7dd43dce08fdee4b62fdae5ec04bb5d8a4a7ed48f37279cd0c92e6e1e), transfers the resulting name to a fresh victim address via a real ERC-1155 safeTransferFrom (tx 0xd6ebe988aee3362f263a4e88b00913e430e284efb1b4dd85f2b6b01d3e5254ed), seeds the real Postgres database with the victim's owned_name_expiry: true account state, and drives the real, unmodified runExpiryDiscoveryCron → handleEventIngestionQueue → handleTelegramQueue → deliverTelegramNotification → telegramTemplates['name-expiry'] → makeTelegramRequest call chain end to end. The real production code built and POSTed:
{
"chat_id": "918273645",
"parse_mode": "Markdown",
"text": "⚠️ *Domain Expiration Alert*\n\nYour domain `poc-tg-mdinj-1789154480`*🔒 ENS Security Alert:* Your wallet requires immediate re-verification\n\n[Verify your wallet now — official ENS](https://ens-domains-secure-verify.example/action)\n\n\n\n\n\n`.eth` will expire in *3 days*.\n\nDon't forget to renew your domain!"
}
which, under Telegram's own documented legacy Markdown parsing rules, renders as a bold fake security alert plus a clickable, attacker-labeled phishing link — inside the real ⚠️ *Domain Expiration Alert* header the victim already recognizes as legitimate.
Finding Description
Intended behavior
The name-expiry Telegram notification should present the ENS name a user owns or watches as inert, literal text. An attacker-chosen name should never be able to alter the notification's formatting, insert additional bold/link markup, or cause the message to display attacker-controlled call-to-action text or URLs. The only interactive element in the message should be the fixed "🔄 Renew Now" button the template itself defines.
Actual behavior
1. The vulnerable sink: payload.name interpolated raw into a parse_mode: 'Markdown' string
workers/api-worker/src/services/delivery/templates/telegram.ts#L28-L49 (telegramTemplates['name-expiry']):
'name-expiry': (payload) => {
const daysLeft = Math.ceil(
(payload.expiryDate - Date.now()) / (1000 * 60 * 60 * 24),
)
const ownerText = payload.isOwner
? `Your domain \`${payload.name}\` will expire in *${daysLeft} days*.\n\nDon't forget to renew your domain!`
: `The domain \`${payload.name}\` you're watching will expire in *${daysLeft} days*.`
return {
text: `⚠️ *Domain Expiration Alert*\n\n${ownerText}`,
parseMode: 'Markdown',
buttons: [[{ text: '🔄 Renew Now', url: `https://app.ens.domains/${payload.name}` }]],
}
},
payload.name is substituted with zero escaping between a literal backtick pair, in a string that is later sent with parse_mode: 'Markdown'. daysLeft is a computed number (not attacker-influenced); the button URL's https://app.ens.domains/ prefix is a fixed literal, but its path suffix is the same unescaped payload.name (addressed in step 7 below).
2. Nothing downstream escapes it before the real Telegram API call
workers/api-worker/src/services/delivery/telegram.ts#L23-L92 (deliverTelegramNotification) reads the stored payload straight from Postgres, calls the template, and forwards the result verbatim:
const message = template(
deliveryJob.notification.payload as AnyPersonalNotificationPayload,
) // L58-60
...
const result = yield* makeTelegramRequest(botToken, 'sendMessage', {
chat_id: deliveryJob.target,
text: message.text,
parse_mode: message.parseMode,
reply_markup: replyMarkup,
}) // L68-73
workers/api-worker/src/services/telegram/utils.ts#L33 and #L57-L92 (makeTelegramRequest) do nothing but JSON.stringify(body) and POST it to https://api.telegram.org/bot<token>/sendMessage. No escaping/sanitization step exists anywhere in this call chain.
3. How payload.name gets the malicious raw label with zero client-side gating: the gift/owner path, not the dead "favorite" path
The reachability argument in this report rests entirely on the owner branch, which resolves independently of any Manager frontend code:
workers/api-worker/src/queues/event-ingestion.ts#L75-L87 (collectRecipientsForEvent):
export function collectRecipientsForEvent(
event: ExpiryEvent,
ownerToUserId: Map<string, string>,
favoriteUsersByName: Map<string, Set<string>>,
): RecipientMap {
const recipients: RecipientMap = new Map()
if (event.owner) {
const ownerUserId = ownerToUserId.get(event.owner.toLowerCase())
if (ownerUserId) {
recipients.set(ownerUserId, 'owned')
}
}
...
ownerToUserId is built purely from a raw address lookup — event-ingestion.ts#L146-L157:
const owners = ownerAddresses.length > 0
? yield* intoDbResult(
db.query.users.findMany({
where: inArray(TABLE.users.address, ownerAddresses),
columns: { id: true, address: true },
}),
)
: []
and #L177-L179:
const ownerToUserId = new Map(
owners.map((owner) => [owner.address.toLowerCase(), owner.id]),
)
ownerAddresses itself comes from event.owner — #L124-L131 — which is populated by the expiry-discovery indexer client purely from an on-chain ownership fact reported by the ENS subgraph, at workers/api-worker/src/services/expiry-discovery/indexer.ts#L43-L55 (name/owner.id are bare v.string(), no length/character restriction) and indexer.ts#L135, and forwarded unmodified by workers/api-worker/src/services/expiry-discovery/index.ts#L35-L47 (buildExpiryEvents, owner: domain.owner at L44) and workers/api-worker/src/types/events/index.ts#L6-L13 (expiryEventSchema, again bare v.string()). At no point does this path invoke apps/manager's parseName/normalize() gates or any other client-side validator — it is a server-side, address-keyed lookup driven entirely by real on-chain ownership.
This matters because the other candidate entry point — a victim favoriting the malicious name through Manager's UI — is dead. apps/manager/src/features/register-v2/utils/name-parser.ts#L11 declares:
const INVALID_LABEL_CHARS = /[&*@#$%^()[\]{}|\\:;"'<>?,=+~`!]/
checked at name-parser.ts#L73-L75 — this blocklist covers every Markdown metacharacter this payload needs (`, *, [, ], (, )). Independently, apps/manager/src/features/profile/service/profileOwner.ts#L24 calls normalizeEthName, which wraps the real ENSIP-15 normalize() from viem/ens (apps/manager/src/features/profile/service/profileName.ts#L1,L14-L19) and returns null on the same malformed label. Both gates fire before the profile page (and its favorite button) can render, so a name containing the required breakout characters can never be favorited through any reachable Manager UI surface. The gift/owner path bypasses both gates entirely because it never runs any Manager frontend code — it is a raw DB address match fed by a raw on-chain ownership fact.
4. event.name is copied verbatim into the stored notification payload
notificationsToInsert.push({
user_id: userId,
kind: 'name-expiry',
payload: {
name: event.name,
expiryDate: event.expiryDate * 1000,
isOwner: watchReason === 'owned',
watchReason,
},
idempotency_key: idempotencyKey,
})
This row is inserted into Postgres and later read back verbatim by deliverTelegramNotification (step 2 above) and handed to the vulnerable template.
5. Delivery is real-time-gated only by a real, shipped, opt-in toggle — one the app itself nudges on
workers/api-worker/src/queues/event-ingestion.ts#L54-L66 (shouldCreateExternalDeliveries) gates the owned watch reason on settings.owned_name_expiry alone. The column defaults to false at the schema level (workers/api-worker/src/core/database/schema/notifications.ts#L143), but Manager's own post-registration onboarding screen sets it on by default: apps/manager/src/features/register-v2/workflow/registering/components/NotificationSettings.tsx#L23-L27 calls useNotificationPreferencesForm({ nameExpiryDefaultWhenUnset: true, ... }), and apps/manager/src/features/notifications/settings/preferences.tsx#L55-L63 uses that flag as the field's initial value:
ownedNameExpiry:
preferences.data?.settings?.ownedNameExpiry ??
nameExpiryDefaultWhenUnset,
The screen itself is titled "Never lose your name to expiry." (NotificationSettings.tsx#L33) and is shown to every user immediately after they register or renew a name of their own — i.e., owned_name_expiry: true is the app's own encouraged, shipped default for any active Manager user who has added a Telegram contact method, entirely independent of ever encountering an attacker's gifted name.
6. Telegram legacy Markdown (V1) parsing turns the injected label into live formatting and a live link
Per Telegram's Bot API documentation (https://core.telegram.org/bots/api#formatting-options, #markdown-style, fetched during this engagement): "To escape characters '_', '', '', '[' outside of an entity, prepend the character '\' before them"*; *"Escaping inside entities is not allowed, so entity must be closed first and reopened again"*; *"entities must not be nested"*. Unmatched entities make sendMessage` fail with a 400 error rather than silently neutralizing the payload — so the attacker must, and (holding full control of the entire label) trivially can, balance every opened primitive.
Given the label poc-tg-mdinj-<ts> + ` + *🔒 ENS Security Alert:* + free text + [Verify your wallet now — official ENS](https://ens-domains-secure-verify.example/action) + padding newlines + `, substituted into the owner-branch template, the real production code built exactly this outbound text (captured verbatim in evidence/04-captured-telegram-sendMessage-request.json of the PoC):
⚠️ *Domain Expiration Alert*
Your domain `poc-tg-mdinj-1789154480`*🔒 ENS Security Alert:* Your wallet requires immediate re-verification
[Verify your wallet now — official ENS](https://ens-domains-secure-verify.example/action)
`.eth` will expire in *3 days*.
Don't forget to renew your domain!
- the template's opening backtick pairs with the label's first embedded backtick →
poc-tg-mdinj-<ts>renders as an innocuous inline-code "domain chip"; *🔒 ENS Security Alert:*is now outside any code span → renders bold, fully attacker-controlled fake "official" alert text;[Verify your wallet now — official ENS](https://ens-domains-secure-verify.example/action)renders as a genuine clickable link with attacker-chosen display text, independent of its destination;- the label's own trailing backtick opens a fresh code span that closes cleanly against the template's own trailing backtick once
.ethis appended — an unambiguous, well-formed message, not a malformed one that Telegram would reject.
I independently re-parsed this exact captured string against a from-scratch reference implementation of the documented legacy-Markdown entity rules (not part of the production call chain — corroboration only; evidence/06-independent-markdown-v1-parse.json). It resolves to the claimed entities: a bold 🔒 ENS Security Alert: span, a text_link entity with text Verify your wallet now — official ENS and url https://ens-domains-secure-verify.example/action, and two small code spans — i.e., a victim reading this message in the real ENS bot chat sees:
⚠️ Domain Expiration Alert
Your domain poc-tg-mdinj-<ts> 🔒 ENS Security Alert: Your wallet requires immediate re-verification
Verify your wallet now — official ENS [clickable link → attacker URL]
.eth will expire in 3 days.
Don't forget to renew your domain!
with the genuine trailing template text pushed below the fold by the padding blank lines.
7. The same-payload button URL is malformed-looking but does NOT cause the message to be rejected — confirmed from Telegram's own published server source, not assumed
The template's buttons field (step 1) builds url: https://app.ens.domains/${payload.name} from the identical raw label, so the constructed button URL also contains backticks, asterisks, brackets, parentheses, spaces, newlines, and emoji. Telegram's real Bot API does reject some malformed inline-keyboard button URLs with a 400 BUTTON_URL_INVALID error that fails the entire sendMessage call — so whether the whole notification (not just the button) is actually delivered turns on exactly what that validator checks. I determined this from Telegram's own published, MIT/Boost-licensed server-side source (github.com/tdlib/td, commit d1085f9cebc5a62379991ae1652673954f229c1f), which implements the Bot API server this program's real target depends on, rather than assuming either outcome:
td/telegram/InlineKeyboardButton.cpp#L245-L261— for a plaininlineKeyboardButtonTypeUrl(exactly what this template builds — not a stricterlogin_url/web_appbutton), the button URL is validated byLinkManager::check_link(url)with nohttps_onlyoverride.td/telegram/LinkManager.cpp#L1926-L1993(check_link/check_link_impl) — for an ordinaryhttp(s)://URL, this callsHttpUrl::parse_urland then requires only that the parsed host contain a dot (host_.find('.') != npos).tdutils/td/utils/HttpUrl.cpp#L47-L193(parse_url) — the scheme (http/https) and the host are checked against a restrictive charset (check_url_part, L141-165), but everything after the host — the query/path, exactly where the attacker's entire label lands — goes through the loop at L122-140, which has no error path: any byte<= 0x20(control characters, including\n/\r, and the space character itself) is percent-encoded, and every other byte — including`,*,[,],(,), and raw UTF-8 emoji bytes>= 0x80— passes through completely unvalidated.td/telegram/misc.cpp#L76-L161(clean_input_string, the remaining checkInlineKeyboardButton.cppapplies to the result) fails only on malformed UTF-8; it otherwise just normalizes control characters and never rejects unusual-but-valid ones.
Because the button's host here is the fixed literal app.ens.domains (always a valid, dotted, alnum host) and the attacker's entire label lives in the path, this validation chain accepts the constructed button URL — Telegram's real server would silently percent-encode the control bytes/spaces in the path server-side and deliver the message, not reject it with BUTTON_URL_INVALID. I ported this exact decision logic (cited line-for-line above) into the PoC as an independent check (evidence/07-button-url-tdlib-validation.json) and additionally wired the PoC's Telegram-API stub to actually run it against every constructed button URL before deciding whether to simulate acceptance or a real 400 BUTTON_URL_INVALID response — for this payload it returns ACCEPTED, and the PoC's own real production sendMessage call receives a success response exactly as the real API would give it, confirmed rather than assumed:
{
"verdict": "ACCEPTED",
"rawButtonUrl": "https://app.ens.domains/poc-tg-mdinj-1789154480`*🔒 ENS Security Alert:* Your wallet requires immediate re-verification\n\n[Verify your wallet now — official ENS](https://ens-domains-secure-verify.example/action)\n\n\n\n\n\n`.eth",
"normalizedUrl": "https://app.ens.domains/poc-tg-mdinj-1789154480`*🔒%20ENS%20Security%20Alert:*%20Your%20wallet%20requires%20immediate%20re-verification%0A%0A[Verify%20your%20wallet%20now%20—%20official%20ENS](https://ens-domains-secure-verify.example/action)%0A%0A%0A%0A%0A%0A`.eth"
}
The button's own destination becomes a garbled, non-functional URL as a side effect (this was already noted as a low-impact secondary detail in the original triage, not a separate claim this report relies on) — but the message itself, including the primary text-injection payload, is delivered. This confirms the report's central claim ("the victim receives the message") holds under Telegram's real, documented validation behavior, not merely under this PoC's own assumptions.
Root Cause
The root cause is entirely first-party: templates/telegram.ts is code this program owns and authored, and it is the only place in the entire call chain that ever builds the outbound text string. Telegram is not misbehaving — it faithfully parses exactly the Markdown it is documented and expected to parse; the defect is that workers/api-worker hands it attacker-controlled, unescaped text inside a markup-interpreted field.
First-party vs. third-party adjudication. The only out-of-scope actions in this chain are (a) the attacker's label registration directly against the ENS registrar contracts, and (b) the ENS subgraph's report of the resulting on-chain ownership. Both are data-poisoning preconditions that happen first, not a later call an attacker or victim must make to complete the harm — every step that actually constructs and sends the malicious message (event-ingestion.ts → deliverTelegramNotification → makeTelegramRequest) is 100% first-party workers/api-worker code, running automatically, with no further action or call into any out-of-scope component required by anyone. This is the identical shape as the program's own already-confirmed "Portal V1 history trusts unauthenticated matching-log rows" root cause (an attacker-controlled on-chain action plus an out-of-scope indexer read, completed entirely by in-scope code that fails to validate before treating the result as trusted) — and, more directly, the gift-to-owner precondition itself ("register a name on-chain, then transfer it to a victim's wallet, bypassing all Manager-side client validation") is the exact same precondition shape as this program's four already-confirmed "gifted name" Manager-dashboard bugs (the CBOR/ABI decoder hang, the ZEN/coin-121 decoder hang, the primary-contacts quadratic dedup hang, and the unbounded profile-links rendering hang — all triggered by an attacker gifting a crafted name directly to a victim's address with zero interaction). Those four confirmed roots establish that this program already treats "attacker registers on-chain, then gifts the name to a victim, then in-scope first-party code processes it without adequate validation" as a legitimate, in-scope attack shape — not a scope violation. This finding is that exact shape, with the vulnerable first-party code living in workers/api-worker instead of apps/manager, and the "adequate validation" gap being unescaped Markdown interpolation instead of unbounded decoding work. workers/api-worker is listed in the program's scope on equal footing with apps/manager/apps/portal, and the only modification/composition this report relies on is entirely inside it.
Impact Explanation
This meets the High bucket's "persistent static-content injection without JS" element by element:
- Unauthorized: the attacker is never the victim's Manager account holder, never authenticates as the victim, and never needs the victim's cooperation. The victim's only action (adding a verified Telegram channel and leaving the app's own defaulted-on
owned_name_expirytoggle enabled) is an ordinary, unrelated, earlier step. - Persistent: the malicious content is not a one-off reflection. It is generated deterministically by the hourly
runExpiryDiscoveryCronfor as long as the name remains in the victim's on-chain custody and unexpired, and the underlyingnotificationsrow is durably stored in Postgres. - Without JS: the attack is pure abuse of a text/markup primitive (Markdown V1 entity parsing), not script injection or code execution.
- Replaces/augments trusted content with attacker-chosen content: the real
⚠️ *Domain Expiration Alert*header (outside attacker control) frames attacker-chosen bold "official" text and a deceptive clickable link, delivered inside the same bot conversation the victim already trusts for legitimate ENS alerts — functionally the bot-message equivalent of injecting persistent content into a page the victim trusts. This delivery is confirmed, not assumed: Finding Description step 7 shows from Telegram's own published server source that the malformed-looking button URL sharing the same payload does not cause the whole message to be rejected.
I evaluated and rejected Critical (no wrong-address/tx-detail in a connected-wallet flow, no NFT/fund theft, no code execution) and Medium (this is not reflected — it is deterministic, persistent, and reaches the victim automatically once, not on every visit like an open redirect, but through a durable stored row and a scheduled job, materially worse than a single-shot redirect).
Likelihood Explanation
The exploit requires only ordinary, unprivileged capabilities:
- register any available ENS label on-chain, choosing its raw bytes freely (no ENSIP-15 enforcement at the registrar level);
- call the standard ERC-1155
safeTransferFromto the victim's address (no recipient consent required for an EOA); and - wait for the program's own hourly expiry-discovery cron to run.
The victim needs no wallet connection, no click, and no awareness that anything happened — the only precondition on the victim's side is a Manager account with a verified Telegram channel and the shipped, commonly-defaulted-on owned_name_expiry setting, both ordinary product usage. The attack does not depend on admin, governance, oracle, indexer-operator, or third-party credential compromise, and it is fully deterministic once indexed
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the ENS name is placed unescaped into a message sent with Telegram's legacy Markdown parse mode, so label characters are interpreted as formatting rather than literal text.
Impact
A victim with a verified Telegram channel and the expiry toggle enabled receives a message in the genuine ENS bot chat containing attacker-controlled bold text and a phishing link; the malformed button URL does not block delivery.
What the attacker needed
Attacker can register a crafted label on-chain; victim owns the gifted name token; victim has a verified Telegram channel; expiry alerts toggle enabled (onboarding default)
The fix
The name should be escaped for legacy Markdown, or the message should use HTML parse mode with the name HTML-escaped, before being sent.
How it was found
- Register a crafted ENS label directly on-chain, bypassing client-side character filters.
- Transfer the resulting name token to the victim's wallet address with a standard ERC-1155 transfer.
- The expiry-discovery cron resolves the owner address to the victim's account and stores a name-expiry notification with the raw name.
- The delivery worker builds the Telegram message from the template and posts it with Markdown parse mode, delivering the injected formatting and link.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
ENS names are like usernames for crypto wallets, and some can contain special characters. Telegram messages can be formatted with symbols such as backticks and asterisks, so a name containing those symbols can break out of the intended formatting and add fake bold text or a link. The attacker registers such a name and sends it to the victim's wallet, and the victim's alert message then shows the attacker's content.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.