Comments (6)
Great, thanks, I'll take a look.
from eslint-plugin-security.
when I paste
eval("some nefarious code");
into my editor I don't see an error in ESLint Output like you said. It's only when I type it out and ESLint then fails when I typeeval()
.
Ah okay. So what's happening here is that VS Code is running ESLint on incomplete code, meaning that it appears eval()
doesn't have any arguments and that's why you're seeing the error.
eval("some nefarious code")
does not trigger the detect-eval-with-expression
rule because the argument is a literal. The rule specifically warns against expressions in eval()
.
If you want to enforce not using eval
in general, then you should enable the core no-eval
rule.
from eslint-plugin-security.
Can you try with the default ESLint parser? typescript-eslint
produces a different AST and sometimes there are differences that can cause errors.
from eslint-plugin-security.
@nzakas, yes. I tried and it resulted in the same error:
[Info - 9:32:49 AM] ESLint server is starting.
[Info - 9:32:50 AM] ESLint server running in node v18.17.1
[Info - 9:32:50 AM] ESLint server is running.
[Info - 9:32:59 AM] ESLint library loaded from: /Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/unsupported-api.js
Pages directory cannot be found at /Users/stickb/Code/dos/lighthouse/pages or /Users/stickb/Code/dos/lighthouse/src/pages. If using a custom path, please configure with the `no-html-link-for-pages` rule in your eslint config file.
[Error - 11:15:40 AM] An unexpected error occurred:
[Error - 11:15:40 AM] TypeError: Cannot read properties of undefined (reading 'type')
Occurred while linting /Users/stickb/Code/dos/lighthouse/core/src/index.server.ts:11
Rule: "security/detect-eval-with-expression"
at CallExpression (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint-plugin-security/rules/detect-eval-with-expression.js:25:62)
at ruleErrorHandler (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1076:28)
at /Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
at /Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1111:32
[Error - 11:17:40 AM] An unexpected error occurred:
[Error - 11:17:40 AM] TypeError: Cannot read properties of undefined (reading 'type')
Occurred while linting /Users/stickb/Code/dos/lighthouse/core/src/test.js:1
Rule: "security/detect-eval-with-expression"
at CallExpression (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint-plugin-security/rules/detect-eval-with-expression.js:25:62)
at ruleErrorHandler (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1076:28)
at /Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:58
at Array.forEach (<anonymous>)
at Object.emit (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
at NodeEventGenerator.applySelector (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
at NodeEventGenerator.applySelectors (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
at NodeEventGenerator.enterNode (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
at CodePathAnalyzer.enterNode (/Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:803:23)
at /Users/stickb/Code/dos/lighthouse/node_modules/.pnpm/[email protected]/node_modules/eslint/lib/linter/linter.js:1111:32
Notice above, I first tried with a TS file, it failed, then I tried with a JS file (commented out TS parser in eslint.config.js) but it still failed.
from eslint-plugin-security.
Okay, so the only way I've been able to reproduce this error is by linting eval()
(no arguments). The example you gave works just fine in all of the configurations I tried. It shouldn't crash in this case, for sure, but it makes me curious what is going on with your case.
Would it be possible for you to create a Stackblitz to reproduce the problem? I'd like to see it in action if possible.
from eslint-plugin-security.
@nzakas, when I paste eval("some nefarious code");
into my editor I don't see an error in ESLint Output like you said. It's only when I type it out and ESLint then fails when I type eval()
.
But, when I paste eval("some nefarious code");
into VS Code, I don't see any ESLint warning/error saying that I shouldn't use eval
in my code which is what I'd expect. See screenshot below how ESLint is correctly linting for rule, no-compare-neg-zero
, but it's not working for detect-eval-with-expression
.
In your testing, was the linting rule correctly working? (besides just not erroring out)
from eslint-plugin-security.
Related Issues (20)
- docs: maybe an error in the-dangers-of-square-bracket-notation HOT 1
- Bug: object injection not detected HOT 2
- A Suggestion for the Docs HOT 2
- New Rule: Detect invisible characters
- New Rule: disallow unicode confusable identifiers HOT 4
- Bug: `security/detect-non-literal-regexp` should ignore `escapeStringRegexp()` HOT 1
- Bug: `security/detect-object-injection` should be ignored when property is switch case discriminant. HOT 2
- `security/detect-object-injection` false alarm on type safe key HOT 5
- Rule Change: (fill in) HOT 2
- Bug: Crashes ESLint due to circular reference in config HOT 4
- Bug: Converting circular structure to JSON when running eslint HOT 2
- Upgrade causes obscure error HOT 4
- Bug: false positive for security/detect-object-injection HOT 2
- Bug: Configuration using JSON eslintrc file HOT 2
- Add support for flat config and types HOT 1
- ESLint v9 compatibility (TypeError: context.getScope is not a function) HOT 8
- Bug: (fill in) HOT 1
- Does This Plugin Support TypeScript? HOT 5
- Bug: no type definitions for eslint flat config HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-security.