Features/Platform/Iframe Sandbox: Difference between revisions

no edit summary
No edit summary
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{FeatureStatus
{{FeatureStatus
|Feature name=Iframe Sandbox
|Feature name=Iframe Sandbox
|Feature stage=Development
|Feature stage=Landed
|Feature status=In progress
|Feature status=Complete
|Feature version=Firefox 17
|Feature health=OK
|Feature health=OK
|Feature status note=initial implementation done, initial test suite under development
|Feature status note=landed in FF17 - some followup work remains
}}
}}
{{FeatureTeam
{{FeatureTeam
Line 14: Line 15:
}}
}}
{{FeaturePageBody
{{FeaturePageBody
|Feature open issues and risks=* The origin (in string form) of a null principal - this will be sent by CORS, the origin header (if/when it's implemented), postMessage etc - the HTML5 spec says that it should be a GUID in this case - need to see what gets used in these cases when content has a null principal a
|Feature overview=The HTML5 spec specifies a new attribute for the IFRAME element, "sandbox", see http://dev.w3.org/html5/spec/the-iframe-element.html#attr-iframe-sandbox. See also [https://bugzilla.mozilla.org/show_bug.cgi?id=341604 bug 341604] "Implement HTML5 sandbox attribute for IFRAMEs" and [https://bugzilla.mozilla.org/show_bug.cgi?id=671389 bug 671389] "Implement CSP sandbox directive"
* what to do with Workers in a sandboxed frame - would probably need allow-scripts for these, and maybe allow-same-origin ? or just block them altogether, as apparently some other browsers have done
|Feature users and use cases=Users are web developers looking for a way to isolate content on their site and prevent it from having its default same origin privileges, ability to execute scripts and other normally granted abilities. The HTML5 spec specifies some modifying attributes that can grant permissions such as same origin , executing scripts, navigating the top window and submitting forms, etc. There are other abilities which are always removed in a sandboxed document that cannot be granted.
* are there other methods that the ones mentioned in the HTML5 spec (target='blank_', showModalDialog() and window.open) to open new windows ?
|Feature overview=The HTML5 standard specifies a new attribute for the IFRAME element, "sandbox". See also [https://bugzilla.mozilla.org/show_bug.cgi?id=341604 bug 341604] "Implement HTML5 sandbox attribute for IFRAMEs" and [https://bugzilla.mozilla.org/show_bug.cgi?id=671389 bug 671389] "Implement CSP sandbox directive"
|Feature users and use cases=Users are web developers looking for a way to isolate content on their site and preventing it from having its default same origin privileges and ability to execute scripts. The HTML5 spec specifies some modifying attributes that can re-grant permissions such as same origin privilege, executing scripts, navigating the top window and submitting forms, etc.
|Feature requirements=This feature should be designed and implemented in a way that makes it usable for also implementing the sandboxing required to support the CSP (Content Security Policy) sandbox value also.
|Feature requirements=This feature should be designed and implemented in a way that makes it usable for also implementing the sandboxing required to support the CSP (Content Security Policy) sandbox value also.


Line 27: Line 25:
* implementing @sandbox on <frame> - this was discussed on the whatwg list and @sandbox for <frame> will not be implemented at the current time (this matches at least one other implementation)
* implementing @sandbox on <frame> - this was discussed on the whatwg list and @sandbox for <frame> will not be implemented at the current time (this matches at least one other implementation)
* implementing @sandbox on <xul:iframe/browser/editor> - the current implementation shouldn't prevent this enhancement from being implemented but there are no plans to implement this at the current time
* implementing @sandbox on <xul:iframe/browser/editor> - the current implementation shouldn't prevent this enhancement from being implemented but there are no plans to implement this at the current time
|Feature functional spec=An IFRAME with the sandbox attribute (and its various modifying attributes) should behave as outlined in the HTML5 spec. See W3C Working Draft at http://www.w3.org/TR/html5/the-iframe-element.html#the-iframe-element and W3C Editor's Draft at http://dev.w3.org/html5/spec/Overview.html#the-iframe-element. This feature attempts to be compatible with the CSP sandbox directive (see https://wiki.mozilla.org/Security/CSP/Sandbox) by establishing infrastructure where CSP would only have to set the sandbox flags on content documents to have them sandboxed as intended.
|Feature functional spec=An IFRAME with the sandbox attribute (and its various modifying attributes) should behave as outlined in the HTML5 spec. See W3C Working Draft at http://www.w3.org/TR/html5/the-iframe-element.html#the-iframe-element and W3C Editor's Draft at http://dev.w3.org/html5/spec/Overview.html#the-iframe-element. This feature attempts to be compatible with the CSP sandbox directive (see https://wiki.mozilla.org/Security/CSP/Sandbox) by establishing infrastructure where CSP only needs to set the sandbox flags on content documents to have them sandboxed as intended.
|Feature implementation plan=* The general approach is to give a sandboxed IFRAME a null principal to remove its normal domain/principal. This removes its same origin privileges (unless allow-same-origin is specified as part of the sandbox attribute)
|Feature implementation plan=* The general approach for removing same-origin privileges is to give a sandboxed IFRAME a null principal to remove its normal domain/principal. This removes its same origin privileges unless allow-same-origin is specified as part of the sandbox attribute. In some case, there are additional checks that need to be added to the code to see if a document is sandboxed in a way that would prevent an operation from occurring.
* We will use nsDocShell::SetAllowJavascript(false) to prevent scripts being executed (unless allow-scripts is specified as part of the sandbox attribute)
* We will use nsDocShell::SetAllowPlugins(false) to prevent plugins being loaded by a sandboxed IFRAME
* We will use nsDocShell::SetAllowPlugins(false) to prevent plugins being loaded by a sandboxed IFRAME
* We will create the flags as described in the HTML5 spec's description of the IFRAME sandbox attribute on both the docshell and the document when it is loaded  
* We will create the flags as described in the HTML5 spec's description of the IFRAME sandbox attribute on both the docshell and the document when it is loaded  


nsIDocShell.idl will contain :  
content/base/src/nsSandboxFlags.h contains :  
<pre>
<pre>
+  /**
+  /**
Line 74: Line 71:
+  const unsigned long SANDBOXED_SCRIPTS = 0x20;
+  const unsigned long SANDBOXED_SCRIPTS = 0x20;
</pre>
</pre>
** when the sandbox attribute on an IFRAME element is modified, we will change the flags on the docshell but not the document  
** when the sandbox attribute on an IFRAME element is modified, we will change the flags on the docshell but not the document - the document must be reloaded for the changed flags on the docshell to take effect
*** we will implement this using nsGenericHTMLFrameElement::AfterSetAttr,  
*** we will implement this using nsHTMLIFrameElement::AfterSetAttr,  
** the document needs to keep the exact set of flags assigned at load time (these are immutable - changing sandbox attributes does NOT dynamically affect already loaded content)
** the document needs to keep the exact set of flags assigned at load time (these are immutable - changing sandbox attributes does NOT dynamically affect already loaded content)
** sandbox flags for a document are set based on the sandbox flags of its parent document and the sandbox flags of the embedding frame (stored in the docshell)
** sandbox flags for a document are set based on the sandbox flags of its parent document and the sandbox flags of the embedding frame (stored in the docshell)
Line 83: Line 80:
* nsFrameLoader will be modified to assign the null principal to a sandboxed IFRAME (if allow-same-origin is not specified)
* nsFrameLoader will be modified to assign the null principal to a sandboxed IFRAME (if allow-same-origin is not specified)
** this also requires modifying surrounding code to be able to force an owner to be set on the loading channel.  
** this also requires modifying surrounding code to be able to force an owner to be set on the loading channel.  
** SHentry will also need the same 'force owner' flag for when the IFRAME is loaded from session history.
** we may be able to implement both cases in one place if we do the null principal assignment at a low enough level in the docshell loading code
** we may be able to implement both cases in one place if we do the null principal assignment at a low enough level in the docshell loading code
** The nsFrameLoader will check if its owner content has the sandbox attribute set and is an nsHTMLIFrameElement to determine whether to sandbox the frame being loaded (again, if the allow-same-domain modifier isn't present in the sandbox attribute)
** The nsFrameLoader will check if its owner content has the sandbox attribute set and is an nsHTMLIFrameElement to determine whether to sandbox the frame being loaded (again, if the allow-same-domain modifier isn't present in the sandbox attribute)
Line 89: Line 85:
* for CSP sandbox, the flags will only be stored on the document itself - when content is navigated to, the CSP sandbox flags won't be persisted (unless the new content also specifies a CSP sandbox directive)
* for CSP sandbox, the flags will only be stored on the document itself - when content is navigated to, the CSP sandbox flags won't be persisted (unless the new content also specifies a CSP sandbox directive)
* the HTML5 spec provides examples of how to apply flags with nested IFRAMEs, abarth has proposed that if both CSP and IFRAME sandbox can apply to content, the algorithm used in these example should be used to merge the policies which sounds reasonable
* the HTML5 spec provides examples of how to apply flags with nested IFRAMEs, abarth has proposed that if both CSP and IFRAME sandbox can apply to content, the algorithm used in these example should be used to merge the policies which sounds reasonable
|Feature security review=This feature will definitely need a full security review from the secteam. I suggest discussing the spec and making sure other means to do actions like opening windows or 'doing something automatically' are also covered by the implementation and test suite.
* Disabling Javascript uses the same script choke points as CSP to maximize the functionality available in a sandboxed document while still not allowing the document to load a remote script or execute inline script.
* After discussion, we allow workers to be loaded inside a sandboxed document with 'allow-scripts' (but without 'allow-same-origin') from a data: URL or a blob URL created by the same sandboxed document creating the worker. This requires modifying either worker code or CheckMayLoad() code most likely.
* After discussion, although the sandbox attribute is specified as DOMSettableTokenList in the HTML5 spec, this implementation implements it as a DOMString.
|Feature security review=This feature will definitely need a full security review from the Security Assurance team. I've posted this feature page on dev.security and updated the bug with decisions and implementation plans as implementation has proceeded. Before the security review I will post again to dev.security and encourage review of this feature page and the HTML5 iframe sandbox spec.
|Feature qa review=We will need a test suite for this feature. Microsoft has released test cases for sandboxing publically that have been submitted to the W3C for inclusion in the HTML5 test suite. We will definitely want to compare our implementation to other browsers' implementation for consistency etc. and address inconsistencies via suggested modifications to the HTML5 spec and discussion on the whatwg list. Boris Zbarsky has suggested submitting our sandbox test suite to the W3C also.
|Feature qa review=We will need a test suite for this feature. Microsoft has released test cases for sandboxing publically that have been submitted to the W3C for inclusion in the HTML5 test suite. We will definitely want to compare our implementation to other browsers' implementation for consistency etc. and address inconsistencies via suggested modifications to the HTML5 spec and discussion on the whatwg list. Boris Zbarsky has suggested submitting our sandbox test suite to the W3C also.


A mochitest test suite will be written to provide consistent automated testing for this feature.
A mochitest test suite has been written to provide consistent automated testing for this feature.
|Feature implementation notes=See https://bugzilla.mozilla.org/show_bug.cgi?id=341604 for a patch that attempts to implement HTML5 iframe sandbox. tests will be posted in that bug as well when complete.
|Feature implementation notes=See https://bugzilla.mozilla.org/show_bug.cgi?id=341604 for a patch that attempts to implement HTML5 iframe sandbox.  
|Feature landing criteria=* Needs a test suite
 
* Needs to be compared against other implementations and public test suites for consistency
There's an set of tests for various pieces of functionality in that bug as well.
* Needs a full security review
 
Please see the bug for updates to current patches and iteration based on feedback/review.
|Feature landing criteria=* Needs a test suite - DONE
* Needs to be compared against other implementations and public test suites for consistency - DONE
* Needs a full security review - DONE
}}
}}
{{FeatureInfo
{{FeatureInfo
Line 106: Line 109:
}}
}}
{{FeatureTeamStatus
{{FeatureTeamStatus
|Feature engineering status=In Progress
|Feature engineering status=Complete
|Feature engineering notes=Initial implementation done, has received feedback from 3 people. Experimental prototype was rewritten after initial feedback. Test suite under development, will be looking for feedback soon.
|Feature engineering notes=Landed in FF17 - there are some followups.
 
}}
}}
Confirmed users
197

edits