JavaScript is an increasingly popular language for server-side development, thanks in part to the Node.js runtime environment and its vast ecosystem of modules. With the Node.js package manager npm, users are able to easily include external modules as dependencies in their projects. However, npm installs modules with all of their functionality, even if only a fraction is needed, which causes an undue increase in code size. Eliminating this unused functionality from distributions is desirable, but the sound analysis required to find unused code is difficult due to JavaScript's extreme dynamicity. We present a fully automatic technique that identifies unused code by constructing static or dynamic call graphs from the application's tests, and replacing code deemed unreachable with either file- or function-level stubs. If a stub is called, it will fetch and execute the original code on-demand, thus relaxing the requirement that the call graph be sound. The technique also provides an optional guarded execution mode to guard application against injection vulnerabilities in untested code that resulted from stub expansion. This technique is implemented in an open source tool called Stubbifier, which supports the ECMAScript 2019 standard. In an empirical evaluation on 15 Node.js applications and 75 clients of these applications, Stubbifier reduced application size by 56% on average while incurring only minor performance overhead. The evaluation also shows that Stubbifier's guarded execution mode is capable of preventing several known injection vulnerabilities that are manifested in stubbed-out code. Finally, Stubbifier can work alongside bundlers, popular JavaScript tools for bundling an application with its dependencies. For the considered subject applications, we measured an average size reduction of 37% in bundled distributions.
翻译:JavaScript 是一种对服务器端开发越来越受欢迎的语言, 这部分归功于 Norde. js 运行时环境及其巨大的模块生态系统。 由于 Npm 的 Node. js 软件包管理员 ndm, 用户能够很容易地将外部模块作为项目的依赖性纳入项目。 但是, npm 安装包含所有功能的模块, 即使只需要一个分数, 也会导致代码尺寸的不适当增加。 从分布中删除这个未使用的功能是可取的, 但寻找未使用的代码所需的正确分析是困难的。 由于 JavaScript 的极端动态性能。 我们提出了一个完全自动的技术, 通过从应用程序测试中构建静态或动态调用图来识别未使用的代码, 用户可以很容易地将外部模块的代码包含在内。 如果调用鼠标, 它会获取并执行原始的代码, 从而放松调时, 调时, 调时, 需要找到一个可选择的默认执行模式, 用于防范未测试的代码的输入脆弱性。 这个技术是完全自动的代码的, 在应用程序中, 在可测量的操作的操作中, 将显示一个Stubbblidealb lippe lide lide lapp li li li lip lip lip lip lip lip lip lip lip lipp lip la lipp lip lip lip lip lip lip lip lip liver lipperus