Instantly share code, notes, and snippets.
Save mala/c2ef4b49e7d71490de22bd8e9c3f962f to your computer and use it in GitHub Desktop.
Disclosure of a vulnerability that allows the theft of visitors' email addresses using Medium's custom domain feature
Author: mala
- This article describes a vulnerability in a web service called Medium that allows you to steal visitors' e-mail addresses by using custom domain plan of Medium.
- This is done as my personal activity and is not related to my organization.
- I'm not a zero-day guy and this is simply the result of a failure of coordinated disclosure.
- This vulnerability has not been fixed as of the time this article is published (2023-07-13).
- I have notified Medium with sufficient time for disclosure, but have not received a response, and a reasonable period of time that would be required for a fix has passed, and I believe it is in the greater public interest to disclose this information.
- The purpose is to alert the public and to discuss this type of issue, not to suggest abuse.
- 2023-07-22 New applications for custom domains have been suspended (also mentioned in email reply from Medium)
- 2023-08-17 I confirm that the local part of the email address is masked except for the first two characters
Although Medium has implemented some mitigations, the issue has not been fully fixed and Medium's logged-in users are still at risk.
The email address is now masked, but the auto-login for the custom domain remains the same, and the visitor's Medium account can still be identified. As such, it is still possible to identify a visitor if the owner of a custom domain that has already been set up is malicious. Also, the domain part and the first two characters of the email address are not masked, so the full email address may be inferred or the mask may not work. eg:me@example.com
- Pay $5/month to Medium and subscribe to Medium Membership.
- Set up your own domain as a custom domain e.g.: Set medium.example.com as a custom domain on the Medium side, and specify the IP address of the Medium server in the A record in the DNS settings.
- Confirm that you can connect to your blog with the custom domain.
- Change the A record of medium.example.com to the IP address of your own server and set up a proxy server.
- The Proxy server will keep the request header from the client and the Host header of medium.example.com, and specify the IP address of the Medium server as upstream to relay the request.
- The Proxy server can steal the response content received by the visitor.
- When a visitor logs into medium.example.com, the response of the graphql endpoint includes the visitor's e-mail address and so on.
- Log out of Medium.
- Since it is not known in advance which sites are using Medium, and logging in to Medium may automatically log you in to custom domains, you cannot protect yourself unless you log out of Medium beforehand.
- Complain to Medium
- 2022-12-24 Reported tobugbounty@medium.com that a custom domain's graphql endpoint is returning emails, etc.
- 2022-12-30 Medium replies that they are not accepting any potential problems and that the DNS servers are under Medium's control.
- 2022-12-31 mala to Medium: reply that it is not a potential problem but a low-cost problem to collect emails from medium users and that the DNS servers can be changed by the domain owner at any time.
- 2023-01-02 mala to Medium: create and send demo and video
- 2023-01-17 mala to Medium: urged to reply. Medium replied saying they would let me know if they had any additional information.
- 2023-05-12 mala to Medium: informing them that if there are no effective fixes, mitigations, or user clarifications within a month, I will disclose them.
- 2023-06-12 Due date but no reply from Medium.
- I was busy.
- 2023-07-13 No reply from Medium, confirms that graphql endpoint on own domain continues to return responses including visitor's email address, discloses vulnerability
- 2023-07-18 Medium to mala: Received a notification that it was being treated as an invalid bug and they asked if it was possible to delete Tweets and this gist.
- 2023-07-19 Medium to mala: They says that test and fix will be completed in few days.
- 2023-07-19 I temporarily unpublished this gist (assuming it will be resolved in a few days)
- 2023-07-22 Medium to mala: They says that they has stopped accepting new custom domain and some solution will be rolled out soon.
- 2023-07-27 mala to Medium: I asked when "soon" and "few days"
- 2023-07-28 Medium to mala: They says investigation and fix in progress, will be deployed when ready
- 2023-08-15 I got $1500 from Medium
- 2023-08-17 I confirm that the local part of the email address is masked except for the first two characters. I published this gist again
文責: mala
前置き
- MediumというWebサービスで独自ドメインプランを利用することで訪問者のメールアドレスを窃取することができる脆弱性について解説します。
- 個人の活動として行っており所属組織とは関係ない。
- これはゼロデイではなく調整に失敗した結果です。
- この脆弱性は、この記事を公開する時点(2023-07-13)で修正されていません。
- 開示についてMedium社に十分な期限を設けて通知をしましたが返事がなく、修正に必要であろう妥当な期間も経過しており、開示することがより公共の利益にかなうと判断するものです。
- 注意喚起や、この種の問題についての議論を目的としており、悪用を教唆するものではありません。
- 2023-07-22 カスタムドメインの新規申し込みが停止されている (Mediumからのメール返信でも言及あり)
- 2023-08-17 メールアドレスのローカルパート部分が先頭2文字を除いてマスクされるようになっているのを確認する
Mediumはいくつかの緩和策を実施していますが、問題は完全に修正されておらず、Mediumのログインユーザーには引き続きリスクがあります。
メールアドレスがマスクされるようになりましたが、custom domainに対して自動ログインする部分は変わらず、訪問ユーザーのMediumアカウントを特定することはできます。そのため、既にセットアップ済みの custom domainのオーナーに悪意がある場合、訪問者を特定することが引き続き可能です。また、メールアドレスのドメイン部分と先頭2文字はマスクされないため、フルのメールアドレスが推定されたり、マスクが機能しないことがあります。 eg:me@example.com
- Mediumに月5ドルのお金を払ってMedium Membershipに加入する
- 自分の保有するドメインをcustom domainとして設定する 例: Medium側にcustom domainとして medium.example.com を設定し、DNSの設定で Aレコードに MediumのサーバーのIPアドレスを指定する
- custom domainで自分のブログに正常に接続できるのを確認する
- medium.example.com のAレコードを自前のサーバーのIPアドレスに変更してProxyサーバーを立てる。let's encryptなどで自前での証明書を取得する。
- Proxyサーバーはクライアントからのリクエストヘッダや medium.example.com のHostヘッダを維持したまま、MediumのサーバーのIPアドレスをupstreamとして指定して中継する。
- Proxyサーバーは訪問者が受け取る応答内容を窃取することができる。
- 訪問者が medium.example.com にログイン状態になると、graphqlエンドポイントの応答には訪問者のメールアドレス等も含まれている。
- Mediumからログアウトしておく。
- どのサイトがMediumを使っているのかは事前には分からないし、Mediumにログインしているとcustom domainに対しても自動でログインすることもあるため、予めMediumからログアウトしないと自衛することができない。
- Medium社に文句を言う
- 2022-12-24bugbounty@medium.com 宛に報告。custom domainのgraphqlエンドポイントでEmailなどを返しているといった内容。
- 2022-12-30 Mediumより返信 潜在的な問題は受け付けてないとかDNSサーバーはMediumの制御下にあるといった返事が来る
- 2022-12-31 malaからMedium: 潜在的な問題ではなく低コストでmediumユーザーのemailを収集できる問題であり、DNSサーバーはドメイン所有者がいつでも変更できると返信
- 2023-01-02 malaからMedium: デモと動画を作成して送りつける。
- 2023-01-17 malaからMedium: 返信を催促。その後、Mediumから用意したデモに対してアクセスがあったことも確認。Mediumからは追加情報があれば知らせると返信あり。
- 2023-05-12 malaからMedium: 一ヶ月以内に実効性のある修正、緩和策、またはユーザーへの説明がない場合は開示予定であると伝える。
- 2023-06-12 期日になるが返事がない
- 忙しかった
- 2023-07-13 返信がないこと、独自ドメインでのgraphqlエンドポイントで引き続き訪問者のメールアドレスも含むレスポンスを返していることを確認、脆弱性の開示
- 2023-07-18 Mediumからmala: 連絡が再開される。無効なバグとして取り扱われていたことの連絡と、Tweetとgistを削除できないかという打診を受ける
- 2023-07-19 Mediumからmala: few daysのうちにテストと修正が完了すると連絡を受ける。
- 2023-07-19 (few daysで解決する前提で) このgistを一時的に非公開にする
- 2023-07-22 Mediumからmala: カスタムドメイン機能の新規申し込みを停止したことと、何らかの解決を近いうち(soon)に展開予定と連絡を受ける
- 2023-07-27 malaからMedium: soonとか few daysって具体的にいつだよと質問
- 2023-07-28 Mediumからmala: 調査と修正は進行中であり、準備ができたら展開される
- 2023-08-15 Mediumから $1500 が届く
- 2023-08-17 メールアドレスのローカルパート部分が先頭2文字を除いてマスクされるようになっているのを確認する。gistを再度公開する
Hi, I'm a Japanese web engineer.
I found an authentication flaw in medium's custom domain feature a fewhours ago.
my medium account ishttps://medium.com/@bulkneetsI'm sorry, but I haven't used it much,so I'm not familiar with medium's features. If there is any mistake inmy understanding, please point it out.
Authors using medium's custom domain feature can read users' privateinformation.The ViewerQuery operation for graphql contains the viewer's email address.
The graphql response contains an email address registered for medium.I didn't intend to make my email address public.Also, email is not a visible item in other users' public profile information.
When you visit a medium that uses a custom domain, a request is sentto the graphql endpoint like below.
https://custom-domain-for-medium.example.com/_/graphql
payload like this
[{"operationName":"ViewerQuery","variables":{},"query":"queryViewerQuery {\n viewer {\n __typename\n id\n username\n name\nimageId\n mediumMemberAt\n hasPastMemberships\nisPartnerProgramEnrolled\n email\n unverifiedEmail\n createdAt\nisAuroraVisible\n isEligibleToViewNewResponses\nisMembershipTrialEligible\n isSuspended\nstyleEditorOnboardingVersionSeen\nallowEmailAddressSharingEditorWriter\n hasSubdomain\ndismissableFlags\n hasGroupGiftingEnabled\n twitterScreenName\ngeolocation {\n country\n __typename\n }\n atsQualifiedAt\npostSubscribeMembershipUpsellShownAt\n hightowerTermsAcceptedAt\nisEligibleToImportEmails\n }\n}\n"}]
response like this (my information)
[{"data": {"viewer": {"__typename": "User","id": "cc22fbe5f640","username": "bulkneets","name": "mala","imageId": "0*IQerQa9DDSVYufwh.png","mediumMemberAt": 0,"hasPastMemberships": false,"isPartnerProgramEnrolled": false,"email": "■■■■■■@ma.la","unverifiedEmail": "","createdAt": 1475845601586,"isAuroraVisible": true,"isEligibleToViewNewResponses": true,"isMembershipTrialEligible": true,"isSuspended": false,"styleEditorOnboardingVersionSeen": 0,"allowEmailAddressSharingEditorWriter": false,"hasSubdomain": false,"dismissableFlags": ["FIRST_USE_GLOBAL_NAV_TOOLTIP"],"hasGroupGiftingEnabled": false,"twitterScreenName": "bulkneets","geolocation": {"country": "JP","__typename": "Geolocation"},"atsQualifiedAt": 0,"postSubscribeMembershipUpsellShownAt": 0,"hightowerTermsAcceptedAt": null,"isEligibleToImportEmails": false}}}]
If you use a custom domain on medium, it will usually be processed bythe medium server, including the graphql endpoint.
However, the domain owner can change the A record at any time, soA medium author using a custom domain can steal the viewer's validauthentication cookie.
Also, users of custom domains may be able to read cookies through the proxy.For example, as far as I have checked, these domains seem to behosting medium via cloudflare.
... snip ...
If the author of the custom domain relays the request on the serverprepared by himself and sets it to display medium,the author can collect the viewer's profile and email address withoutbeing noticed by the viewer.
- Sessions issued for custom domains should not be able to see user's private information.
- Even if you restrict the acquisition of private information, if you do not completely remove the common header, the username of the viewer may still be collected from the author using the custom domain.
- Auto-login functionality for custom domains should have enough warnings and options to disable.
- Simply, it would be safer to disable auto-login for custom domains by default and only log in by explicit user action.
In 2020, I reported a similar vulnerability to a medium-like blogservice provided in Japan, and recently disclosed the report.
I received a comment that medium also has a similar custom domainfunction, so I investigated medium.This issue may be easy to discover or exploit.