{"eip":7087,"title":"MIME type for Web3 URL in Auto Mode","description":"Add ability to indicate or determine the MIME type of the data returned by a Web3 URL in auto mode","authors":["Qi Zhou (@qizhou)","Nicolas Deschildre (@nand2)"],"status":"Draft","type":"Standards Track","category":"ERC","created":"2023-05-28","requires":[6860],"discussionsTo":"https://ethereum-magicians.org/t/erc-7087-mime-type-for-web3-url-in-auto-mode/14471","repo":"ERCs","label":"ERC-7087","officialUrl":"https://eips.ethereum.org/EIPS/eip-7087","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7087.md","url":"https://eips.huatuo.xyz/eip-7087/","tldr":{"en":"Draft extension to web3:// URLs that adds mime.* query parameters, so data returned by ordinary contracts in auto mode is served with the right Content-Type.","ja":"web3:// URL に mime.* クエリパラメーターを追加するドラフトの拡張。auto モードで通常のコントラクトが返すデータを、正しい Content-Type で配信できるようにする。","ko":"web3:// URL에 mime.* 쿼리 파라미터를 추가하는 초안 확장. auto 모드에서 일반 컨트랙트가 반환하는 데이터를 올바른 Content-Type으로 제공할 수 있게 한다.","zh":"web3:// URL 的草案扩展，增加 mime.* 查询参数，使普通合约在 auto 模式下返回的数据能以正确的 Content-Type 提供。"},"tags":["web3-url","mime","content-type","dapp","hosting"],"explainers":{"en":{"lang":"en","tldr":"Draft extension to web3:// URLs that adds mime.* query parameters, so data returned by ordinary contracts in auto mode is served with the right Content-Type.","tags":["web3-url","mime","content-type","dapp","hosting"],"related":[6860,4804,6944],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7087/","markdown":"## What problem does it solve?\n\n`web3://` URLs ([ERC-6860](/eip-6860/), the revision of [ERC-4804](/eip-4804/)) let a browser or gateway fetch data straight from a contract. In **auto mode**, which applies to any contract that doesn't declare otherwise, the URL path is turned into an ABI function call, e.g. `/tokenURI/100`.\n\nThe returned bytes come with no type information. A browser that doesn't know an SVG is an SVG, or that a string is JSON, may display it wrongly or not at all. Contracts written for `web3://` can advertise a type, but the vast majority of existing contracts (NFTs, on-chain art) were never designed for it. ERC-7087 lets the **URL** say what type the result is.\n\n## How it works\n\nThree new query parameters (the last one present wins):\n\n| Parameter | Effect |\n| --- | --- |\n| `mime.content=\u003ctype\u003e` | Use this MIME type (RFC 6838 syntax, URL-encoded, e.g. `image/svg%2Bxml`) as `Content-Type`. Invalid syntax is an error. |\n| `mime.type=\u003cext\u003e` | Derive the MIME type from a file extension such as `svg` or `png`. An unknown extension is an error. |\n| `mime.dataurl` | Treat the returned bytes as an RFC 2397 `data:` URL: decode it, serve the decoded body, and use the MIME type it declares. Unparseable data is an error. |\n\nRules of precedence:\n\n- No `mime.*` parameter → `Content-Type` is decided by ERC-6860 as before.\n- If the ERC-6860 `returns` parameter is present, `mime.*` is ignored.\n\nAdding parameters is safe because in auto mode the query string is not part of the calldata sent to the contract.\n\n## Sample code\n\nExample URLs from the spec:\n\n```text\n# Force SVG for a function returning raw SVG text\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.content=image/svg%2Bxml\n\n# Same, using a file extension\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.type=svg\n\n# tokenURI returns 'data:application/json,[\"xx\"]' -\u003e served as JSON body [\"xx\"]\nweb3://0xff9c1b15b16263c61d017ee9f65c50e4ae0113d7/tokenURI/100?mime.dataurl\n```\n\nHow a gateway might choose the header (TypeScript sketch):\n\n```ts\nfunction contentType(q: URLSearchParams, body: Uint8Array) {\n  if (q.has(\"returns\") || q.has(\"returnTypes\")) return { type: \"application/json\", body };\n  const keys = [...q.keys()].filter(k =\u003e k.startsWith(\"mime.\"));\n  const last = keys.at(-1);\n  if (last === \"mime.content\") return { type: q.get(last)!, body };\n  if (last === \"mime.type\") return { type: lookupByExtension(q.get(last)!), body };\n  if (last === \"mime.dataurl\") return decodeDataUrl(body); // { type, body }\n  return null; // fall back to ERC-6860 default handling\n}\n```\n\n## Things to know\n\n- **Status: Draft**, as is the underlying ERC-6860.\n- Major **XSS risk**: anyone who can influence a string a contract returns could craft a link with `mime.content=text/html` that runs their script under a trusted-looking web3 hostname, reading browser storage or triggering wallet prompts. The spec recommends discouraging auto-mode websites and documenting this vector.\n- Contracts that control their own output should signal the type themselves (manual mode, or the [ERC-6944](/eip-6944/) 5219 mode) rather than rely on URL parameters.\n"},"ja":{"lang":"ja","tldr":"web3:// URL に mime.* クエリパラメーターを追加するドラフトの拡張。auto モードで通常のコントラクトが返すデータを、正しい Content-Type で配信できるようにする。","tags":["web3-url","mime","content-type","dapp","hosting"],"related":[6860,4804,6944],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7087/","markdown":"## 何を解決するのか\n\n`web3://` URL（[ERC-4804](/eip-4804/) の改訂版である [ERC-6860](/eip-6860/)）により、ブラウザーやゲートウェイはコントラクトから直接データを取得できます。特に宣言のないあらゆるコントラクトに適用される **auto モード**では、URL のパスが ABI の関数呼び出しに変換されます（例: `/tokenURI/100`）。\n\n返されるバイト列には型情報がありません。SVG が SVG であること、文字列が JSON であることをブラウザーが知らなければ、誤って表示したり、まったく表示できなかったりします。`web3://` 向けに書かれたコントラクトは型を示すことができますが、既存のコントラクトの大半（NFT、オンチェーンアートなど）はそのように設計されていません。ERC-7087 は、結果の型を **URL** で指定できるようにします。\n\n## 仕組み\n\n新しいクエリパラメーターが 3 つあります（最後に指定したものが優先されます）。\n\n| パラメーター | 効果 |\n| --- | --- |\n| `mime.content=\u003ctype\u003e` | この MIME タイプ（RFC 6838 の構文、URL エンコード済み。例: `image/svg%2Bxml`）を `Content-Type` として使います。構文が不正な場合はエラーです。 |\n| `mime.type=\u003cext\u003e` | `svg` や `png` などのファイル拡張子から MIME タイプを決めます。未知の拡張子はエラーです。 |\n| `mime.dataurl` | 返されたバイト列を RFC 2397 の `data:` URL として扱います。デコードしてデコード後のボディを配信し、宣言されている MIME タイプを使います。解析できないデータはエラーです。 |\n\n優先順位のルール:\n\n- `mime.*` パラメーターがない → `Content-Type` はこれまでどおり ERC-6860 が決定します。\n- ERC-6860 の `returns` パラメーターがある場合、`mime.*` は無視されます。\n\nauto モードではクエリ文字列はコントラクトに送られる calldata に含まれないため、パラメーターを追加しても安全です。\n\n## サンプルコード\n\n仕様にある URL の例:\n\n```text\n# Force SVG for a function returning raw SVG text\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.content=image/svg%2Bxml\n\n# Same, using a file extension\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.type=svg\n\n# tokenURI returns 'data:application/json,[\"xx\"]' -\u003e served as JSON body [\"xx\"]\nweb3://0xff9c1b15b16263c61d017ee9f65c50e4ae0113d7/tokenURI/100?mime.dataurl\n```\n\nゲートウェイがヘッダーを選ぶ方法の例（TypeScript のスケッチ）:\n\n```ts\nfunction contentType(q: URLSearchParams, body: Uint8Array) {\n  if (q.has(\"returns\") || q.has(\"returnTypes\")) return { type: \"application/json\", body };\n  const keys = [...q.keys()].filter(k =\u003e k.startsWith(\"mime.\"));\n  const last = keys.at(-1);\n  if (last === \"mime.content\") return { type: q.get(last)!, body };\n  if (last === \"mime.type\") return { type: lookupByExtension(q.get(last)!), body };\n  if (last === \"mime.dataurl\") return decodeDataUrl(body); // { type, body }\n  return null; // fall back to ERC-6860 default handling\n}\n```\n\n## 知っておくべきこと\n\n- **ステータス: Draft。** 土台となる ERC-6860 も Draft です。\n- 重大な **XSS リスク**があります。コントラクトが返す文字列に影響を与えられる人は、`mime.content=text/html` を付けたリンクを作り、信頼できそうに見える web3 のホスト名の下で自分のスクリプトを実行させ、ブラウザーのストレージを読み取ったりウォレットのプロンプトを発生させたりできます。仕様は、auto モードのウェブサイトを推奨しないことと、この攻撃経路を文書化することを勧めています。\n- 自分の出力を制御するコントラクトは、URL パラメーターに頼るのではなく、型を自分で示すべきです（manual モード、または [ERC-6944](/eip-6944/) の 5219 モード）。\n"},"ko":{"lang":"ko","tldr":"web3:// URL에 mime.* 쿼리 파라미터를 추가하는 초안 확장. auto 모드에서 일반 컨트랙트가 반환하는 데이터를 올바른 Content-Type으로 제공할 수 있게 한다.","tags":["web3-url","mime","content-type","dapp","hosting"],"related":[6860,4804,6944],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7087/","markdown":"## 어떤 문제를 해결하나요?\n\n`web3://` URL([ERC-4804](/eip-4804/)의 개정판인 [ERC-6860](/eip-6860/))을 사용하면 브라우저나 게이트웨이가 컨트랙트에서 데이터를 바로 가져올 수 있습니다. 별도로 선언하지 않은 모든 컨트랙트에 적용되는 **auto 모드**에서는 URL 경로가 ABI 함수 호출로 바뀝니다(예: `/tokenURI/100`).\n\n반환되는 바이트에는 타입 정보가 없습니다. 브라우저가 SVG를 SVG로, 문자열을 JSON으로 알아보지 못하면 잘못 표시하거나 아예 표시하지 못할 수 있습니다. `web3://`용으로 작성된 컨트랙트는 타입을 알릴 수 있지만, 기존 컨트랙트(NFT, 온체인 아트)의 대다수는 그렇게 설계되지 않았습니다. ERC-7087은 결과의 타입을 **URL**이 알려 주게 합니다.\n\n## 어떻게 동작하나요?\n\n새 쿼리 파라미터가 세 개 있습니다(마지막에 나온 것이 적용됩니다).\n\n| 파라미터 | 효과 |\n| --- | --- |\n| `mime.content=\u003ctype\u003e` | 이 MIME 타입(RFC 6838 문법, URL 인코딩, 예: `image/svg%2Bxml`)을 `Content-Type`으로 사용합니다. 문법이 잘못되면 오류입니다. |\n| `mime.type=\u003cext\u003e` | `svg`나 `png` 같은 파일 확장자에서 MIME 타입을 도출합니다. 알 수 없는 확장자는 오류입니다. |\n| `mime.dataurl` | 반환된 바이트를 RFC 2397 `data:` URL로 취급합니다. 디코딩한 본문을 제공하고, 그 안에 선언된 MIME 타입을 사용합니다. 파싱할 수 없는 데이터는 오류입니다. |\n\n우선순위 규칙:\n\n- `mime.*` 파라미터가 없음 → `Content-Type`은 이전처럼 ERC-6860이 결정합니다.\n- ERC-6860의 `returns` 파라미터가 있으면 `mime.*`는 무시됩니다.\n\nauto 모드에서는 쿼리 문자열이 컨트랙트에 보내는 calldata에 포함되지 않기 때문에 파라미터를 추가해도 안전합니다.\n\n## 샘플 코드\n\n명세의 예시 URL:\n\n```text\n# Force SVG for a function returning raw SVG text\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.content=image/svg%2Bxml\n\n# Same, using a file extension\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.type=svg\n\n# tokenURI returns 'data:application/json,[\"xx\"]' -\u003e served as JSON body [\"xx\"]\nweb3://0xff9c1b15b16263c61d017ee9f65c50e4ae0113d7/tokenURI/100?mime.dataurl\n```\n\n게이트웨이가 헤더를 고르는 방법의 예(TypeScript 스케치):\n\n```ts\nfunction contentType(q: URLSearchParams, body: Uint8Array) {\n  if (q.has(\"returns\") || q.has(\"returnTypes\")) return { type: \"application/json\", body };\n  const keys = [...q.keys()].filter(k =\u003e k.startsWith(\"mime.\"));\n  const last = keys.at(-1);\n  if (last === \"mime.content\") return { type: q.get(last)!, body };\n  if (last === \"mime.type\") return { type: lookupByExtension(q.get(last)!), body };\n  if (last === \"mime.dataurl\") return decodeDataUrl(body); // { type, body }\n  return null; // fall back to ERC-6860 default handling\n}\n```\n\n## 알아둘 점\n\n- **상태: Draft.** 기반이 되는 ERC-6860도 Draft입니다.\n- 중대한 **XSS 위험**이 있습니다. 컨트랙트가 반환하는 문자열에 영향을 줄 수 있는 사람은 `mime.content=text/html`이 붙은 링크를 만들어, 신뢰할 만해 보이는 web3 호스트 이름 아래에서 자신의 스크립트를 실행하고 브라우저 스토리지를 읽거나 지갑 프롬프트를 띄울 수 있습니다. 명세는 auto 모드 웹사이트를 권장하지 않고 이 공격 경로를 문서화할 것을 권합니다.\n- 자신의 출력을 제어하는 컨트랙트는 URL 파라미터에 의존하지 말고 타입을 직접 알려야 합니다(manual 모드 또는 [ERC-6944](/eip-6944/)의 5219 모드).\n"},"zh":{"lang":"zh","tldr":"web3:// URL 的草案扩展，增加 mime.* 查询参数，使普通合约在 auto 模式下返回的数据能以正确的 Content-Type 提供。","tags":["web3-url","mime","content-type","dapp","hosting"],"related":[6860,4804,6944],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7087/","markdown":"## 它解决什么问题？\n\n`web3://` URL（[ERC-6860](/eip-6860/)，即 [ERC-4804](/eip-4804/) 的修订版）让浏览器或网关可以直接从合约获取数据。在 **auto 模式**下（适用于所有没有另行声明的合约），URL 路径会被转换成 ABI 函数调用，例如 `/tokenURI/100`。\n\n返回的字节不带任何类型信息。如果浏览器不知道某个 SVG 是 SVG，或某个字符串是 JSON，就可能显示错误或根本无法显示。为 `web3://` 编写的合约可以声明类型，但绝大多数现有合约（NFT、链上艺术）从未为此设计过。ERC-7087 让 **URL** 来说明结果的类型。\n\n## 它如何运作\n\n三个新的查询参数（以最后出现的为准）：\n\n| 参数 | 作用 |\n| --- | --- |\n| `mime.content=\u003ctype\u003e` | 使用该 MIME 类型（RFC 6838 语法，经 URL 编码，例如 `image/svg%2Bxml`）作为 `Content-Type`。语法无效则报错。 |\n| `mime.type=\u003cext\u003e` | 根据文件扩展名（如 `svg` 或 `png`）推导 MIME 类型。未知扩展名则报错。 |\n| `mime.dataurl` | 把返回的字节当作 RFC 2397 的 `data:` URL：解码后提供解码得到的内容，并使用其中声明的 MIME 类型。无法解析的数据则报错。 |\n\n优先级规则：\n\n- 没有 `mime.*` 参数 → `Content-Type` 仍由 ERC-6860 决定。\n- 如果存在 ERC-6860 的 `returns` 参数，则忽略 `mime.*`。\n\n添加参数是安全的，因为在 auto 模式下，查询字符串不属于发送给合约的 calldata。\n\n## 示例代码\n\n规范中的示例 URL：\n\n```text\n# Force SVG for a function returning raw SVG text\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.content=image/svg%2Bxml\n\n# Same, using a file extension\nweb3://0x91cf36c92feb5c11d3f5fe3e8b9e212f7472ec14/accessorizedImageOf/1289?mime.type=svg\n\n# tokenURI returns 'data:application/json,[\"xx\"]' -\u003e served as JSON body [\"xx\"]\nweb3://0xff9c1b15b16263c61d017ee9f65c50e4ae0113d7/tokenURI/100?mime.dataurl\n```\n\n网关可能如何选择响应头（TypeScript 示意）：\n\n```ts\nfunction contentType(q: URLSearchParams, body: Uint8Array) {\n  if (q.has(\"returns\") || q.has(\"returnTypes\")) return { type: \"application/json\", body };\n  const keys = [...q.keys()].filter(k =\u003e k.startsWith(\"mime.\"));\n  const last = keys.at(-1);\n  if (last === \"mime.content\") return { type: q.get(last)!, body };\n  if (last === \"mime.type\") return { type: lookupByExtension(q.get(last)!), body };\n  if (last === \"mime.dataurl\") return decodeDataUrl(body); // { type, body }\n  return null; // fall back to ERC-6860 default handling\n}\n```\n\n## 需要注意\n\n- **状态：Draft**，其所依赖的 ERC-6860 也是 Draft。\n- 存在重大的 **XSS 风险**：任何能影响合约所返回字符串的人，都可以构造带有 `mime.content=text/html` 的链接，在看起来可信的 web3 主机名下运行自己的脚本，读取浏览器存储或触发钱包提示。规范建议不鼓励使用 auto 模式的网站，并记录这一攻击途径。\n- 能控制自己输出的合约应当自行声明类型（manual 模式，或 [ERC-6944](/eip-6944/) 的 5219 模式），而不是依赖 URL 参数。\n"}}}
