When we scaffold an SPFx webpart/Extension we get many Node Modules as part of dependencies. These can be seen in node_modules folder and there are also entries in package-lock.json file.

I know these are dependencies for development.

Now assume a case where one of the Node Modules contains Virus (like in flatmap-stream and event-stream). Does the package files generated from commands gulp bundle --ship and gulp package-solution --ship will contain any of the code from all or effected Node Modules?



The short answer is no, the package doesn't contain all of the code from node_modules, yet it contains some very small amount of proven code (mostly css-loader code from corresponding webpack loader).

Long answer

SharePoint Framework uses webpack to bundle your code into a single file (aka package). Apart your code SharePoint Framework contains a lot of components which you reference in your code via imports (import smth from '@microsoft/sp-webpart-base' etc.), however, those components are not included in your code. They serve as "externals" and are loaded by SharePoint Framework at runtime.
If you take a look at webpack configuration, you will see below picture:

devtool: 'source-map',
       { 'hello-world-web-part':
          'C:\\temp\\spfx-test\\lib\\webparts\\myNewWp\\MyNewWpWebPart.js' },
       [ '@microsoft/sp-lodash-subset',
         'MyNewWpWebPartStrings' ],

Everything which is in the external section won't be included into the resulting bundle, yet it will be served at runtime by Microsoft. Your package contains only your code (plus a bit of code from webpack's css-loader like mentioned earlier). You can run gulp clean then gulp bundle and open ./dist folder to review the generated bundle. Only your code will be included.
Which basically means that you shouldn't care about such things like viruses, etc. However, Microsoft should care that all externals modules they use (aka @microsoft/* and react*) are virus-free and safe.
From your side, you should only care about any external modules you install after scaffolding your project. For example react modules, or helpers, or whatever else.

Additional reading:

250+ vulnerabilities in a new SharePoint Framework project
Don't be alarmed by vulnerabilities after running NPM Install
Code Security Audit using “npm audit”

  • There is the possibility that the webpack or one of it plugins has "evil" code in and injects this into your build result (like in XcodeGhost). But the size and importance makes likely that such an attack would be detect fast – sschoof Jan 4 at 8:18
  • That's true, but this is the task for Microsoft, because like mentioned all webpack modules as well as node modules with dependencies are externals and controlled by Microsoft. So technically "evil" code won't be in your bundle unless you add it explicitly. – Sergei Sergeev Jan 4 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.