InspectJS: Leveraging Code Similarity and User-Feedback for Effective Taint Specification Inference for JavaScript

Saikat Dutta, Diego Garbervetsky, Shuvendu K. Lahiri, Max Schäfer

TL;DR

InspectJS is a new tool that automates the discovery of security "sinks" (vulnerable points in code) in JavaScript libraries by combining probabilistic machine learning with code-similarity metrics. By putting a human-in-the-loop with a "ban similar" feedback mechanism, it reduces the manual effort of triaging potential vulnerabilities by up to 3x compared to previous automated methods.

What Problem Does This Paper Address?

Static taint analysis is a cornerstone of modern security. It tracks the flow of data from untrusted sources (like a URL parameter) to sensitive sinks (like a database query or a file system call). If data reaches a sink without being "sanitized," you have a vulnerability like SQL injection or Cross-Site Scripting (XSS).

The bottleneck? JavaScript has a massive, ever-evolving ecosystem of third-party libraries. Security engineers usually have to write "taint specifications" for these libraries by hand—a tedious, error-prone process that can't possibly keep up with npm's growth. While machine learning (ML) has been used to predict these specifications automatically, the results are often "noisy," burying engineers under thousands of false positives.

Methods

The authors introduce InspectJS, a pipeline built on top of GitHub’s CodeQL analysis framework. It uses a three-pronged approach:

  1. Seldon*: An adaptation of the Seldon algorithm. It mines thousands of open-source projects to find "triples" (Source, Sanitizer, Sink). It then uses probabilistic inference to guess which library functions are likely sinks based on how they are used in relation to known sources and sanitizers.
  2. Similarity-Based Refiner: This is the "secret sauce." Using GraphCodeBERT (a transformer model trained on code), InspectJS compares predicted sinks to a corpus of known, manually-modeled sinks. If a predicted sink "looks" syntactically and contextually like a known one, its confidence score is boosted.
  3. Feedback-Based Refiner: Recognizing that ML isn't perfect, the authors built a UI that allows a security engineer to triage predictions. A key feature is the "ban similar" button: if an engineer identifies a false positive, the tool can automatically hide all other predictions that are syntactically similar, drastically speeding up the review process.

Datasets

The researchers leveraged the massive scale of LGTM.com, querying roughly 200,000 GitHub projects. From this pool, they identified subsets of projects relevant to three major vulnerability types:

  • TaintedPath: 562 projects.
  • XSS (Cross-Site Scripting): 2,834 projects.
  • NoSQLInjection: 833 projects.

They used these to train their models and evaluated the results against the existing, manually-curated CodeQL standard library models.

Key Insights and Ideas

  • Context is King: A function isn't just a sink because of its name; it's a sink because of the context in which it appears. By using GraphCodeBERT, InspectJS captures the "vibe" of a code snippet, helping distinguish a legitimate database call from a harmless log statement.
  • The Power of Multi-Dismissal: The biggest hurdle in ML for security isn't finding the "true positives"—it's the sheer volume of "false positives." The "ban similar" feature treats false positives as clusters rather than individual points, allowing a human to prune the search space exponentially faster.
  • Complementary, Not Competitive: The authors don't try to replace manual modeling. Instead, they use ML as a "driver" to find gaps in existing models. In fact, their work led to several pull requests that improved the official CodeQL JavaScript models.

Key Results

  • New Vulnerabilities Found: InspectJS successfully identified dozens of new sinks that were missing from CodeQL’s manual models. For example, it found 56 new true-positive sinks for TaintedPath and 187 for NoSQL Injection.
  • Efficiency Gains: The similarity-based filtering and UI features reduced the number of steps required to triage results by roughly 3x. For NoSQL Injection, the number of manual steps dropped from 666 to 243.
  • High Recall: In experiments "boosting" older versions of security queries, InspectJS was able to recover a high percentage of the alerts found in the latest manual versions, proving it can effectively anticipate the work of human experts.

Limitations and Future Work

While effective, InspectJS still produces a high volume of false positives that require a human expert to filter. The authors noted that for XSS, the similarity metrics were less effective because many harmless UI functions look very similar to dangerous ones.

Future work includes extending the tool to infer source and sanitizer specifications (currently it focuses primarily on sinks) and exploring "abductive inference" to further refine library models. The team also aims to integrate these techniques more deeply into the developer workflow to catch missing specifications as soon as a new library becomes popular.

Summary updated

BibTeX
@inproceedings{dutta2022inspectjs,
  author = {Saikat Dutta and Diego Garbervetsky and Shuvendu K. Lahiri and Max Schäfer},
  title = {{InspectJS: Leveraging Code Similarity and User-Feedback for Effective Taint Specification Inference for JavaScript}},
  booktitle = {ICSE (SEIP)},
  year = {2022},
  doi = {10.1109/icse-seip55303.2022.9794015},
}
Figure