-
Notifications
You must be signed in to change notification settings - Fork 22.9k
HTMLIFrameElement.srcdoc - takes trusted types #41459
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
base: main
Are you sure you want to change the base?
Conversation
Preview URLs Flaws (6)Note! 1 document with no flaws that don't need to be listed. 🎉 URL:
External URLs (1)URL:
|
If the frame is not sandboxed using the Content Security Property (CSP) [`sandbox` directive](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/sandbox) (or is sandboxed but includes the [`allow-same-origin`](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/sandbox#allow-same-origin) value) then it will be same-origin with the parent. | ||
This means that the frame will have complete access to the parent DOM and resources, and visa versa. | ||
|
||
This is a very significant vector for [Cross-site-scripting (XSS)](/en-US/docs/Web/Security/Attacks/XSS) attacks if potentially unsafe strings provided by a user injected into a frame without first being sanitized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very significant vector for [Cross-site-scripting (XSS)](/en-US/docs/Web/Security/Attacks/XSS) attacks if potentially unsafe strings provided by a user injected into a frame without first being sanitized. | |
This is a very significant vector for [Cross-site-scripting (XSS)](/en-US/docs/Web/Security/Attacks/XSS) attacks if potentially unsafe strings provided by a user are injected into a frame without first being sanitized. |
This means that the frame will have complete access to the parent DOM and resources, and visa versa. | ||
|
||
This is a very significant vector for [Cross-site-scripting (XSS)](/en-US/docs/Web/Security/Attacks/XSS) attacks if potentially unsafe strings provided by a user injected into a frame without first being sanitized. | ||
Consider the following code where a string of HTML from a user might be passed into a frame, that is then added to the document. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the following code where a string of HTML from a user might be passed into a frame, that is then added to the document. | |
Consider the following code where a string of HTML from a user might be passed into a frame that is then added to the document. |
``` | ||
|
||
If the frame is not expected to need access to your parent document, you can significantly mitigate the risk by using a CSP sandbox without the `allow-same-origin` value. | ||
The frame will then be treated as a cross-origin resource, and and attacks will be significantly restricted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The frame will then be treated as a cross-origin resource, and and attacks will be significantly restricted. | |
The frame will then be treated as a cross-origin resource, and attacks will be significantly restricted. |
``` | ||
|
||
Next we create a {{domxref("TrustedTypePolicy")}} that defines a {{domxref("TrustedTypePolicy/createHTML", "createHTML()")}} for transforming an input string into {{domxref("TrustedHTML")}} instances. | ||
Commonly implementations of `createHTML()` use a library such as [DOMPurify](https://github.com/cure53/DOMPurify) to sanitize the input as shown below: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commonly implementations of `createHTML()` use a library such as [DOMPurify](https://github.com/cure53/DOMPurify) to sanitize the input as shown below: | |
Commonly, implementations of `createHTML()` use a library such as [DOMPurify](https://github.com/cure53/DOMPurify) to sanitize the input, as shown below: |
``` | ||
|
||
> [!WARNING] | ||
> While you can directly assign a string to `srcdoc` this is a [security risk](#security_considerations) if the string to be inserted might contain potentially malicious content. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> While you can directly assign a string to `srcdoc` this is a [security risk](#security_considerations) if the string to be inserted might contain potentially malicious content. | |
> While you can directly assign a string to `srcdoc`, this is a [security risk](#security_considerations) if the string to be inserted might contain potentially malicious content. |
HTMLIFrameElement.srcdoc
now takes TrustedHTML. This updates the docs using similar patterns to theElement.innerHTML
docs.Related docs work can be tracked in #37518 (comment)