Back to results

University of Freiburg

Higher-order contracts for JavaScript

Abstract

dc:description.abstract

JavaScript is an untyped and dynamic programming language with objects and first-class functions. While it is most well-known as the client-side scripting language for websites, it is also increasingly used for non-browser development, such as developing server-side applications with Node.js, for game development, to implement platform-independent mobile applications, or as a compilation target for other languages like TypeScript or Dart.<br><br>Unfortunately, JavaScript itself has no real security awareness: there is a global scope for functions and variables, all scripts have the same authority, and everything can be modified, from the fields and methods of an object over its prototype property to the scope chain of a function closure. As a consequence, JavaScript code is prone to injection attacks, library code can read and manipulate everything reachable from the global scope, and third-party code can get access to sensitive data. Furthermore, side effects may cause unexpected behavior so that program understanding and maintenance become difficult.<br><br>To overcome these limitations, we propose using contracts with runtime monitoring. Software contracts were introduced with Meyer’s Design by Contract methodology which stipulates invariants for objects as well as Hoare-like pre- and postconditions for functions. Contract monitoring has become a prominent mechanism to provide strong guarantees for programs in dynamically typed languages while preserving their flexibility and expressiveness.<br><br>This dissertation presents the design and implementation of TreatJS, a language-embedded, higher-order contract system for JavaScript which enforces contracts by runtime monitoring. Beyond the standard abstractions for higher-order contracts (flat contracts, function contracts, dependent contracts), TreatJS provides intersection and union operators for contracts and a contract constructor that constructs and composes contracts at runtime using contract abstraction. Contract constructors are the building blocks for dependent contracts, parameterized contracts, and recursive contracts.<br><br>Another novel aspect is TreatJS’s use of constraints to create a structure for computing positive and negative blame according to the semantics of subject and context satisfaction, respectively. Moreover, it applies a compatibility check to distinguish contracts from different sides of an intersection or union, and it provides three general monitoring semantics which handles the visibility of contracts inside of predicate code.<br><br>TreatJS is implemented as a library in JavaScript. It enables a developer to specify all aspects of a contract using the full JavaScript language. JavaScript proxies implement delayed contract checking of function and object contracts and guarantee full interposition for the full JavaScript language, including the with-statement and eval. Moreover, its implementation gives noninterference a high priority and it employs a membrane-based sandbox to keep the predicate code apart from the normal program execution.<br><br>Finally, the implementation of TreatJS illustrates the need for a different proxy constructor that is better suited for the implementation of contract wrappers. One issue with the current contract implementation arises because a contract wrapper is different (not pointer-equal) from its target object so that an equality test between wrapper and target returns false instead of true. Thus, TreatJS comes with an implementation of a transparent object proxy which ensures transparent operations with all JavaScript programs.

Author and committee

dc:creator, dc:contributor.*
Author dc:creator
  • Keil, Roman Matthias
Contributors dc:contributor
  • Thiemann, Peter
ORCID person:identifier.orcid

Subjects

dc:subject × 1

Rights

dc:rights
Statement dc:rights
  • free
Language dc:language.dcterms_iso639_2
eng

Identifiers

dc:identifier.*
URN
urn:nbn:de:bsz:25-freidok-169633

Chain of custody

source
Harvested from
University of Freiburg
Base URL
freidok.uni-freiburg.de/oai/oai2.php
Last updated
2026-11-19
Source record
OAI-PMH GetRecord
citation

Keil, Roman Matthias. Higher-order contracts for JavaScript. 2018. https://doi.org/10.6094/UNIFR/16963