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

fix(unsafe-import): warning on unsafe-import using eval/require #190

Merged
merged 9 commits into from
Jan 12, 2024

Conversation

tchapacan
Copy link
Contributor

@tchapacan tchapacan commented Dec 18, 2023

fix #179

Warning on unsafe-import using eval/require

const stream = eval('require')('stream')

should return unsafe-import & unsafe-eval ?

Purpose of this PR is to propose a fix for the issue #179 by mdofifying probes isRequire & isUnsafeCallee :

  • modify probe isRequire
  • modify probe isUnsafeCallee
  • add tests
  • documentation

Feel free to update it or give any feedback i'll be happy to try to improve it (this is my first real PR 😄 i'm new to the environment so I didn't dig deeper yet sorry, but don't hesitate to give any suggestion to improve it)

Result after :

import { runASTAnalysis } from "./index.js";

const result = runASTAnalysis(`
const stream = eval('require')('stream')
`);

console.log(result);
➜  js-x-ray git:(fix/179) ✗ node test.js
{
  idsLengthAvg: 6,
  stringScore: 0,
  warnings: [
    {
      kind: 'unsafe-stmt',
      location: [Array],
      source: 'JS-X-Ray',
      value: 'eval',
      code: 'unsafe-stmt',
      i18n: 'sast_warnings.unsafe_stmt',
      severity: 'Warning'
    },
    {
      kind: 'unsafe-import',
      location: [Array],
      source: 'JS-X-Ray',
      value: 'stream',
      i18n: 'sast_warnings.unsafe_import',
      severity: 'Warning'
    }
  ],
  dependencies: Map(1) {
    'stream' => { unsafe: true, inTry: false, location: [Object] }
  },
  isOneLineRequire: true
}

src/utils.js Outdated Show resolved Hide resolved
test/probes/isUnsafeImport.spec.js Outdated Show resolved Hide resolved
src/probes/index.js Outdated Show resolved Hide resolved
src/probes/isRequire.js Outdated Show resolved Hide resolved
src/probes/isRequire.js Outdated Show resolved Hide resolved
src/probes/isRequire.js Outdated Show resolved Hide resolved
src/probes/isRequire.js Outdated Show resolved Hide resolved
src/probes/isRequire.js Outdated Show resolved Hide resolved
src/probes/isUnsafeCallee.js Outdated Show resolved Hide resolved
src/utils.js Outdated Show resolved Hide resolved
src/probes/isRequire.js Outdated Show resolved Hide resolved
@tchapacan tchapacan marked this pull request as ready for review January 8, 2024 19:10
@tchapacan
Copy link
Contributor Author

I have updated the PR according to your comments, again thanks a lot lot for your help and your time, I couldn't have done it without your help ! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Properly detect eval("require") as require
2 participants