This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29061 - iframe@sandbox support should be feature-detectable.
Summary: iframe@sandbox support should be feature-detectable.
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: https://html.spec.whatwg.org/#dom-ifr...
Whiteboard:
Keywords:
Depends on:
Blocks: 28796
  Show dependency treegraph
 
Reported: 2015-08-18 13:39 UTC by contributor
Modified: 2016-01-24 06:06 UTC (History)
8 users (show)

See Also:


Attachments

Description contributor 2015-08-18 13:39:06 UTC
Specification: https://html.spec.whatwg.org/multipage/embedded-content.html
Multipage: https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
Complete: https://html.spec.whatwg.org/#dom-iframe-sandbox
Referrer: https://html.spec.whatwg.org/multipage/index.html

Comment:
iframe@sandbox support should be feature-detectable.

Currently, there's no feature-detection mechanism for sandbox attributes. A
trivial way of adding one might be to limit iframe@sandbox attribute to
reflect only known values
(https://html.spec.whatwg.org/multipage/infrastructure.html#limited-to-only-kn
own-values).

Posted from: 216.239.45.87
User agent: Mozilla/5.0 (X11; CrOS x86_64 7262.33.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.37 Safari/537.36
Comment 1 Mike West 2015-08-18 13:40:23 UTC
WDYT, Anne, Domenic?
Comment 2 Anne 2015-08-18 14:13:39 UTC
That only works for enumerated attributes. sandbox="" is an unordered set of unique space-separated tokens.
Comment 3 Mike West 2015-08-18 14:26:28 UTC
Ok. I admit, I didn't actually read the definition, but it sounded right. :)

You're right that we'd need a new concept, but conceptually it'd be similar. That is, it seems reasonable to just drop unknown values on the floor during parsing, such that the following would hold:

```
var i = document.createElement('iframe');
i.sandbox = "allow-scripts lldshf";
i.sandbox.value; // "allow-scripts"
```
Comment 4 Anne 2015-08-18 14:30:40 UTC
Well, the sandbox property also returns a DOMSettableTokenList so it's not really a string. And DOMSettableTokenList cannot enforce validity of strings at the moment. So it would require quite a bit more changes I think.
Comment 5 Mike West 2015-08-18 14:38:19 UTC
If modifying the attribute's behavior is more work than it's worth, I'm open to any other options. Put an inspectable enum of allowed values somewhere, done. :)
Comment 6 Domenic Denicola 2015-08-18 22:29:41 UTC
I think this would be a reasonable change to DOMSettableTokenList/DOMTokenList, to only reflect to the tokens that the browser recognizes. It would require some spec and implementation work to happen though, including a willingness to break back-compat.
Comment 7 Mike West 2015-08-19 00:44:22 UTC
(In reply to Domenic Denicola from comment #6)
> I think this would be a reasonable change to
> DOMSettableTokenList/DOMTokenList, to only reflect to the tokens that the
> browser recognizes. It would require some spec and implementation work to
> happen though, including a willingness to break back-compat.

Looking at IDL files, backwards compatability doesn't seem to be a big risk: there are only three DOMSettableTokenList attributes implemented in Chrome, for example.
Comment 8 Domenic Denicola 2015-08-19 04:47:50 UTC
Here is a potential plan for the required spec changes:

Modifications to DOM:

- Add an associated optional token validation algorithm to DOMTokenList.
- Modify DOMTokenList.prototype.{add,remove,toggle,contains} to either throw or ignore their input if it the token validation algorithm is present and running it fails on a given token. Be sure to define e.g. `i.sandbox.add("valid", "invalid", "valid2")` in a well-defined way. I can see pro- and con- arguments for either behavior.
- Modify DOMSettableTokenList.prototype.value's setter to run the token validation algorithm if present, before setting tokens to the result.

Modifications to HTML:

- Add such a token validation algorithm to HTMLIFrameElement.prototype.seamless, validating that the value is in the given set.
- If possible, find other specs that could benefit from this and add algorithms to them at the same time.

Anne, WDYT?
Comment 9 Anne 2015-08-19 06:16:05 UTC
Sounds reasonable. And useful.
Comment 10 Simon Pieters 2015-08-28 15:08:27 UTC
Throwing as a way to feature-detect seems more annoying than e.g. a return value. It seems to me that we don't necessarily want the API to reject invalid values, we just want to enable feature-detection. You might still want to add values that the implementation doesn't support if that makes the logic simpler. It also seems somewhat risky Web-compat-wise to start throwing.

To that end, I think the minimal change is to make DOMTokenList#add have a boolean return value where, if there is token validation defined and all values added are supported, it returns true; otherwise returns false.

var i = document.createElement('iframe');
var supported = i.sandbox.add("lldshf");
Comment 11 Simon Pieters 2015-08-28 15:10:53 UTC
Alternatively introduce DOMTokenList#supports()
Comment 12 Domenic Denicola 2015-08-28 15:37:14 UTC
It still seems valuable to me to have the built-in ways of manipulating a DOMTokenList try to preserve no-invalid-tokens. That is, having add and toggle ignore invalid tokens seems like a good change regardless.
Comment 13 Simon Pieters 2015-08-29 16:18:08 UTC
Why?
Comment 14 Anne 2015-08-29 16:46:44 UTC
It would be more consistent with "limited to known values", an existing pattern, whereas you are proposing a new pattern.
Comment 15 Simon Pieters 2015-08-31 11:07:25 UTC
OK. Consistency with that suggests not throwing. Let's try it.
Comment 16 Yoav Weiss 2015-11-03 10:18:47 UTC
I like the solution outlined and it seems like it would be useful for https://github.com/w3c/preload/issues/7 as well, when used on `relList`.

Having a boolean return value also has the added benefit of having legacy UAs fall into the "false" bucket for most cases, since their return value for `add()` would be `undefined`.
Comment 17 Ms2ger 2015-11-03 11:47:48 UTC
The solution that's most consistent with "limited to known values" would be to make `add` return true or false depending on whether the token(s) are supported, but add all passed tokens to the content attribute regardless of whether they're supported. I suspect this is also likely the most web-compatible change.
Comment 18 Simon Pieters 2015-11-10 12:33:36 UTC
https://github.com/whatwg/dom/pull/103 fixes this issue for the DOM spec, but the HTML spec needs to use the new hook for <iframe sandbox> (this bug) and <link rel> (bug 28796).
Comment 19 Domenic Denicola 2016-01-24 06:06:47 UTC
This is now fixed: "The supported tokens for sandbox are the allowed values defined for the sandbox attribute that are supported by the user agent."