Nothing Special   »   [go: up one dir, main page]

Skip to main content
Log in

Stubbifier: debloating dynamic server-side JavaScript applications

  • Published:
Empirical Software Engineering Aims and scope Submit manuscript

Abstract

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. Due to JavaScript’s highly dynamic nature, call graph construction may suffer from unsoundness, i.e., code identified as unused may in fact be reachable. To handle such cases, if a stub is called, it will fetch and execute the original code on-demand to preserve the application’s behavior. 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, designed to help package developers to produce a minimal production distribution. Stubbifier 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.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Subscribe and save

Springer+ Basic
$34.99 /Month
  • Get 10 units per month
  • Download Article/Chapter or eBook
  • 1 Unit = 1 Article or 1 Chapter
  • Cancel anytime
Subscribe now

Buy Now

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6

Similar content being viewed by others

Notes

  1. See https://www.github.com/emarteca/stubbifier.

  2. See http://www.modulecounts.com/.

  3. Many npm modules rely on additional development dependencies (sometimes referred to as “devDependencies”) that are needed only for development purposes, e.g., for running tests. These dependencies are typically not installed by clients.

  4. There is more unreachable code in css-loader, but we focus on semver for the sake of illustration

  5. Recall that in JavaScript functions are objects, and can have properties assigned dynamically.

  6. apply calls its receiver as a function, binding its first argument to inside the function, and passing the other arguments as function arguments. arguments is a metavariable available inside functions that refers to its arguments.

  7. The metrics in the table reflect the project’s own source code (excluding tests), and all its (transitive) production dependencies, but excluding devDependencies. .

  8. Of the subject applications reported on in Karim et al. (2018), these were the only two that had a confirmed vulnerability and a test suite with passing tests.

  9. The default behavior of rollup is to ignore dependent modules in node_modules, but the bundle should all code in which stubs may be introduced, to be able to determine Stubbifier’s effectiveness.

  10. The full data for all applications is included in the supplemental material.

  11. Of all the subject applications considered in Karim et al. (2018), these are the only two that still build, install, and have a test suite with passing tests, as required by Stubbifier.

  12. In general, adapting application test suites to work with a bundled version of the application instead of the original version can be a complex and error-prone process, as test suites may import specific functions (that may be renamed by the bundler) from specific files (that may be combined by the bundler). For the applications mentioned here, this conversion was straightforward.

  13. memfs, fs-nextra, commander.js, redux

  14. memory-fs, serve-favicon

  15. prop-types

  16. See https://www.docs.python.org/3/library/functions.html#exec

References

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Alexi Turcotte.

Ethics declarations

Conflict of Interest

The authors declared that they have no conflict of interest.

Additional information

Communicated by: Carlo A. Furia

Publisher’s note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

This research was supported in part by Office of Naval Research (ONR) grants N00014-17-1-2945 and N00014-21-1-2491, and by National Science Foundation grant CCF-1907727. E. Arteca and A. Turcotte are supported in part by the Natural Sciences and Engineering Research Council of Canada.

Alexi Turcotte and Ellen Arteca contributed equally to the work.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Turcotte, A., Arteca, E., Mishra, A. et al. Stubbifier: debloating dynamic server-side JavaScript applications. Empir Software Eng 27, 161 (2022). https://doi.org/10.1007/s10664-022-10195-6

Download citation

  • Accepted:

  • Published:

  • DOI: https://doi.org/10.1007/s10664-022-10195-6

Keywords

Navigation