跳到主要内容

4. URI 的 Origin (Origin of a URI)

4. URI 的 Origin (Origin of a URI)

URI 的 origin 是通过以下算法计算得到的值:

  1. 如果 URI 不使用 hierarchical element 作为 naming authority (见 [RFC3986], Section 3.2), 或者 URI 不是 absolute URI, 则生成一个新的 globally unique identifier 并返回该值.

    NOTE: 对同一 URI 多次运行该算法可能每次产生不同值. 通常, user agents 会对例如 HTML document 的 origin 计算一次, 并在后续 security checks 中使用该 origin, 而不是为每次 security check 重新计算 origin.

  2. uri-scheme 为 URI 的 scheme component, 并转换为 lowercase.

  3. 如果 implementation 不支持 uri-scheme 给出的 protocol, 则生成一个新的 globally unique identifier 并返回该值.

  4. 如果 uri-scheme 是 "file", implementation MAY 返回 implementation-defined value.

    NOTE: 从历史上看, user agents 曾授予来自 file scheme 的 content 大量 privilege. 然而, 授予所有 local files 如此广泛的 privileges 可能导致 privilege escalation attacks. 一些 user agents 通过向 local files 授予 directory-based privileges 取得了成功, 但这种方法尚未被广泛采用. 其他 user agents 为每个 file URI 使用 globally unique identifiers, 这是最安全的选项.

  5. uri-host 为 URI 的 host component, 并转换为 lower case (使用 [RFC4790] 中定义的 i;ascii-casemap collation).

    NOTE: 本文档假定 user agent 在构造 URI 时执行 Internationalizing Domain Names in Applications (IDNA) processing 和 validation. 特别是, 本文档假定 uri-host 只包含 LDH labels, 因为 user agent 已经将任何 non-ASCII labels 转换为其对应的 A-labels (见 [RFC5890]). 因此, origin-based security policies 对 user agent 采用的 IDNA algorithm 很敏感. 进一步讨论见 Section 8.4.

  6. 如果 URI 没有 port component:

    1. uri-porturi-scheme 给出的 protocol 的 default port.

    否则:

    1. uri-port 为 URI 的 port component.
  7. 返回 triple (uri-scheme, uri-host, uri-port).