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

Update S1523 (code-eval): merge ESLint no-script-url #4037

Merged
merged 3 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"backbone:backbone.js": [
1875
],
"backbone:index.html": [
5252
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"es5-shim:es5-sham.js": [
255
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jStorage:example/index.html": [
82
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
],
"javascript-test-sources:src/ace/tool/mode_creator.js": [
214
],
"javascript-test-sources:src/ecmascript6/Ghost/core/client/app/components/gh-skip-link.js": [
16
],
"javascript-test-sources:src/ecmascript6/Ghost/core/client/tests/integration/components/gh-navitem-url-input-test.js": [
293
]
}
5 changes: 5 additions & 0 deletions src/linting/eslint/rules/code-eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@

import { Rule } from 'eslint';
import * as estree from 'estree';
import { eslintRules } from 'linting/eslint/rules/core';

const noScriptUrlRule = eslintRules['no-script-url'];

export const rule: Rule.RuleModule = {
meta: {
messages: {
safeCode: 'Make sure that this dynamic injection or execution of code is safe.',
unexpectedScriptURL: "Make sure that 'javascript:' code is safe as it is a form of eval().",
},
},
create(context: Rule.RuleContext) {
Expand All @@ -35,6 +39,7 @@ export const rule: Rule.RuleModule = {
checkCallExpression(node as estree.CallExpression, context),
NewExpression: (node: estree.Node) =>
checkCallExpression(node as estree.CallExpression, context),
...noScriptUrlRule.create(context),
};
},
};
Expand Down
4 changes: 4 additions & 0 deletions tests/linting/eslint/rules/code-eval.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,9 @@ ruleTester.run('Dynamically executing code is security-sensitive', rule, {
code: `new Function('a', x)`,
errors: 1,
},
{
code: `location.href = 'javascript: void(0)';`,
errors: 1,
},
],
});