Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Xss fix#40136

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
mhevery wants to merge1 commit intoangular:masterfrommhevery:xss_fix
Closed

Xss fix#40136

mhevery wants to merge1 commit intoangular:masterfrommhevery:xss_fix

Conversation

@mhevery
Copy link
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

@mheverymhevery requested review fromAndrewKushnir andIgorMinar and removed request forIgorMinarDecember 15, 2020 21:05
@pullapprovepullapprovebot added area: coreIssues related to the framework runtime comp: docs/api and removed cla: yes labelsDec 15, 2020
@google-cla
Copy link

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

@ngbotngbotbot modified the milestone:BacklogDec 15, 2020
@pullapprovepullapprovebot requested a review fromalxhubDecember 15, 2020 21:05
@mheverymhevery added target: ltsThis PR is targeting a version currently in long-term support target: patchThis PR is targeted for the next patch release and removed area: coreIssues related to the framework runtime comp: docs/api labelsDec 15, 2020
@ngbotngbotbot modified the milestone:BacklogDec 15, 2020
@mheverymhevery added the action: mergeThe PR is ready for merge by the caretaker labelDec 15, 2020
@pullapprovepullapprovebot added area: coreIssues related to the framework runtime comp: docs/api labelsDec 15, 2020
@ngbotngbotbot modified the milestone:BacklogDec 15, 2020
Copy link
Member

@jelbournjelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

Reviewed-for: fw-security

Copy link
Contributor

@AndrewKushnirAndrewKushnir left a comment

Choose a reason for hiding this comment

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

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

@mhevery
Copy link
ContributorAuthor

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 textnot 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 commenttext is not escaped, the comment may contain text which will prematurely close the commentopening up the application for XSS attack. (In SSR we programmatically create comment nodes whichmay contain such text and expect them to be safe.)This function escapes the comment text by looking for the closing char sequence `-->` and replaceit with `-_-_>` where the `_` is a zero width space `\u200B`. The result is that if a commentcontains `-->` text it will render normally but it will not cause the HTML parser to close thecomment.
*/

constEND_COMMENT=/-->/g;
constEND_COMMENT_ESCAPED='-\u200B-\u200B>';
Copy link
Member

Choose a reason for hiding this comment

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

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

@alxhubalxhub removed the target: ltsThis PR is targeting a version currently in long-term support labelDec 16, 2020
alxhub pushed a commit that referenced this pull requestDec 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 textnot 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 commenttext is not escaped, the comment may contain text which will prematurely close the commentopening up the application for XSS attack. (In SSR we programmatically create comment nodes whichmay contain such text and expect them to be safe.)This function escapes the comment text by looking for the closing char sequence `-->` and replaceit with `-_-_>` where the `_` is a zero width space `\u200B`. The result is that if a commentcontains `-->` text it will render normally but it will not cause the HTML parser to close thecomment.PRClose#40136
@angular-automatic-lock-bot

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 ourautomatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-botangular-automatic-lock-botbot locked and limited conversation to collaboratorsJan 16, 2021
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@gkalpakgkalpakgkalpak left review comments

@AndrewKushnirAndrewKushnirAndrewKushnir approved these changes

@jelbournjelbournjelbourn approved these changes

Assignees

No one assigned

Labels

action: mergeThe PR is ready for merge by the caretakerarea: coreIssues related to the framework runtimecla: yestarget: patchThis PR is targeted for the next patch release

Projects

None yet

Milestone

Backlog

Development

Successfully merging this pull request may close these issues.

5 participants

@mhevery@jelbourn@gkalpak@AndrewKushnir@alxhub

[8]ページ先頭

©2009-2025 Movatter.jp