Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Handlebars with Template Strings #977

Closed
aorinevo opened this issue Mar 27, 2020 · 5 comments
Closed

Replace Handlebars with Template Strings #977

aorinevo opened this issue Mar 27, 2020 · 5 comments
Labels
feature New functionality or improvement

Comments

@aorinevo
Copy link

aorinevo commented Mar 27, 2020

Support plan

  • which support plan is this issue covered by? Community
  • is this issue currently blocking your project? no
  • is this issue affecting a production system? yes

Context

  • node version: 12.16.1
  • module version: 22.0.4
  • environment (e.g. node, browser, native): node
  • used with hapi
  • any other relevant information: N/A

What problem are you trying to solve?

Lab depends on Handlebars to generate HTML for coverage reports. While Handlebars is a great templating language, it seems to have fallen out of maintenance. There are currently almost 200 vulnerabilities ranging in severity from critical to low (albeit the overwhelming majority are low). In addition, some advisories just cannot be resolved without resorting to forced resolutions or exceptions via nsprc. That is, npm audit --fix or npm update --depth={{depth}} do not work.

Screen Shot 2020-03-26 at 9 35 46 PM

Screen Shot 2020-03-26 at 9 29 35 PM

With a relatively low-level of effort, we can remove handlebars dependency altogether by using template strings. For example, see https://github.com/hapijs/lab/pull/978/files.

ROI

  • removes 1 dependency (~80KB, includes compiler and runtime)
  • reduces install time
  • resolves existing and future Handlebars vulnerabilities
  • increased testability of html reporter templates
  • unlocks potential to remove all html files (i.e. reporters/html/partials/*.html and reporters/reporter.html

Notes

Do you have a new or modified API suggestion to solve the problem?

The suggested feature does not require changes to the API.

@aorinevo aorinevo added the feature New functionality or improvement label Mar 27, 2020
@aorinevo
Copy link
Author

Partial work towards this can be found here: https://github.com/hapijs/lab/pull/978/files

@aorinevo
Copy link
Author

aorinevo commented Mar 28, 2020

@hueniverse, I got this fully working.

This change is backwards compatible. Template String HTML reporter can be enabled via .labrc.js by setting enableTemplateStringHTMLReporter to 'true'.

With feature flag on, unit tests pass and coverage is at 100%. With feature flag off, all but one unit tests pass.

It is important to note that the failed unit test is a false positive as the unit test itself was updated to support template strings. Meaning that when feature flag is off, all functionality works as before but runs one unit test that is meant to pass only when feature flag is on.

It is possible to add backwards compatibility to the failed unit tests. That is, toggle between the appropriate assertions via the feature flag. Would love to get some guidance here.

Looking forward to your feedback :)

@stevendesu
Copy link

Just wanted to add on the "resolves [...] future Handlebars vulnerabilities" note -- this showed up in my NPM audit today:

stevenbarnett@MacBook-Pro hapi-test % npm audit 
                                                                                
                       === npm audit security report ===                        
                                                                                
┌──────────────────────────────────────────────────────────────────────────────┐
│                                Manual Review                                 │
│            Some vulnerabilities require your attention to resolve            │
│                                                                              │
│         Visit https://go.npm.me/audit-guide for additional guidance          │
└──────────────────────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.2.1 <1.0.0 || >=1.2.3                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ @hapi/lab [dev]                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ @hapi/lab > handlebars > optimist > minimist                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1179                            │
└───────────────┴──────────────────────────────────────────────────────────────┘

@aorinevo
Copy link
Author

aorinevo commented Apr 1, 2020

@stevendesu, Handlebars has released v4.7.4 which deprecates use of optimist in favor of yargs.

As an interim solution, while this issue is being reviewed, you can try updating to v4.7.4 by way of running npm update --depth={{depth}} to see if that resolves the issue.

@aorinevo
Copy link
Author

Closing this issue for now as the vulnerability was addressed through a combination of PRs to Handlebars:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

2 participants