X Tutup
The Wayback Machine - https://web.archive.org/web/20211112004622/https://github.com/angular/angular/pull/43108
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

build: Enable tsec checks for critical packages. #43108

Closed
wants to merge 5 commits into from
Closed

Conversation

Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
@uraj
Copy link
Contributor

@uraj uraj commented Aug 10, 2021

tsec is a static analyzer that discovers Trusted Types violations.
Deploy tsec to make sure there will be no TT regression in the core
package. Existing violations have been reviewed and exempted in
packages/tsec-exemption.json.

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 google-cla bot added the cla: yes label Aug 10, 2021
@uraj uraj marked this pull request as draft Aug 10, 2021
@uraj
Copy link
Contributor Author

@uraj uraj commented Aug 10, 2021

@josephperrott This is the PR that enables TT static analysis for the core package. Could you take a look?

Loading

@AndrewKushnir AndrewKushnir requested a review from IgorMinar Aug 10, 2021
@google-cla
Copy link

@google-cla google-cla bot commented Aug 11, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

Loading

@google-cla google-cla bot added cla: no and removed cla: yes labels Aug 11, 2021
@uraj uraj marked this pull request as ready for review Aug 11, 2021
Copy link
Member

@IgorMinar IgorMinar left a comment

Thanks @uraj for sending us this PR! I'm supportive of adding tsec to our repo.

Overall I like where this is heading, I left a few comments primarily asking for clarification on your intention here.

If we could change the PR to run these tests via bazel, then that would be better, but I can't easily estimate how much more work that would be. @josephperrott might have a better understanding. Maybe running it via the new https://bazelbuild.github.io/rules_nodejs/ that autogenerate bazel rules for npm binaries (see the babel example in that link) would make it trivial if we can collect all the right inputs easily.

Please take a look at the other comments. Thank you again.

Loading

"outDir": ".tsec",
"types": ["node"]
},
"files": ["zone.ts"]
Copy link
Member

@IgorMinar IgorMinar Aug 11, 2021

Choose a reason for hiding this comment

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

is it right that you included just the zone.ts, shouldn't files under browser/* and others be included as well?

Loading

Copy link
Contributor Author

@uraj uraj Aug 11, 2021

Choose a reason for hiding this comment

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

The original plan is to only check core, which only depends zone.d.ts but not anything in browser/* (in terms of type checking). Do we actually want to check browser/*? If so, I can include it as one of the to-be-checked packages.

Loading

packages/tsconfig-build.json Outdated Show resolved Hide resolved
Loading
packages/tsconfig-tsec.json Outdated Show resolved Hide resolved
Loading
"extends": "../tsconfig-tsec-base.json",
"compilerOptions": {
"composite": true,
"outDir": ".tsec"
Copy link
Member

@IgorMinar IgorMinar Aug 11, 2021

Choose a reason for hiding this comment

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

I'm not too keen on writing these files into the working directory. I see that it's .gitignored but it still feels icky.

how difficult is it to run tsec under bazel?

Loading

Copy link
Contributor Author

@uraj uraj Aug 11, 2021

Choose a reason for hiding this comment

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

Tsetse (the checker engine used by tsec) used to be part of @bazel/typescript, but the support was discontinued due to the TS team being understaffed.

I tried to hack this a bit, and it turns out to need quite some work. To effectively manage dependencies with bazel, all tsconfig-tsec.json files need to be generated rather than being hand-written. The TypeScript compiler provided by bazel has a few augmentations to make this easier, but tsec is not that different from the vanilla tsc.

I can discuss with my TL whether we should support using tsec with bazel in the future (I have a prototype that can handle TS libraries with only node_modules dependencies). For now I think we have two options as temporary compromises:

  • Make tsec place all the generated declaration files at a location outside of the working directory, e.g., /tmp/tsec or ${PROJECT_ROOT}/.tsec.
  • Stop using project references so that I can turn on noEmit. That way tsec won't generate any files in the working directory, at the cost of loosing incremental compilation. This, however, may not be feasible, due to zone.js/lib producing an global-scoped file zone.d.ts (without any exports), which is tricky to handle in a noEmit configuration.

What do you think?

Loading

Copy link
Contributor Author

@uraj uraj Aug 13, 2021

Choose a reason for hiding this comment

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

I was able to do certain amount of bazel integration. There are several caveats though.

  • tsconfig-tsec.json files are still not auto-generated and have to be maintained manually to make it consistent with BUILD.bazel. The maintenance cost should be low though.
  • The bazel rule tsec_test does not check transitive dependencies, so each dependency needs to have its own tsec_test. This is hard to fix, unless we can have some upstream patches for the vanilla ts_library bazel rule.

Loading

packages/localize/tsconfig-tsec.json Outdated Show resolved Hide resolved
Loading
packages/tsec-exemption.json Show resolved Hide resolved
Loading
@pullapprove pullapprove bot requested a review from alan-agius4 Aug 11, 2021
@google-cla
Copy link

@google-cla google-cla bot commented Aug 11, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

Loading

1 similar comment
@google-cla
Copy link

@google-cla google-cla bot commented Aug 11, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

Loading

@google-cla
Copy link

@google-cla google-cla bot commented Aug 11, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

Loading

@uraj uraj changed the title feat(core): Enable tsec checks for @angular/core. feat(dev-infra): Enable tsec checks for critical packages. Aug 11, 2021
@google-cla google-cla bot added cla: yes and removed cla: no labels Aug 11, 2021
@uraj uraj changed the title feat(dev-infra): Enable tsec checks for critical packages. feat: Enable tsec checks for critical packages. Aug 12, 2021
@uraj uraj changed the title feat: Enable tsec checks for critical packages. build: Enable tsec checks for critical packages. Aug 12, 2021
@uraj uraj requested a review from IgorMinar Aug 12, 2021
@uraj
Copy link
Contributor Author

@uraj uraj commented Sep 13, 2021

@devversion I filled google/tsec#23 to track Windows compatibility.

Loading

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Sep 13, 2021

@josephperrott there is an indication that this PR needs g3 presubmit and it looks like only **/tsconfig-tsec.json files are synced (see presubmit CL). Do we need those files in g3 of should we exclude them from the sync? Adding the "cleanup" label to this PR for now.

Loading

@uraj
Copy link
Contributor Author

@uraj uraj commented Sep 13, 2021

@AndrewKushnir I think they can be excluded.

Loading

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Sep 13, 2021

@uraj thanks for the comment. Could you please update the exclude list in https://github.com/angular/angular/blob/master/.github/angular-robot.yml#L42 to reflect that (and also the file in g3 that is mentioned at https://github.com/angular/angular/blob/master/.github/angular-robot.yml#L35)? That should eliminate the need to have a presubmit for this PR.

Loading

Those files are for tsec_test only and therefore irrelevant to google3.
@uraj
Copy link
Contributor Author

@uraj uraj commented Sep 13, 2021

@AndrewKushnir Updated.

Loading

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Sep 13, 2021

Thanks for the update @uraj. I've updated g3 status for this PR and removed the "cleanup" label.

Loading

@AndrewKushnir
Copy link
Contributor

@AndrewKushnir AndrewKushnir commented Sep 13, 2021

Merge-assistance: it's ok to proceed with the current set of reviews, since its just testing changes around everything and not changing the code in those areas.

Loading

AndrewKushnir added a commit that referenced this issue Sep 13, 2021
Introduce two new bazel rules: tsec_test and tsec_config, for
describing the tsec checks and the tsconfig file needed for such
checks, respectively. Currently, tsec_test only checks the srcs
of a ts_library or ng_module. It does not check direct or transitive
dependencies. Also, tsconfig files need to be manually maintained
to make sure tsec can read all necessary input (including global
symbols).

PR Close #43108
AndrewKushnir added a commit that referenced this issue Sep 13, 2021
This is to replace the implicitly created ts_library_forwared rules and
keep changes related to tsec/bazel integration solely in tools/tsec.bzl.

PR Close #43108
AndrewKushnir added a commit that referenced this issue Sep 13, 2021
Upgrade tsec version form 0.1.8 to 0.1.9. The new version has a minor
bug fix.

PR Close #43108
AndrewKushnir added a commit that referenced this issue Sep 13, 2021
Those files are for tsec_test only and therefore irrelevant to google3.

PR Close #43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 16, 2021
tsec is a static analyzer that discovers Trusted Types violations.
Deploy tsec to make sure there will be no TT regression in several
critical packages, including core, platform-browser, platform-server
and their dependencies. Existing violations have been reviewed and
exempted in packages/tsec-exemption.json. Future changes to the
exemption list requires security review.

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 16, 2021
Introduce two new bazel rules: tsec_test and tsec_config, for
describing the tsec checks and the tsconfig file needed for such
checks, respectively. Currently, tsec_test only checks the srcs
of a ts_library or ng_module. It does not check direct or transitive
dependencies. Also, tsconfig files need to be manually maintained
to make sure tsec can read all necessary input (including global
symbols).

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 16, 2021
)

This is to replace the implicitly created ts_library_forwared rules and
keep changes related to tsec/bazel integration solely in tools/tsec.bzl.

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 16, 2021
Upgrade tsec version form 0.1.8 to 0.1.9. The new version has a minor
bug fix.

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 16, 2021
)

Those files are for tsec_test only and therefore irrelevant to google3.

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 22, 2021
tsec is a static analyzer that discovers Trusted Types violations.
Deploy tsec to make sure there will be no TT regression in several
critical packages, including core, platform-browser, platform-server
and their dependencies. Existing violations have been reviewed and
exempted in packages/tsec-exemption.json. Future changes to the
exemption list requires security review.

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 22, 2021
Introduce two new bazel rules: tsec_test and tsec_config, for
describing the tsec checks and the tsconfig file needed for such
checks, respectively. Currently, tsec_test only checks the srcs
of a ts_library or ng_module. It does not check direct or transitive
dependencies. Also, tsconfig files need to be manually maintained
to make sure tsec can read all necessary input (including global
symbols).

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 22, 2021
)

This is to replace the implicitly created ts_library_forwared rules and
keep changes related to tsec/bazel integration solely in tools/tsec.bzl.

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 22, 2021
Upgrade tsec version form 0.1.8 to 0.1.9. The new version has a minor
bug fix.

PR Close angular#43108
TeriGlover added a commit to TeriGlover/angular that referenced this issue Sep 22, 2021
)

Those files are for tsec_test only and therefore irrelevant to google3.

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

@angular-automatic-lock-bot angular-automatic-lock-bot bot commented Oct 14, 2021

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.

Loading

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
X Tutup