FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Xss fix by mhevery · Pull Request #40136 · angular/angular · GitHub

Xss fix - #40136

Closed
mhevery wants to merge 1 commit into
angular:masterfrom
mhevery:xss_fix
Closed

Xss fix#40136
mhevery wants to merge 1 commit into
angular:masterfrom
mhevery:xss_fix

Conversation

mhevery commented Dec 15, 2020

Copy link
Copy Markdown
Contributor

Escape the content of the strings so that it can be safely inserted into a comment node.

The issue is that HTML does not specify any way to escape comment end text inside the comment. <!-- The way you close a comment is with "-->". -->. Above the "-->" is meant to be text not an end to the comment. This can be created programmatically through DOM APIs.

div.innerHTML = div.innerHTML

One would expect that the above code would be safe to do, but it turns out that because comment text is not escaped, the comment may contain text which will prematurely close the comment opening up the application for XSS attack. (In SSR we programmatically create comment nodes which may contain such text and expect them to be safe.)

This function escapes the comment text by looking for the closing char sequence --> and replace it with -_-_> where the _ is a zero width space \u200B. The result is that if a comment contains --> text it will render normally but it will not cause the HTML parser to close the comment.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

google-cla Bot added the cla: yes label Dec 15, 2020
mhevery requested review from AndrewKushnir and IgorMinar and removed request for IgorMinar December 15, 2020 21:05
pullapprove Bot requested review from atscott and jelbourn December 15, 2020 21:05
pullapprove Bot added area: core Issues related to the framework runtime comp: docs/api and removed cla: yes labels Dec 15, 2020
google-cla Bot added the cla: yes label Dec 15, 2020

google-cla Bot commented Dec 15, 2020

Copy link
Copy Markdown

☹️ Sorry, but only Googlers may change the label cla: yes.

ngbot Bot modified the milestone: Backlog Dec 15, 2020
pullapprove Bot requested a review from alxhub December 15, 2020 21:05
mhevery added target: lts This PR is targeting a version currently in long-term support target: patch This PR is targeted for the next patch release and removed area: core Issues related to the framework runtime comp: docs/api labels Dec 15, 2020
ngbot Bot modified the milestone: Backlog Dec 15, 2020
mhevery added the action: merge The PR is ready for merge by the caretaker label Dec 15, 2020
pullapprove Bot added area: core Issues related to the framework runtime comp: docs/api labels Dec 15, 2020
ngbot Bot modified the milestone: Backlog Dec 15, 2020

jelbourn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Reviewed-for: fw-security

Comment thread packages/core/test/util/dom_spec.ts Outdated

AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, thanks for the fix @mhevery 👍
(just left a couple minor comments related to comments, nothing critical)

Comment thread packages/core/src/util/dom.ts Outdated

mhevery commented Dec 15, 2020

Copy link
Copy Markdown
Contributor Author

presubmit

Escape the content of the strings so that it can be safely inserted into a comment node.
The issue is that HTML does not specify any way to escape comment end text inside the comment.
`<!-- The way you close a comment is with "-->". -->`. Above the `"-->"` is meant to be text
not an end to the comment. This can be created programmatically through DOM APIs.

```
div.innerHTML = div.innerHTML
```
One would expect that the above code would be safe to do, but it turns out that because comment
text is not escaped, the comment may contain text which will prematurely close the comment
opening up the application for XSS attack. (In SSR we programmatically create comment nodes which
may contain such text and expect them to be safe.)
This function escapes the comment text by looking for the closing char sequence `-->` and replace
it with `-_-_>` where the `_` is a zero width space `\u200B`. The result is that if a comment
contains `-->` text it will render normally but it will not cause the HTML parser to close the
comment.
*/

const END_COMMENT = /-->/g;
const END_COMMENT_ESCAPED = '-\u200B-\u200B>';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

OOC, why use two \u200Bs? Wouldn't --\u200B> also work?

alxhub removed the target: lts This PR is targeting a version currently in long-term support label Dec 16, 2020
alxhub closed this in 47d9b6d Dec 16, 2020
alxhub pushed a commit that referenced this pull request Dec 16, 2020
Escape the content of the strings so that it can be safely inserted into a comment node.
The issue is that HTML does not specify any way to escape comment end text inside the comment.
`<!-- The way you close a comment is with "-->". -->`. Above the `"-->"` is meant to be text
not an end to the comment. This can be created programmatically through DOM APIs.

```
div.innerHTML = div.innerHTML
```
One would expect that the above code would be safe to do, but it turns out that because comment
text is not escaped, the comment may contain text which will prematurely close the comment
opening up the application for XSS attack. (In SSR we programmatically create comment nodes which
may contain such text and expect them to be safe.)
This function escapes the comment text by looking for the closing char sequence `-->` and replace
it with `-_-_>` where the `_` is a zero width space `\u200B`. The result is that if a comment
contains `-->` text it will render normally but it will not cause the HTML parser to close the
comment.

PR Close #40136

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jan 16, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL