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

False positive for detect-non-literal-fs-filename #54

Closed
freaktechnik opened this issue Oct 12, 2019 · 11 comments
Closed

False positive for detect-non-literal-fs-filename #54

freaktechnik opened this issue Oct 12, 2019 · 11 comments

Comments

@freaktechnik
Copy link

detect-non-literal-fs-filename seems to also be triggered when passing fs.writeFile to other functions, especially explicitly safe ones like util.promisify.

The message is also quite wrong ("Found fs.writeFile with non literal argument at index 0") while the actual warning is more that it's being passed in to a function and who knows what that function does with it?

@mikecbrant
Copy link

+1 on this issue.

Code to reproduce...

import fs from 'fs';
import { promisify } from 'util';

const readFile = promisify(fs.readFile);

@FelixRe0
Copy link

+1
Seems to also false positive on a variable with a .link key
Found fs.link with non literal argument at index 1 security/detect-non-literal-fs-filename
ie:
console.log('this should not be an issue', item.link)

@cope
Copy link

cope commented Jul 15, 2020

Also
Found fs.truncate with non literal argument at index 0
_.truncate(item.description, {...

@modestfake
Copy link

It also false positive for any function with name which overlaps with fs method names:

const id = '123'

const obj = {
  readFile() {
    return 1
  },
  writeFile() {
    return 2
  },
}

obj.readFile(id) // Yields here
obj.writeFile(id) // and here

@Deepesh316
Copy link

Any fix for the same?

@alvaroinckot
Copy link

+1 on this issue.

@jesusprubio
Copy link
Contributor

Summary
False positive for any function with name which overlaps with fs method names. Examples:

Still relevant?
Yes.

Next steps

  • Work in a fix

@jesusprubio
Copy link
Contributor

Verified with the actual version and this snippet:

const fs = require('fs');
const { promisify } = require('util');

const readFile = promisify(fs.readFile);

Versions:

  • Node: 16.14.0
  • ESLint: 8.11.0
  • eslint-plugin-security: 1.4.0

@revelt
Copy link

revelt commented Jul 5, 2022

PR raised

@ota-meshi
Copy link
Member

I believe this issue has been fixed in the latest version.
https://github.com/eslint-community/eslint-plugin-security/releases/tag/v1.6.0
It was fixed by PR #92.

@nzakas
Copy link
Contributor

nzakas commented Jan 12, 2023

Yup, you're correct. Thanks!

@nzakas nzakas closed this as completed Jan 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet