Statically locating web application bugs caused by asynchronous calls

Yunhui Zheng, Tao Bao, Xiangyu ZhangWWW 2011 · DOI

TL;DR

This paper introduces a static analysis technique to automatically detect subtle bugs in web applications caused by asynchronous JavaScript (Ajax) calls. By modeling these issues as specialized data race and atomicity violation problems, their approach can find real-world bugs in complex web applications without requiring execution.

What Problem Does This Paper Address?

Modern web applications heavily rely on Ajax to provide a smooth, responsive user experience by allowing asynchronous communication with the server. However, this asynchronous nature introduces a new class of bugs: non-deterministic behavior. When user actions and server responses can interleave in unexpected ways, it can lead to situations where the user interacts with outdated data ("what you operate on is not what you see"), or where operations that should be atomic are broken, leading to runtime exceptions. Traditional debugging and testing methods struggle with these issues because they often depend on specific execution orders that are hard to reproduce. This paper aims to automatically detect these specific types of bugs using static analysis.

Methods

The core of the paper is a static program analysis designed to detect two main problems:

  • Inconsistency: This is framed as a data race where a response handler (which runs asynchronously) might update a global variable after a user action has already read it to compose a new request. The analysis identifies situations where a user action's request uses a global variable that is later modified by an Ajax response handler before that response is fully processed.
  • Atomicity Violation: This occurs when an Ajax request and its corresponding response handler are interrupted by another event handler, breaking the intended atomicity. The analysis looks for scenarios where a request, its response, and an intervening event handler all access the same variable, potentially leading to errors.

To achieve this, the authors developed a system that:

  1. Extracts Client-Side JavaScript: Since JavaScript is often embedded within server-side scripts (like PHP), they created a technique to extract the client-side JavaScript code by analyzing server-side code paths. This involves rewriting server scripts to guide execution and generate all relevant client-side pages.
  2. Performs Static Analysis: They leverage the WALA (Watson Libraries for Analysis) framework to build call graphs, control flow graphs, and perform points-to analysis on the extracted JavaScript.
  3. Uses Datalog for Analysis: The core logic for detecting inconsistency and atomicity violations is expressed using Datalog, a declarative logic programming language. This allows for a formal and systematic way to define and infer the buggy conditions.

Datasets

The paper evaluates their technique on a set of real-world web applications, including:

  • Ajallerix (online image gallery)
  • AjaxLogin (secure login plug-in)
  • XHTML Chat (online chatting plug-in)
  • Ajax File Browser
  • Tixean chat
  • Phormer (PHP PhotoGallery)
  • Quizzy (PHP AJAX quiz library)
  • Rogozhka chat

They also analyze a portion of the MSN website. The paper does not introduce a new benchmark dataset but rather uses existing, publicly available web applications.

Key Insights and Ideas

  • Ajax Bugs as Data Races/Atomicity Violations: The key insight is reframing complex, non-deterministic Ajax bugs into more traditional concurrency problems (data races and atomicity violations), which can then be tackled with static analysis techniques.
  • Server-Side Script Analysis for JS Extraction: The ability to extract client-side JS from server-side scripts is crucial for analyzing modern, dynamically generated web applications. Their approach of rewriting PHP to guide execution is a novel way to achieve this.
  • Datalog for Expressing Analysis Rules: Using Datalog provides a clear, formal, and scalable way to define the complex inference rules needed for static analysis, especially for intricate program properties like data dependencies and potential race conditions.
  • Focus on Global Variables: The analysis specifically targets global variables, as these are common points of interaction and potential conflict in JavaScript, especially in the context of asynchronous operations.

Key Results

The authors evaluated their system on several real-world web applications and found it to be effective:

  • Their technique successfully identified a number of real bugs, including inconsistency and atomicity violation problems.
  • The analysis was performed automatically and did not require running the web applications.
  • The extraction process generated a reasonable number of client pages for analysis, and the analysis itself was performed within a practical time frame (average analysis time per client page was typically under 10 seconds, with a maximum of 12.53 seconds for the Ajax File Browser).
  • They reported a small number of false positives, which they attribute to the analysis exploring infeasible paths or interleavings that are unlikely to occur in practice.

Limitations and Future Work

  • False Positives: The authors acknowledge that their system produces some false positives. These arise primarily from two scenarios:
  • The analysis might extract client pages that combine event handlers that would never appear together in a real user interaction scenario.
  • The analysis might identify interleavings that are not feasible due to the inherent execution flow of the application (e.g., an Ajax request that is only meant to initialize a page). They suggest using symbolic execution to prune infeasible paths and analyzing "happens-before" relations to reduce false positives from infeasible interleavings.

  • Library Support: While they support popular JavaScript libraries (jQuery, Prototype, YUI), their technique does not analyze the internal code of these libraries, relying instead on interface abstractions.

  • Atomicity Violation Rules Omitted: The paper mentions that the rules for detecting atomicity violations are omitted due to space limitations, suggesting this is an area that could be further detailed.
  • Manual Confirmation: All reported bugs were manually confirmed by the authors, indicating that while the tool finds potential bugs, human verification is still necessary.

Summary updated

BibTeX
@inproceedings{zheng2011statically,
  author = {Yunhui Zheng and Tao Bao and Xiangyu Zhang},
  title = {{Statically locating web application bugs caused by asynchronous calls}},
  booktitle = {The Web Conference},
  year = {2011},
  doi = {10.1145/1963405.1963517},
}
Figure