Skip to content

Commit d93d9a3

Browse files
authored
ci: Add tsec_test for all ng_module targets. (#24066)
* ci: Add tsec_test for all ng_module targets. Instead of modifying ~250 BUILD.bazel files, instrument the ng_module macro to conveniently create tsec_test for all modules. The ts_library macro is not instrumented since most of them are about testing, schematics and examples, which are not relevant to XSS. For those that are indeed security sensitive, tsec_test is manually added into individual BUILD.bazel files. * fixup! ci: Add tsec_test for all ng_module targets. * fixup! ci: Add tsec_test for all ng_module targets.
1 parent 73f5a5f commit d93d9a3

File tree

9 files changed

+67
-3
lines changed

9 files changed

+67
-3
lines changed

goldens/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
exports_files([
22
"size-test.yaml",
3+
"tsec-exemption.json",
34
])

goldens/tsec-exemption.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"ban-trustedtypes-createpolicy": [
3+
"../src/material/icon/trusted-types.ts"
4+
],
5+
"ban-element-innerhtml-assignments": [
6+
"../src/material/icon/icon-registry.ts"
7+
],
8+
"ban-element-setattribute": [
9+
"../src/cdk/a11y/aria-describer/aria-reference.ts",
10+
"../src/material-experimental/mdc-checkbox/checkbox.ts",
11+
"../src/material-experimental/mdc-list/interactive-list-base.ts",
12+
"../src/material-experimental/mdc-progress-spinner/progress-spinner.ts",
13+
"../src/material-experimental/mdc-slide-toggle/slide-toggle.ts",
14+
"../src/material/icon/icon-registry.ts",
15+
"../src/material/icon/icon.ts"
16+
]
17+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"test": "node ./scripts/run-component-tests.js",
2323
"test-local": "yarn -s test --local",
2424
"test-firefox": "yarn -s test --firefox",
25+
"test-tsec": "yarn bazelisk test //... --build_tag_filters=tsec --test_tag_filters=tsec",
2526
"lint": "yarn -s tslint && yarn -s stylelint && yarn -s ownerslint && yarn -s ng-dev format changed --check",
2627
"e2e": "bazel test //src/... --build_tag_filters=e2e --test_tag_filters=e2e --build_tests_only",
2728
"deploy-dev-app": "node ./scripts/deploy-dev-app.js",
@@ -211,6 +212,7 @@
211212
"stylelint": "^14.0.1",
212213
"terser": "^5.9.0",
213214
"ts-node": "^10.2.1",
215+
"tsec": "0.2.1",
214216
"tsickle": "0.39.1",
215217
"tslint": "^6.1.3",
216218
"tsutils": "^3.21.0",

src/BUILD.bazel

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@ ts_library(
4949
name = "dev_mode_types",
5050
srcs = ["dev-mode-types.d.ts"],
5151
)
52+
53+
ts_config(
54+
name = "tsec_config",
55+
src = "tsconfig-tsec.json",
56+
deps = [
57+
":bazel-tsconfig-build.json",
58+
"//goldens:tsec-exemption.json",
59+
],
60+
)

src/cdk/a11y/focus-monitor/focus-monitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export class FocusMonitor implements OnDestroy {
134134
// Make a note of when the window regains focus, so we can
135135
// restore the origin info for the focused element.
136136
this._windowFocused = true;
137-
this._windowFocusTimeoutId = setTimeout(() => (this._windowFocused = false));
137+
this._windowFocusTimeoutId = window.setTimeout(() => (this._windowFocused = false));
138138
};
139139

140140
/** Used to reference correct document/window */

src/material-experimental/mdc-chips/chip-row.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ export class MatChipRow
167167
}
168168

169169
// Wait to see if focus moves to the other gridcell
170-
this._focusoutTimeout = setTimeout(() => {
170+
this._focusoutTimeout = window.setTimeout(() => {
171171
this._hasFocusInternal = false;
172172
this._onBlur.next({chip: this});
173173
this._handleInteraction(event);

src/tsconfig-tsec.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./bazel-tsconfig-build.json",
3+
"compilerOptions": {
4+
"plugins": [
5+
{"name": "tsec", "exemptionConfig": "../goldens/tsec-exemption.json"}
6+
]
7+
}
8+
}
9+

tools/defaults.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
1212
load("@npm//@bazel/concatjs:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
1313
load("@npm//@bazel/protractor:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
1414
load("@npm//@bazel/typescript:index.bzl", _ts_library = "ts_library")
15+
load("@npm//tsec:index.bzl", _tsec_test = "tsec_test")
1516
load("//:packages.bzl", "NO_STAMP_NPM_PACKAGE_SUBSTITUTIONS", "NPM_PACKAGE_SUBSTITUTIONS")
1617
load("//:pkg-externals.bzl", "PKG_EXTERNALS")
1718
load("//tools/markdown-to-html:index.bzl", _markdown_to_html = "markdown_to_html")
@@ -31,6 +32,17 @@ integration_test = _integration_test
3132
esbuild = _esbuild
3233
esbuild_config = _esbuild_config
3334

35+
def _make_tsec_test(target):
36+
package_name = native.package_name()
37+
if not package_name.startswith("src/components-examples") and \
38+
not package_name.endswith("/testing") and \
39+
not package_name.endswith("/schematics"):
40+
_tsec_test(
41+
name = target + "_tsec_test",
42+
target = target,
43+
tsconfig = "//src:tsec_config",
44+
)
45+
3446
def _compute_module_name(testonly):
3547
current_pkg = native.package_name()
3648

@@ -109,6 +121,9 @@ def ts_library(
109121
**kwargs
110122
)
111123

124+
if module_name and not testonly:
125+
_make_tsec_test(kwargs["name"])
126+
112127
def ng_module(
113128
deps = [],
114129
srcs = [],
@@ -147,6 +162,9 @@ def ng_module(
147162
**kwargs
148163
)
149164

165+
if module_name and not testonly:
166+
_make_tsec_test(kwargs["name"])
167+
150168
def ng_package(name, data = [], deps = [], externals = PKG_EXTERNALS, readme_md = None, visibility = None, **kwargs):
151169
# If no readme file has been specified explicitly, use the default readme for
152170
# release packages from "src/README.md".

yarn.lock

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11272,7 +11272,7 @@ minimalistic-assert@^1.0.0, minimalistic-assert@^1.0.1:
1127211272
resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.1.tgz#2e194de044626d4a10e7f7fbc00ce73e83e4d5c7"
1127311273
integrity sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==
1127411274

11275-
"minimatch@2 || 3", [email protected], minimatch@^3.0.2, minimatch@^3.0.4:
11275+
"minimatch@2 || 3", [email protected], minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4:
1127611276
version "3.0.4"
1127711277
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
1127811278
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
@@ -15658,6 +15658,14 @@ ts-node@^10.2.1:
1565815658
make-error "^1.1.1"
1565915659
yn "3.1.1"
1566015660

15661+
15662+
version "0.2.1"
15663+
resolved "https://registry.yarnpkg.com/tsec/-/tsec-0.2.1.tgz#017423174b2be54f26da5cb7591dc7035996086b"
15664+
integrity sha512-RP9vhbRbRI9VH4CfOlQvo5W9HdfiPKq0gdiUOWI5oKmLaZKNFN8CsPwBfT5ySmhnKNwmmAS/BtY3WoTfABwwig==
15665+
dependencies:
15666+
glob "^7.1.1"
15667+
minimatch "^3.0.3"
15668+
1566115669
1566215670
version "0.39.1"
1566315671
resolved "https://registry.yarnpkg.com/tsickle/-/tsickle-0.39.1.tgz#7ccf672cde5b430f5dd0b281ee49e170ef390ff9"

0 commit comments

Comments
 (0)