Automated Detecting and Repair of Cross-Site Scripting Vulnerabilities

Mahmoud Mohammadi, Bei-Tseng Chu, Heather Richter LipfordarXiv 2018

Introduction

Cross-Site Scripting (XSS) remains one of the most persistent and dangerous security threats to web applications. The standard defense—encoding untrusted data before rendering—is deceptively difficult to implement correctly because it is highly context-sensitive. An encoder suitable for an HTML body may fail if the data is placed within a JavaScript attribute or a CSS block. Existing tools, such as static analysis or black-box scanners, often struggle with high false-positive rates or poor coverage. This paper introduces an automated framework that leverages security unit testing to bridge this gap, detecting and repairing XSS vulnerabilities with high precision.

Methodology

The proposed framework utilizes a four-stage pipeline designed to identify, verify, and fix vulnerabilities by combining static and dynamic analysis.

Overview of the automated XSS detection and repair pipeline.
  1. Unit Test Construction: The system uses static analysis on JavaServer Pages (JSP) to map "sources" (user inputs) to "sinks" (output locations). It generates standalone Java unit tests for every identified execution path.
  2. Attack Generation: Rather than relying on static payload lists, the tool uses a grammar-based generator. By employing Context-Free Grammars (CFG) for HTML, CSS, URI, and JavaScript, it creates syntactically correct payloads tailored to trigger execution in specific web contexts.
  3. Attack Evaluation (Dynamic Analysis): The generated unit tests are executed in a headless browser (JWebUnit). A vulnerability is only confirmed if the payload successfully executes (e.g., triggers a script), effectively eliminating false positives.
  4. Automatic Repair: For confirmed vulnerabilities, the tool iteratively tests a candidate list of industry-standard encoders (e.g., OWASP ESAPI). It identifies the specific encoder that neutralizes the attack while maintaining the application's intended functionality.

Evaluation and Results

The framework was evaluated using iTrust, an open-source medical records application comprising 112,000 lines of code and 235 JSP files. The results were compared against the industry-standard scanner, OWASP ZAP.

  • Zero-Day Discovery: The tool discovered 24 previously unreported vulnerabilities in iTrust.
  • High Precision: The system achieved a 0% false positive rate, as every report was backed by a successful dynamic execution. In contrast, OWASP ZAP exhibited a 91% false positive rate and missed 14 vulnerabilities caught by this approach.
  • Efficiency: Testing a JSP page with no vulnerabilities took approximately 8.2 minutes, while evaluating a single unit test averaged 17 seconds, making it feasible for integration into development workflows.

Key Insights

  • Contextual Awareness: The primary cause of many XSS vulnerabilities is not a lack of security measures, but the misapplication of encoders (e.g., using HTML encoding for a JavaScript context).
  • Dynamic Verification: By treating "execution as truth," the framework avoids the guesswork of static analysis. If a script runs in the headless browser, the vulnerability is undeniable.
  • Security as a Bug-Fix: The automated repair phase transforms security reports into actionable code fixes, providing developers with verified solutions rather than just alerts.

Limitations and Future Work

While effective, the current implementation is limited to server-side JSP and cannot fix vulnerabilities requiring structural logic changes. Future work will focus on extending analysis to modern Single Page Applications (SPAs) that rely heavily on client-side JavaScript and AJAX, as well as optimizing performance for highly complex pages with numerous input variables.

Summary updated

BibTeX
@misc{mohammadi2018automated,
  author = {Mahmoud Mohammadi and Bei-Tseng Chu and Heather Richter Lipford},
  title = {{Automated Detecting and Repair of Cross-Site Scripting Vulnerabilities}},
  year = {2018},
  eprint = {1804.01862},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1804.01862},
}
Figure