未加星标

Statically Checking Web API Requests in JavaScript

字体大小 | |
[前端(javascript) 所属分类 前端(javascript) | 发布者 店小二04 | 时间 2017 | 作者 红领巾 ] 0人收藏点击收藏
Programming in the Stone-age

Writing javascript applications that perform HTTP requests to web APIs relies on the request URL, HTTP method, and request data to be constructed corrected via string operations. This can feel like going back to the stone-age, especially if you are a fan of statically-typed languages: you often ask “where is my beloved compiler”? Traditional compile-time error checking, such as calling a non-existent method in Java, is not available for checking whether such requests in JavaScript code. In this blog post, I am sharing with you our research prototype that can potentially rescue us from this situation, a static checker on web API requests in JavaScript. Thanks to the amazing co-authors Erik Wittern, Yunhui Zheng, Julian Dolby, and Jim Laredo, this work (see thefull paper) has been accepted to the International Conference in Software Engineering (ICSE) this year.

Simple checks like on non-existent endpoints are not available!

On GitHub, we found code that mistakenly attempts to make a request to https://api. spotify.com/v1/seach , as opposed to invoking the correct URL ending with /search .

This is what I mean by stone-age why don’t we have more static support on checking stupid errors like that!

A programmer wishing to avoid such errors can manually assess the correctness of web API requests by consulting the API’s (online) documentation or formal web API specifications. Such specifications, like the OpenAPI Specification (or formerly known as Swagger ), can be created by API providers or third parties to document valid URLs, HTTP methods, as well as inputs and outputs that a web API expects.

Getting out the stone-age: our static checker on web API requests

In essence, our tool automates this manual process by doing two things:

First, our approach extracts a request’s URL string, HTTP method, and the corresponding request data using an inter-procedural string analysis

This task is not super easy task because we need an inter-procedural static program analysis capable of extracting strings. Yunhui has described the magic behind this analysis .

Making use of available Swagger specifications for the definitions of valid URLs, HTTP methods, and data. Our approach checks whether the request extracted from the first step conforms to given web API specifications. Erik has shared some interesting insights about these specifications in aprevious post.

Our check is quite precise!

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 we examined from GitHub, this is what we found:

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.

If you ask me, this numbers mean that we are ready to deploy our approach!

Atom plug-in

And we have! Our checker is already integrated as a plug-in in Atom, as described in Erik’s previous post! It can also be integrated with continuous integration tools to warn programmers about code containing potentially erroneous requests.

Please find thefull paper here and, as always, connect with us on Twitter @apiHarmony . Is there any other similar stong-age annoyance from a language like JavaScript that maybe we can help with static analysis?

本文前端(javascript)相关术语:javascript是什么意思 javascript下载 javascript权威指南 javascript基础教程 javascript 正则表达式 javascript设计模式 javascript高级程序设计 精通javascript javascript教程

主题: JavaJavaScriptGitHubGitTwitter
分页:12
转载请注明
本文标题:Statically Checking Web API Requests in JavaScript
本站链接:http://www.codesec.net/view/533131.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 前端(javascript) | 评论(0) | 阅读(14)