arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 1702.03906cs.SE
收藏

在JavaScript中静态检查Web API请求

Statically Checking Web API Requests in JavaScript

Erik Wittern, Annie T. T. Ying, Yunhui Zheng, Julian Dolby, Jim A. Laredo

摘要:

许多JavaScript应用程序对Web API执行HTTP请求,依赖于请求URL、HTTP方法和请求数据通过字符串操作正确构造。传统的编译时错误检查,例如调用Java中不存在的方法,无法检查此类请求是否符合Web API的要求。本文提出了一种在JavaScript中静态检查Web API请求的方法。我们的方法首先使用过程间字符串分析提取请求的URL字符串,HTTP方法和相应的请求数据,然后检查请求是否符合给定的Web API规范。我们通过检查从GitHub挖掘的JavaScript文件中的Web API请求是否与公开的API规范一致或不一致来评估我们的方法。从范围内的6575个请求中,我们的方法确定了请求的URL和HTTP方法是否与Web API规范一致或不一致,精度为96.0%。我们的方法还正确地确定了提取的请求数据是否与数据需求一致或不一致,有效负载数据的精度为87.9%,查询数据的精度为99.9%。在对不一致案例的系统分析中,我们发现其中许多是由于客户端代码中的错误造成的。这里提出的检查器可以与代码编辑器或持续集成工具集成,以警告程序员代码包含潜在的错误请求。

英文摘要:

Many JavaScript applications perform HTTP requests to web APIs, relying on the request URL, HTTP method, and request data to be constructed correctly by string operations. Traditional compile-time error checking, such as calling a non-existent method in Java, are not available for checking whether such requests comply with the requirements of a web API. In this paper, we propose an approach to statically check web API requests in JavaScript. Our approach first extracts a request's URL string, HTTP method, and the corresponding request data using an inter-procedural string analysis, and then checks whether the request conforms to given web API specifications. We evaluated our approach by checking whether web API requests in JavaScript files mined from GitHub are consistent or inconsistent with publicly available API specifications. From the 6575 requests in scope, our approach determined whether the request's URL and HTTP method was consistent or inconsistent with web API specifications with a precision of 96.0%. Our approach also correctly determined whether extracted request data was consistent or inconsistent with the data requirements with a precision of 87.9% for payload data and 99.9% for query data. In a systematic analysis of the inconsistent cases, we found that many of them were due to errors in the client code. The here proposed checker can be integrated with code editors or with continuous integration tools to warn programmers about code containing potentially erroneous requests.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑