Skip to content

Navigation fetch always uses document destination #11306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jdm opened this issue May 15, 2025 · 12 comments · Fixed by #11318
Closed

Navigation fetch always uses document destination #11306

jdm opened this issue May 15, 2025 · 12 comments · Fixed by #11318
Labels
clarification Standard could be clearer

Comments

@jdm
Copy link
Member

jdm commented May 15, 2025

What is the issue with the HTML Standard?

https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching is the only time a request is created for navigation that I can see. It always uses the "document" destination for the request, even if the navigation occurs within an iframe. This has implications for other specifications like CSP, which use the destination to determine which directives to consult: https://www.w3.org/TR/CSP/#directive-algorithms

@domenic
Copy link
Member

domenic commented May 15, 2025

This seems to be working as intended. Can you explain further what the problem you're trying to solve is?

@jdm
Copy link
Member Author

jdm commented May 15, 2025

By following the spec, frame-src CSP directives will never be consulted when deciding whether to block an iframe's navigation.

@TimvdLippe
Copy link
Contributor

We are trying to figure out why Servo isn't correctly checking CSP for iframes. @jdm are we maybe missing the steps in https://fetch.spec.whatwg.org/#ref-for-concept-request-destination%E2%91%A1%E2%91%A1 ?

@jdm
Copy link
Member Author

jdm commented May 15, 2025

We are trying to figure out why Servo isn't correctly checking CSP for iframes. @jdm are we maybe missing the steps in https://fetch.spec.whatwg.org/#ref-for-concept-request-destination%E2%91%A1%E2%91%A1 ?

That's text for spec authors making use of the Fetch infrastructure from other specs.

@TimvdLippe
Copy link
Contributor

Navigation of an iframe starts with https://html.spec.whatwg.org/multipage/iframe-embed-object.html#the-iframe-element:navigate which in step 21.9 of https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate calls https://html.spec.whatwg.org/multipage/browsing-the-web.html#attempt-to-populate-the-history-entry's-document Here, the navigation params are empty, since that's only called for object or embed. Thus, we end up in https://html.spec.whatwg.org/multipage/browsing-the-web.html#create-navigation-params-by-fetching where we set the destination to document (rather than iframe).

When that ends up in https://www.w3.org/TR/CSP3/#effective-directive-for-a-request we return connect-src rather than frame-src. Alle frame related CSP checks (child-src for example) therefore don't run.

@domenic
Copy link
Member

domenic commented May 15, 2025

I see, I guess that does seem like a bug.

At this point I don't really understand what the intended architecture was here. CSP does indeed have some frame-ish destinations, but it also has initiators, and seems to imply that CSP should be using initiator instead of destination:

A request’s initiator is not particularly granular for the time being as other specifications do not require it to be. It is primarily a specification device to assist defining CSP and Mixed Content. It is not exposed to JavaScript. [CSP] [MIX]

Do you know what existing browsers do?

@TimvdLippe
Copy link
Contributor

It seems that all browsers store this information in {load,request}_info and implement a switch function, either on the element type or from some other internal enum.

@jdm
Copy link
Member Author

jdm commented May 15, 2025

I see this in #6315:

+    <p>If <var>navigable</var>'s <span data-x="nav-container">container</span> is non-null:</p>
 
-  <p class="note">The <code data-x="dom-location-href">href</code> setter intentionally has no
-  security check.</p>
+    <ol>
+     <li><p>If the <var>navigable</var>'s <span data-x="nav-container">container</span> has a
+     <span>browsing context scope origin</span>, then set <var>request</var>'s <span
+     data-x="concept-request-origin">origin</span> to that <span>browsing context scope
+     origin</span>.</p></li>
 
-  <p>The <dfn attribute for="Location"><code data-x="dom-location-origin">origin</code></dfn>
-  getter steps are:</p>
+     <li><p>Set <var>request</var>'s <span data-x="concept-request-destination">destination</span>
+     and <span data-x="concept-request-initiator-type">initiator type</span> to
+     <var>navigable</var>'s <span data-x="nav-container">container</span>'s <span
+     data-x="concept-element-local-name">local name</span>.</p></li>
+    </ol>

I no longer see that text in the spec, so we apparently lost it at some point since then.

@jdm
Copy link
Member Author

jdm commented May 15, 2025

No, wait, it's just further down the spec from where I originally linked it: step 8 of https://html.spec.whatwg.org/multipage/#create-navigation-params-by-fetching. Apologies for the confusion; this appears to be working as intended.

@jdm jdm closed this as not planned Won't fix, can't repro, duplicate, stale May 15, 2025
@TimvdLippe
Copy link
Contributor

Seems like we were not the first ones to be confused: #8383 Should we maybe add a hint in the spec text to make it clearer what the flow is here?

@annevk annevk added the clarification Standard could be clearer label May 18, 2025
@annevk
Copy link
Member

annevk commented May 18, 2025

@TimvdLippe if you have a concrete suggestion, ideally in the form of a PR, that would make it easier to consider. I'll reopen this for now to keep track of your request.

@annevk annevk reopened this May 18, 2025
TimvdLippe added a commit to TimvdLippe/html that referenced this issue May 18, 2025
To avoid confusion when implementers overlook the step
where destination is updated to the correct navigable
container.

Fixes whatwg#11306
Fixes whatwg#8383
@TimvdLippe
Copy link
Contributor

Sure thing! Opened #11318, but I don't know if a note can be rendered as part of a details table. Also, had to use GitHub codespaces, so not sure if I had to run a commit hook for formatting (I remember HTML spec does that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer
Development

Successfully merging a pull request may close this issue.

4 participants