コード日進月歩

しんくうの技術的な小話、メモ、つれづれ、など

W3Cのpotentially trustworthy URL (信頼できるかもしれないURL)の定義に関して調べる

CORS関連のフレーズを調べているときにW3Cでよく出てくる potentially trustworthy URL というフレーズについて調べる

定義

W3Cの「 Secure Contexts - 3.2. Is url potentially trustworthy?」曰く以下の通り

A potentially trustworthy URL is one which either inherits context from its creator (about:blank, about:srcdoc, data) or one whose origin is a potentially trustworthy origin. Given a URL record (url), the following algorithm returns "Potentially Trustworthy" or "Not Trustworthy" as appropriate:
1. If url is "about:blank" or "about:srcdoc", return "Potentially Trustworthy".
2. If url’s scheme is "data", return "Potentially Trustworthy".
3. Return the result of executing §3.1 Is origin potentially trustworthy? on url’s origin.

機械和訳ミックスすると以下のとおり

potentially trustworthy URLとは、作成者からコンテキストを継承しているもの(about:blank、about:srcdoc、data)、またはその起源が潜在的に信頼できる起源であるもののことです。URLレコード(url)が与えられると、以下のアルゴリズムにより、"Potentially Trustworthy" または"Not Potentially Trustworthy" に切り分けられます。
1. "about:blank" か "about:srcdoc" は 、"Potentially Trustworthy"
2. URLのschemaが"data"であれば "Potentially Trustworthy"
3. 1と2のいずれでもない場合はURLのオリジンを「 §3.1 Is origin potentially trustworthy?」で判断した結果に依存する

§3.1 Is origin potentially trustworthy? について

こちらはURLのorigin(URLのscheme,host,port番号のワンセットの組み合わせ)の信頼できるかもしれない判定のロジック。W3Cこちらに判断ロジックがある。こちらは"Potentially Trustworthy" か "Not Trustworthy" のいずれかが決まる。以下W3Cより意訳抜粋

  1. originが無効なオリジン(opaque origin)の場合は "Not Trustworthy"
  2. originが tuple origin であること
  3. originのschema が "https" or "wss" であれば "Potentially Trustworthy".
  4. originのhostがCIDR表記での127.0.0.0/8 または ::1/128の場合は "Potentially Trustworthy"
  5. Let 'localhost' be localhost. のルールに準拠している状態かつoriginのhostが localhostlocalhost.、あるいは末尾が .localhost.localhost. の場合は"Potentially Trustworthy"
  6. originのschema が "file" であれば "Potentially Trustworthy"
  7. originのschema が アプリケーションが問題としないものである場合(例:Chromechrome-extension: など)は "Potentially Trustworthy"
  8. origin が信頼できる originとして他の部分で設定されている場合、"Potentially Trustworthy"
  9. 1から8の条件で判断がつかないものは "Not Trustworthy"

上記を加味してざっくりと整理する「potentially trustworthy URL」とは

厳密な定義は上記のとおりだが、ざっと信頼して問題ないの判断ポイントとしては以下

  • localhostループバックアドレスabout:blank、などの特別な定義のURL
  • data , file のschemaではじまるURL
  • アプリケーション独自の定義済みschemaとして設定済みのURL
  • WebSocketの場合のschemewss のURL
  • httpsのURL

関連リンク