POSTER: Using Unit Testing to Detect Sanitization Flaws

Mahmoud Mohammadi, Bill Chu, Heather Richter LipfordCCS 2015

TL;DR

This paper introduces a novel unit testing approach to automatically detect flaws in web application sanitization functions, specifically for Cross-Site Scripting (XSS) vulnerabilities. By combining static and dynamic analysis techniques, their method generates attack vectors and evaluates sanitization correctness at development time, aiming to catch security bugs that traditional static analysis tools miss.

What Problem Does This Paper Address?

Web applications often rely on input sanitization to prevent security vulnerabilities like Cross-Site Scripting (XSS). These attacks occur when untrusted user input, containing malicious scripts, is not properly handled before being displayed or used in sensitive parts of the application (sinks). While static analysis tools can check if sanitization functions are used, they struggle to verify their correctness. Correctness here is tricky: it depends on the specific context where the input is used (e.g., HTML, JavaScript) and the order in which multiple sanitization functions are applied. Incorrect sanitization can lead to vulnerabilities even when sanitizers are present, and the paper highlights issues like context inconsistency and incorrect function ordering as common problems.

Methods

The authors propose an automated approach integrated into an IDE as a plug-in. This system performs three main steps:

  1. Attack Generation: It automatically generates attack vectors tailored to the specific application under test. This goes beyond using generic attack repositories by analyzing the injection point's context to create inputs that are likely to exploit vulnerabilities. The goal is to achieve a near-zero false negative rate for attack vector generation.
  2. Sanitization Path Extraction: Using static analysis techniques like dataflow and control flow analysis, the system identifies and models the sequences of sanitization functions applied to untrusted input sources as they travel towards sensitive sinks. This creates a "sanitization path" for each input.
  3. Attack Evaluation: The generated attack vectors are then used to test the extracted sanitization paths. This involves executing the attack scripts, often by simulating user interactions, to see if they can bypass the sanitization and reach a sensitive sink. The evaluation is performed within a unit-testing framework like JUnit.

Datasets

Not discussed in the paper. The authors mention applying their approach to an open-source web-based medical application called "iTrust" and a conceptual example.

Key Insights and Ideas

  • Unit Testing for Security: The core idea is to leverage the developer-centric nature of unit testing to catch security flaws early in the development lifecycle, rather than relying solely on later-stage testing or manual code reviews.
  • Context-Sensitive Sanitization is Crucial: The paper emphasizes that sanitization is not a one-size-fits-all solution. The effectiveness of a sanitizer depends heavily on the specific context (HTML, JavaScript, etc.) in which the data will be rendered or interpreted.
  • Order Matters: The sequence in which sanitization functions are applied can significantly impact their effectiveness. An incorrect order can render a sanitizer useless or even introduce new vulnerabilities.
  • Bridging Static and Dynamic Analysis: The approach aims to combine the strengths of static analysis (identifying sanitization paths) with dynamic analysis (executing attacks to verify correctness) within a unified framework.

Key Results

The authors report successful detection of a "zero-day vulnerability" in the iTrust medical application. This vulnerability involved an untrusted input used in a JavaScript context that was sanitized using an HTML escaping function, which was insufficient for the target context. They also demonstrated the detection of a conceptual example illustrating browser transduction issues due to incorrect sanitization ordering.

Limitations and Future Work

  • Current Limitations: The current implementation focuses on server-side functions and only analyzes string-type untrusted sources.
  • Future Work: The authors suggest that their approach can be fully integrated into IDEs as a development-time plugin, complementing static analysis and ensuring sanitization correctness. They also mention the need to adjust the integration to satisfy agile software development life cycle requirements. The paper also implicitly points to the need for handling more complex input types and client-side sanitization in future work.

Summary updated

BibTeX
@inproceedings{mohammadi2015poster,
  author = {Mahmoud Mohammadi and Bill Chu and Heather Richter Lipford},
  title = {{POSTER: Using Unit Testing to Detect Sanitization Flaws}},
  booktitle = {CCS},
  year = {2015},
  doi = {10.1145/2810103.2810130},
}
Figure