-
Notifications
You must be signed in to change notification settings - Fork 155
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
Prevent programmatic focus in iframe #273
Comments
Good summary of the options, and why feature-policy is probably a better option than sandbox (namely less web compat issues) is in the original issue at w3c/webappsec#543 (comment) (which I've closed in favor of this one). |
Thanks @dveditz ...has this feature also been accepted or what is the process from now? |
This is very similar to what we added in the spatial navigation specification to avoid iframe highjacking the focus: https://drafts.csswg.org/css-nav-1/#policy-feature through the the events defined in that specification. Our feature policy blocks some events that can be used when the user attempts to move the focus to cancel the default move, and focus something else instead. This is intentional and useful in the context of spatial navigation, but dangerous when done by non trusted iframes. This is different from what is proposed here, but there is no contradiction, and both effects together would be needed to achieve the full effect. Because our events are new, we disallow by default in non trusted iframes, as that is safer and there is no existing content to be compatible with. I don't know if the same would be practical on disabling the |
Thanks @frivoal for bringing this up. I haven't fully read the CSS spatial navigation spec, but based on what I read I have a question: Would In terms of preventing |
In our case, we're not try to prevent the focus from going to the iframe, but rather to prevent the iframe from trapping the focus of it goes there, and never letting it leave. Spatial navigation would naturally find its way out if the user was just navigating, but spatial navigation also emits events that let the page author time which element to go to when the user wants to go in a particular direction. But an evil iframe could use these events to prevent the focus from ever returning to the rest of the page. With the feature policy, we turn off these events inside non trusted iframes by default, with an opt-in.
|
In Chrome we are planning to add a feature policy for this. FYI: @ehsan-karamad @clelland. We are proposing |
Just adding a minor point to @mustaqahmed 's comment where the policy name (we are proposing) is |
@ehsan-karamad @mustaqahmed thanks, name sounds good to me 👍 Please keep us posted about the progress. |
I added a PR for an explainer. I am trying to address the following issues with it:
All suggestions welcome! |
The current explainer suggests automatic focus will be blocked in the top-level document as well as framed content. Should it be made explicit that it will only effect framed content? or is the intention to block all focus attempts without user activation? The current implementation in Chrome Beta (75.0.3770.80) seems to only effect framed content. |
To clarify, focus is blocked when
I personally prefer what the document says (extra mile), i.e., disable focus in all sandboxed frames and do not make the main frame an exception. In Chrome we do not do that today and only sandboxed subframes are blocked. WDYT?
I believe you are right. |
Personally I’d prefer if it worked for everything (i.e. including the top-level document as well), only because the feature policy name does not imply it’s limited to framed content. But is there a valid case for Maybe a page that frames something on the current domain, where the framed content should not change focus? I doubt that’s useful though, as something on the same-domain you don’t trust (e.g. user supplied content), should use |
It think the feature policy name could be debated. To apply the feature to top-level means that if user clicked and opened a link from such a |
I think that for consistency, making it applicable to the top-level document makes sense. It's never going to be the default situation - you'd have to explicitly opt in to that via a header (even in popups, I believe, since the policy should be reset in that case). I don't see a use case for it, but I think it makes reasoning about the feature easier, if it's not special, and works the same way that other features do. |
focus-without-user-activation is still pending adoption by every browser except Chrome and the corresponding w3c issue[1] is still open and active. [1]: w3c/webappsec-permissions-policy#273 Signed-off-by: Harsh Shandilya <[email protected]>
When the query service editor (that means index.html, not embed.html) is embedded into a page, it grabs focus as soon as it loads, potentially scrolling the surrounding page until the cursor is in view. This is rude to the surrounding page and usually not intended. (One hopes that the surrounding page would eventually be able to protect itself against this using a suitable feature policy for the iframe – via the Feature-Policy header or the allow attribute on the iframe itself – but that is still under discussion at the W3C [1].) [1]: w3c/webappsec-permissions-policy#273 Bug: T245637 Change-Id: Iaf3f2a1542801164db340618eaea6130055564b6
@ehsan-karamad @clelland what are the current plans with this new feature policy? |
I'd like to get this standardized; the explainer needs to be updated, and an actual HTML spec change written, I think. It's currently experimental in Chrome, but hasn't actually shipped in any browser. |
Thanks @clelland. I don't want to put pressure, just wanted to know whether there is any rough timeline on when we could expect any movement? |
Hey @clelland sorry for the ping, just wanted to know if there's any update/timeline on this feature? (Also wondering if, in the meantime, there's currently any hacky workaround to prevent an external/cross-site iframe from grabbing focus? My use case is rogue/buggy third-party ads, fwiw) |
No status update, but there is more and more support for the feature, so I think (barring major bugs, or finding out that making this the default on the web breaks a lot of sites) that we could probably be able to ship this soon. (no specific timeline though) |
We too (YT Video Processing) would love to see this feature implemented. |
Still not work for chrome122 , has any update?
|
No (public) movement from Chrome in quite a while, it seems:
Recently I've been getting more user reports of ads calling I don't know if this is deliberate, but I'm pretty sure this exploit is actually technically achievable via some intersection observer trickery (it wouldn't result in a 100% accurate forced-click, but it'd be "good enough"). |
Dealing with same issue, would love an option to disable this in iframes. I do not see a use case for ads to be able to steal focus. |
This is tangential, but for those interested: I just noticed while doing some cross-browser testing that Opera seems to have implemented a user agent intervention for this. This error shows up in DevTools when a rogue advert tries to steal focus: However, it doesn't seem to be 100% effective. I could be wrong, but I think they may only be adding a handler after |
@bozghiyy No, there is nothing at all that can be done to stop this in the general case.1 I've tried literally everything. I'm surprised that companies who heavily rely on the health of the online advertising ecosystem (like Google) haven't given this more attention. If not spec work, then at least a targeted intervention for advert iframes (which IIUC, Chromium already detects/labels), which I assume could be pushed to production a lot faster. If anyone knows if it's possible to sponsor work around this issue, please let me know. 1 There are narrow cases where it can be prevented - e.g. if you can predict when the iframe is about to steal focus, then you can add |
I am going to discuss this issue at TPAC 2024 next week in Web Application Security WG meeting. Here is a brief recap of the issue: However, the issue is left open with some unanswered questions. I want to go through all open questions during the meeting and hopefully bring the issue to a resolution:
|
In case I can't attend the meeting in person, these are my opinions:
|
We discussed this issue during TPAC 2024 webappsec WG group meeting. Minutes: https://github.com/w3c/webappsec/blob/main/meetings/2024/2024-09-23-TPAC-Minutes.md#permission-policy-autofocus. This topic was also discussed during TPAC 2024 in WHATWG meeting. Minutes: whatwg/meta#326 (comment). The proposed solution is accepted: RESOLVED: The default value of We should use whatwg/html#4326 from now on to keep track of the html spec PR update. |
According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5
According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <[email protected]> Commit-Queue: Siye Liu <[email protected]> Reviewed-by: Ian Clelland <[email protected]> Cr-Commit-Position: refs/heads/main@{#1374868}
According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <[email protected]> Commit-Queue: Siye Liu <[email protected]> Reviewed-by: Ian Clelland <[email protected]> Cr-Commit-Position: refs/heads/main@{#1374868}
According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <[email protected]> Commit-Queue: Siye Liu <[email protected]> Reviewed-by: Ian Clelland <[email protected]> Cr-Commit-Position: refs/heads/main@{#1374868}
…`focus-without-user-activation`, a=testonly Automatic update from web-platform-tests [Permissions Policy] update default for `focus-without-user-activation` According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <[email protected]> Commit-Queue: Siye Liu <[email protected]> Reviewed-by: Ian Clelland <[email protected]> Cr-Commit-Position: refs/heads/main@{#1374868} -- wpt-commits: aed1fc329b27fd8fa0db10a7d2640c45a3454ff4 wpt-pr: 48842
…`focus-without-user-activation`, a=testonly Automatic update from web-platform-tests [Permissions Policy] update default for `focus-without-user-activation` According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <[email protected]> Commit-Queue: Siye Liu <[email protected]> Reviewed-by: Ian Clelland <[email protected]> Cr-Commit-Position: refs/heads/main@{#1374868} -- wpt-commits: aed1fc329b27fd8fa0db10a7d2640c45a3454ff4 wpt-pr: 48842
…`focus-without-user-activation`, a=testonly Automatic update from web-platform-tests [Permissions Policy] update default for `focus-without-user-activation` According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <sajosmicrosoft.com> Commit-Queue: Siye Liu <siliumicrosoft.com> Reviewed-by: Ian Clelland <iclellandchromium.org> Cr-Commit-Position: refs/heads/main{#1374868} -- wpt-commits: aed1fc329b27fd8fa0db10a7d2640c45a3454ff4 wpt-pr: 48842 UltraBlame original commit: 8b8674c7ab1082d5b42abc5e3e3015edb4dae088
…`focus-without-user-activation`, a=testonly Automatic update from web-platform-tests [Permissions Policy] update default for `focus-without-user-activation` According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <sajosmicrosoft.com> Commit-Queue: Siye Liu <siliumicrosoft.com> Reviewed-by: Ian Clelland <iclellandchromium.org> Cr-Commit-Position: refs/heads/main{#1374868} -- wpt-commits: aed1fc329b27fd8fa0db10a7d2640c45a3454ff4 wpt-pr: 48842 UltraBlame original commit: 8b8674c7ab1082d5b42abc5e3e3015edb4dae088
…`focus-without-user-activation`, a=testonly Automatic update from web-platform-tests [Permissions Policy] update default for `focus-without-user-activation` According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <sajosmicrosoft.com> Commit-Queue: Siye Liu <siliumicrosoft.com> Reviewed-by: Ian Clelland <iclellandchromium.org> Cr-Commit-Position: refs/heads/main{#1374868} -- wpt-commits: aed1fc329b27fd8fa0db10a7d2640c45a3454ff4 wpt-pr: 48842 UltraBlame original commit: 8b8674c7ab1082d5b42abc5e3e3015edb4dae088
…`focus-without-user-activation`, a=testonly Automatic update from web-platform-tests [Permissions Policy] update default for `focus-without-user-activation` According to discussion[1] in webappsec WG and WHATWG, we should set the default of `focus-without-user-activation` permissions policy to `EnableForSelf`. [1]: w3c/webappsec-permissions-policy#273 (comment) Bug: 371112534 Change-Id: I7deb757d0074e1262d07f768e58ea53a99d5faa5 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5950528 Reviewed-by: Sanket Joshi <[email protected]> Commit-Queue: Siye Liu <[email protected]> Reviewed-by: Ian Clelland <[email protected]> Cr-Commit-Position: refs/heads/main@{#1374868} -- wpt-commits: aed1fc329b27fd8fa0db10a7d2640c45a3454ff4 wpt-pr: 48842
Resubmitting an issue from w3c/webappsec#543
I would like to propose a way to restrict iframe from programmatically setting focus on any of its inputs. Restricting would mean that the .focus() calls inside the iframe would have no effect. I am proposing that it could be achieved with a new feature policy or a sandbox flag, not sure which one suits more to this case:
sandbox:
<iframe src="ad.html" sandbox="allow-focus-calls"><iframe>
feature policy:
<iframe src="ad.html" allow="focus-calls"><iframe>
(The name of the flag is just an example. Feel free to propose a better name)
I am a Software Engineer working on advertising security for a house of large online publishers (Yahoo, Tumblr, HuffPost, TechCrunch, AOL to name a few). The reason behind this proposal is that it gives a way for publishers to improve the security of visitors by restricting the ability for (malicious) ads to programmatically steal focus without users noticing.
Example:
The iframe in the example 'steals' focus from the top page as soon as it loads.
The text was updated successfully, but these errors were encountered: