arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2306.08741cs.SE
收藏

一种用于发现属性访问错误的统计方法

A statistical approach for finding property-access errors

Ellen Arteca, Max Schäfer, Frank Tip

AI总结:

针对JavaScript中错误属性访问难检测的问题,提出结合统计分析识别异常模式与局部数据流分析过滤安全实例的两阶段检测方法,准确率82%、召回率90%,同时验证了VSCode代码补全的低召回率局限。

摘要:

我们研究了JavaScript中错误属性访问的发现问题,在JavaScript中对象没有固定布局,属性(包括方法)可以在对象的整个生命周期内被自由添加、覆盖和删除。由于引用不存在的属性在JavaScript中并非错误,(可能由拼写错误或对API文档的误解导致的)对不存在属性的意外访问在没有全面测试的情况下可能无法被发现,且其表现出的问题可能与根源位置相距甚远。我们基于“实际中大多数属性访问都是正确的”这一观察,提出了一种两阶段的属性访问错误检测方法。首先,我们从大量真实世界JavaScript代码语料库中收集大量属性访问模式,并执行统计分析以识别异常使用模式。这些模式的特定实例可能并非漏洞(例如由于动态类型检查),因此我们通过局部数据流分析过滤掉安全的异常属性访问实例,仅保留那些可能是真实漏洞的实例。我们通过实验验证了该方法,结果显示在100个具体的异常属性访问实例上,该方法达到了82%的准确率和90%的召回率,具备实际应用价值。我们还开展了一项实验,测定流行的VSCode代码补全功能在建议对象属性方面的效果,发现尽管它从未建议过错误的属性(准确率100%),但在80个案例中有62个未能建议正确的属性(召回率22.5%)。这表明开发者不能仅依赖VSCode的代码补全来确保所有属性访问都是有效的。

英文摘要:

We study the problem of finding incorrect property accesses in JavaScript where objects do not have a fixed layout, and properties (including methods) can be added, overwritten, and deleted freely throughout the lifetime of an object. Since referencing a non-existent property is not an error in JavaScript, accidental accesses to non-existent properties (caused, perhaps, by a typo or by a misunderstanding of API documentation) can go undetected without thorough testing, and may manifest far from the source of the problem. We propose a two-phase approach for detecting property access errors based on the observation that, in practice, most property accesses will be correct. First a large number of property access patterns is collected from an extensive corpus of real-world JavaScript code, and a statistical analysis is performed to identify anomalous usage patterns. Specific instances of these patterns may not be bugs (due, e.g., dynamic type checks), so a local data-flow analysis filters out instances of anomalous property accesses that are safe and leaves only those likely to be actual bugs. We experimentally validate our approach, showing that on a set of 100 concrete instances of anomalous property accesses, the approach achieves a precision of 82% with a recall of 90%, making it suitable for practical use. We also conducted an experiment to determine how effective the popular VSCode code completion feature is at suggesting object properties, and found that, while it never suggested an incorrect property (precision of 100%), it failed to suggest the correct property in 62 out of 80 cases (recall of 22.5%). This shows that developers cannot rely on VSCode's code completion alone to ensure that all property accesses are valid.

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

↑