NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Information Flow Analysis for a Dynamically Typed Language with Staged Metaprogramming

Martin Mariusz Lester, C.-h. Luke Ong, Max Schaefer2013

Abstract

Web applications written in JavaScript are regularly used for dealing with sensitive or personal data. Consequently, reasoning about their security properties has become an important problem, which is made very difficult by the highly dynamic nature of the language, particularly its support for runtime code generation. As a first step towards dealing with this, we propose to investigate security analyses for languages with more principled forms of dynamic code generation. To this end, we present a static information flow analysis for a dynamically typed functional language with prototype-based inheritance and staged metaprogramming. We prove its soundness, implement it and test it on various examples designed to show its relevance to proving security properties, such as noninterference, in JavaScript. To our knowledge, this is the first fully static information flow analysis for a language with staged metaprogramming, and the first formal soundness proof of a CFA-based information flow analysis for a functional programming language.

Introduction

Securing modern web applications is a significant challenge due to the pervasive use of JavaScript. The language's dynamic features, most notably the eval function, allow for the execution of arbitrary strings as code, creating a "dynamic nightmare" for traditional static analysis. Proving that sensitive data—such as user passwords—does not leak to untrusted third parties becomes nearly impossible when the code structure itself can change at runtime.

This research addresses this problem by proposing a more structured approach to dynamic code generation: staged metaprogramming. By replacing raw string evaluation with principled code manipulation, we can establish a formal foundation for verifying security properties like noninterference.

The SLamJS Framework

The authors introduce SLamJS (Staged Lambda JS), a functional language designed to capture the core semantics of JavaScript, including prototype-based inheritance, while introducing structured metaprogramming constructs:

  • box: Quotes an expression, treating it as a first-class code value.
  • unbox: Splices a boxed expression into a larger code template.
  • run: Executes a boxed value within the current environment.

Static Analysis via 0CFA

To analyze SLamJS programs, the researchers utilize a constraint-based 0-length Control Flow Analysis (0CFA). This analysis approximates the set of values that can flow to various program points. The abstract domains for this analysis, including caches (Γ) and environments (ρ), are formally defined to track the movement of abstract values like functions, boxes, and records.

Definitions of abstract values, variables, caches, and environments used in the 0CFA framework.

Information Flow Analysis

Building upon the 0CFA foundation, the framework layers an information flow analysis that tracks dependencies between program labels. It distinguishes between two types of information leaks:

  1. Direct Flows: Occur through explicit data assignments (e.g., $x = y$).
  2. Indirect Flows: Occur through control flow dependencies, such as the branches of an if statement influenced by a sensitive condition.

The analysis generates a graph of dependencies, ensuring that "high-security" inputs do not influence "low-security" outputs. The formal rules for this analysis are detailed in the table below, showing how the framework handles complex constructs like function application, record access, and the staged metaprogramming primitives (box, unbox, run).

Information flow rules for SLamJS expressions, detailing subexpressions, direct flows, and indirect flows.

Soundness and Implementation

A critical contribution of this work is the formal soundness proof conducted using the Coq theorem prover. This proof guarantees that if the static analysis identifies a program as secure (satisfying noninterference), no execution of that program will leak sensitive information.

The analysis was implemented in OCaml and evaluated against 19 sophisticated code examples. These tests included Church encodings, complex scope-capture scenarios, and patterns modeled after real-world JavaScript eval usage. The implementation demonstrated that the analysis is computationally feasible, maintaining the $O(n^3)$ complexity typical of 0CFA.

Conclusion and Future Work

This research provides the first fully static information flow analysis for a language with staged metaprogramming. While SLamJS currently lacks some imperative features like loops and exceptions, it demonstrates that dynamic code generation is not inherently unanalyzable. Future work aims to bridge the "string gap" by developing safe transformations from raw JavaScript strings to boxed SLamJS expressions and extending the analysis to more precise frameworks like CFA2.

Summary updated

BibTeX
@misc{lester2013information,
  author = {Martin Mariusz Lester and C.-H. Luke Ong and Max Schaefer},
  title = {{Information Flow Analysis for a Dynamically Typed Language with Staged Metaprogramming}},
  year = {2013},
  doi = {10.1109/csf.2013.21},
}

Loading related content...

Figure