Skip to content
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

fix(compiler): disallow i18n of security-sensitive attributes #39554

Closed
wants to merge 5 commits into from

Conversation

bjarkler
Copy link
Contributor

@bjarkler bjarkler commented Nov 3, 2020

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: Security improvements.

What is the current behavior?

It is currently possible to mark security-sensitive attributes for i18n translation, e.g.:

<embed src="https://google.com" i18n-src />

This is a feature that should have very little use, but at the same time introduces complexity and security risk in the i18n pipeline.

What is the new behavior?

The above template now generates a parsing error:

Error: src/app/app.component.html:69:35 - error NG5002: Translating attribute 'src' is disallowed for security reasons.

69   <embed src="https://google.com" i18n-src />
                                     ~~~~~~~~

(The same error occurs when using ng extract-i18n.)

Note that this only applies to attributes/properties that are relevant to Trusted Types, which are now enumerated in trusted_types_schema.ts:

  • frame.srcdoc
  • *.innerHTML
  • *.outerHTML
  • embed.src
  • object.codebase
  • object.data

These can be considered the most risky attributes/properties in terms of XSS. (Note that the script tag, inline event handlers, and other attributes/properties of a script context are not relevant here as they are already forbidden or stripped out by the compiler.)

Piggyback:

  • Remove trustConstScript, as it was never needed.
  • Use the new trusted_types_schema to reduce the number of constants that are converted to Trusted Types, and thus improve tree-shakability.

Does this PR introduce a breaking change?

  • Yes
  • No

This seems to be used extremely rarely. Sifting through GitHub search results for i18n-src only reveals a single result that might be affected by this change. (Note that e.g. <img i18n-src is not affected, since it is not a security-sensitive attribute.)

For applications that need to migrate away from this pattern, translation can be done in the corresponding TS file and regular interpolation used in the Angular template instead.

Other information

@google-cla google-cla bot added the cla: yes label Nov 3, 2020
@josephperrott josephperrott added the area: compiler Issues related to `ngc`, Angular's template compiler label Nov 3, 2020
@ngbot ngbot bot added this to the needsTriage milestone Nov 3, 2020
@petebacondarwin petebacondarwin added the target: major This PR is targeted for the next major release label Nov 4, 2020
@IgorMinar IgorMinar self-requested a review November 4, 2020 17:58
@bjarkler bjarkler changed the title WIP(compiler): disallow i18n of security-sensitive attributes fix(compiler): disallow i18n of security-sensitive attributes Nov 18, 2020
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

LGTM, just added a couple comments 👍

packages/compiler/src/render3/view/i18n/meta.ts Outdated Show resolved Hide resolved
packages/compiler/src/schema/trusted_types_sinks.ts Outdated Show resolved Hide resolved
packages/compiler/src/schema/trusted_types_sinks.ts Outdated Show resolved Hide resolved
@AndrewKushnir AndrewKushnir added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 19, 2020
Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

just a few nits, but otherwise this looks good to me.

Reviewed-for: global-approvers, fw-security

packages/compiler/src/schema/trusted_types_sinks.ts Outdated Show resolved Hide resolved
@IgorMinar IgorMinar self-requested a review November 19, 2020 18:25
Copy link
Contributor

@mhevery mhevery left a comment

Choose a reason for hiding this comment

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

With cleanup

packages/compiler/src/render3/view/i18n/meta.ts Outdated Show resolved Hide resolved
@mhevery mhevery self-assigned this Nov 19, 2020
Create a schema with an associated function to classify Trusted Types
sinks.

Piggyback a typo fix.
Make it possible to report errors from the I18nMetaVisitor parser.
To minimize security risk (XSS in particular) in the i18n pipeline,
disallow i18n translation of attributes that are Trusted Types sinks.
Add integration tests to ensure that such sinks cannot be translated.
Previously all constant values of security-sensitive attributes and
properties were promoted to Trusted Types. While this is not inherently
bad, it is also not optimal.

Use the newly added Trusted Types schema to restrict promotion to
constants that are in a Trusted Types-relevant context.
Script tags, inline event handlers and other script contexts are
forbidden or stripped from Angular templates by the compiler. In the
context of Trusted Types, this leaves no sinks that require use of a
TrustedScript. This means that trustConstantScript is never used, and
can be removed.
@bjarkler
Copy link
Contributor Author

Thanks for the comments everyone. I think all of them have been addressed now. Just started a global presubmit; will update the PR tomorrow with the results.

@mhevery
Copy link
Contributor

mhevery commented Nov 19, 2020

presubmit

Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the updates @bjarkler!

Reviewed-for: global-approvers, fw-security

@IgorMinar IgorMinar removed the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Nov 19, 2020
@IgorMinar IgorMinar added action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release and removed breaking changes labels Nov 19, 2020
@IgorMinar
Copy link
Contributor

I'm unflagging this as a breaking change since we have no evidence that there is any valid use of this feature today.

@IgorMinar IgorMinar removed the target: major This PR is targeted for the next major release label Nov 19, 2020
@IgorMinar IgorMinar removed the request for review from jelbourn November 19, 2020 23:45
@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Nov 20, 2020
@AndrewKushnir
Copy link
Contributor

FYI, adding the "presubmit" label since we are waiting for TAP run results from @bjarkler.

@bjarkler
Copy link
Contributor Author

bjarkler commented Nov 20, 2020

global presubmit

@AndrewKushnir
Copy link
Contributor

@bjarkler, please let us know once you get presubmit results so we can proceed with merging this PR. Thank you.

@AndrewKushnir AndrewKushnir removed the action: presubmit The PR is in need of a google3 presubmit label Nov 20, 2020
@AndrewKushnir
Copy link
Contributor

Just a quick note: we've discussed this offline with @bjarkler and this PR is ready to go. Thank you.

AndrewKushnir pushed a commit that referenced this pull request Nov 23, 2020
Make it possible to report errors from the I18nMetaVisitor parser.

PR Close #39554
AndrewKushnir pushed a commit that referenced this pull request Nov 23, 2020
To minimize security risk (XSS in particular) in the i18n pipeline,
disallow i18n translation of attributes that are Trusted Types sinks.
Add integration tests to ensure that such sinks cannot be translated.

PR Close #39554
AndrewKushnir pushed a commit that referenced this pull request Nov 23, 2020
…#39554)

Previously all constant values of security-sensitive attributes and
properties were promoted to Trusted Types. While this is not inherently
bad, it is also not optimal.

Use the newly added Trusted Types schema to restrict promotion to
constants that are in a Trusted Types-relevant context.

PR Close #39554
AndrewKushnir pushed a commit that referenced this pull request Nov 23, 2020
…39554)

Script tags, inline event handlers and other script contexts are
forbidden or stripped from Angular templates by the compiler. In the
context of Trusted Types, this leaves no sinks that require use of a
TrustedScript. This means that trustConstantScript is never used, and
can be removed.

PR Close #39554
@angular-automatic-lock-bot
Copy link

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 angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 24, 2020
@pullapprove pullapprove bot removed the area: compiler Issues related to `ngc`, Angular's template compiler label Dec 24, 2020
@ngbot ngbot bot removed this from the needsTriage milestone Dec 24, 2020
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 cla: yes target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants