Skip to content

Comments

JS: add js/path-injection-from-library-input query#8429

Closed
kaeluka wants to merge 12 commits intogithub:mainfrom
kaeluka:js/CVE-2022-24718-new-sources
Closed

JS: add js/path-injection-from-library-input query#8429
kaeluka wants to merge 12 commits intogithub:mainfrom
kaeluka:js/CVE-2022-24718-new-sources

Conversation

@kaeluka
Copy link

@kaeluka kaeluka commented Mar 14, 2022

This PR adds library inputs as taint sources. It is related to a current CVE that we did miss partially due to these sources missing [1]. However, as there's a lot of library inputs, it's important to discuss whether this should be merged or not.

I've started an LGTM experiment comparing the results of the main branch with those of adding this PR's changes and the changes of #8430. Find the results here: baseline / patched.

For example, the patched version (due to the new input sources) finds lots of results in alibaba/ice that are not found in the baseline. In my opinion, those are good results that I'd appreciate as a developer. But I have a gut feeling that the team might consider these too noisy. Discuss! :)

[1] - The other part is a missing taint step that I'll be contributing in another PR #8430.

@github-actions github-actions bot added the JS label Mar 14, 2022
@kaeluka kaeluka marked this pull request as ready for review March 14, 2022 12:16
@kaeluka kaeluka requested a review from a team as a code owner March 14, 2022 12:16
@owen-mc owen-mc changed the title add library input as tainted-path sources JS: add library input as tainted-path sources Mar 15, 2022
@asgerf
Copy link
Contributor

asgerf commented Mar 15, 2022

I used this LGTM run to show just the new alerts, which was easier to triage. After looking through these results I couldn't find any results that I would consider a TP 😕

The input parameter/property often has a name that indicates it is intended to be a path, such as cwd, filepath, or something that ends with file or path.

Sometimes the fact that the input is interpreted as a path is explained by a documentation comment, for example for pm2_home:

/**
*  @param {String}  [opts.pm2_home=[<paths.js>]] pm2 directory for log, pids, socket files
*/

If we're going to go ahead with this, the first thing to do is to avoid inputs that are clearly intended to be interpreted as paths.

Overall:

  • Implement as a separate query.
  • Adjust metadata in the new query (@precision warning) and make the description and alert messaging clearly indicate that this is library input, not user data.
  • Use sanitizers to implement name filters for properties. For example opts.cwd could be a sanitizer. Such property accesses can occur arbitrarily far away from the source, so it's more effective than simply trying to filter out sources.

@kaeluka
Copy link
Author

kaeluka commented Mar 24, 2022

  • Implement as a separate query.
  • Adjust metadata in the new query (@precision warning) and make the description and alert messaging clearly indicate that this is library input, not user data.

That feedback was really valuable! I hadn't considered the option to create a new, lower precision query 🙈. Thank you 👍.
I believe I have found another CVE we have missed where the source is a library input. I'll look at some more candidate CVEs to see if there is a pattern. Then I'll adapt this PR to my learnings.

@kaeluka
Copy link
Author

kaeluka commented Mar 25, 2022

Converted the query to a standalone warning query; name filters still missing

@kaeluka kaeluka marked this pull request as draft March 28, 2022 08:35
@kaeluka kaeluka marked this pull request as ready for review March 31, 2022 07:47
@erik-krogh erik-krogh changed the title JS: add library input as tainted-path sources JS: add js/path-injection-from-library-input query Mar 31, 2022
@kaeluka
Copy link
Author

kaeluka commented Mar 31, 2022

I added one more commit that filters out sinks that are parameters that have an @param comment which mentions the parameter is a file/path/etc.

Copy link
Contributor

@erik-krogh erik-krogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't taken a detailed look at the implementation/documentation yet, but I did find a few things that jumped out.

I tried to investigate all the new results from your evaluation, and I could categorize the projects as follows:

  • documented/intentional behavior: 3
  • test code: 2
  • build-script: 1
  • maybe a bit interesting: 1

That's not a great TP rate.

The interesting result I found follow the source -> path construction -> path sink-pattern that is also used by e.g. js/shell-command-constructed-from-input, so we might be able to use that to cut down on the FPs.

Also, you need to copy this code to cut down some other FPs.

@kaeluka
Copy link
Author

kaeluka commented Apr 25, 2022

rebased onto main because the "Check synchronized files / sync (pull_request)" test used to be broken, but has now been fixed in main.

@kaeluka kaeluka marked this pull request as draft May 9, 2022 12:50
@kaeluka
Copy link
Author

kaeluka commented May 23, 2022

Have gotten a lot of failed DCA runs on this and the work got side tracked by other tasks I was working on. Picking up again now.

@kaeluka kaeluka closed this by deleting the head repository Aug 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants