-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add eslint-plugin-security
and unify .eslintrc.yml
#4079
Merged
Merged
Conversation
This file contains 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
compulim
requested review from
a-b-r-o-w-n,
beyackle,
cwhitten,
srinaath,
tdurnford and
tonyanziano
as code owners
November 2, 2021 20:03
cwhitten
approved these changes
Nov 2, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog Entry
Added
eslint-plugin-security
, consolidate.eslintrc.yml
at project root, and treat warnings as errors, by @compulim, in PR #4079Description
We are adding new ESLint rules for security, plus some maintenance work around current ESLint configurations.
The new rules added are warnings, but not errors. As security is top priority for us. We will fail on all warnings and requires an explicit explanation to ignore those warnings.
Also, current ESLint configurations scatter in multiple projects, we are consolidating them into a single set of configurations at the project root for easier maintenance.
We also take some time to clean up the configuration files:
@typescript-eslint
(rules and parser) only for.ts
and.tsx
files, but not all files.js
will useeslint:no-unused-vars
, while.ts
will use@typescript-eslint/no-unused-vars
However, we did not resolve #4003, another ESLint related issue, as that one would introduce lot of changes and put a heavier burden to reviewers.
Design
Prevent object injection is square bracket accessors
Using
+index
ESLint has an (easy) alarm on
array[index]
. We turn them intoarray[+index]
to make sure ifindex
is astring
like"prototype"
, we will catch it asNaN
and returnundefined
.Dealing with the issue
In the order of best practices, we should use the following order when applying the protection.
map[key]
['one', 'two'].map(key => map[key])
, use the declarative form[map.one, map.two]
storage[theirKey]
, usestorage['id-' + theirKey]
ourMap[theirKey]
, try to protect it byObject.keys(ourMap).includes(theirKey) && ourMap[theirKey]
prototype
and everything fromObject.prototype
isForbiddenPropertyNames
exposed fromcore
packages will help denylistingHoisting
eslint
family of packages to the project rootESLint resolves dependencies based on where the
.eslintrc.yml/plugin
is defined. As many of our packages are extending it from the project root.eslintrc.yml
, we need to puteslint-plugin-*
at the root, where ESLint will resolve them from.We are removing
eslint*
packages from our individual package, and hoist them to the project root.One exception is
directlinespeech
as we try our best to isolate it out of our monorepo story and make it easy to eject.Converging into a single
.eslintrc.yml
We attempted to converge all ESLint configurations into a single
.eslintrc.yml
and use file extension approach to differentiate them. Say,.jsx
will have React ruleset enabled, etc. But we failed to do so because:.js
files are custom hooks and should have React ruleset enabled for them.js
files are CJS and some are ESM, requires slightly different modification to the configuration (i.e.parserOptions
)To-do
--report-unused-disable-directives
to ESLint--max-warnings 0
to ESLinteslint-plugin-security
.eslintrc.yml
CHANGELOG.md
Specific Changes
--report-unused-disable-directives
)--max-warnings 0
)eslint-plugin-security/recommended
eslint
and related dependencies is now installed at root, instead of per packagedirectlinespeech
, which we want to make it easily eject-able from our monorepo.eslintrc.yml
into 3 versions located at the root.eslintrc.yml
is the base configuration and platform neutral.ts
,.tsx
) and Jest (__tests__
,*.spec.js
,*.spec.ts
).eslintrc.react.yml
is for projects with React or React Hooks.eslintrc.node.yml
is for CLI projectsno-undefined
rulenpm run prettier
scriptevent-target-shim
page-object/src/globals/testHelpers/speech/speechSynthesis/MockAudioContext.js
CHANGELOG.md
I have updated documentationReview Checklist
Accessibility reviewed (tab order, content readability, alt text, color contrast)Browser and platform compatibilities reviewedCSS styles reviewed (minimal rules, noz-index
)Documents reviewed (docs, samples, live demo)Internationalization reviewed (strings, unit formatting)package.json
andpackage-lock.json
reviewed