WEBVTT

00:00:02.050 --> 00:00:05.980
We've notified the Globomantics team about the outdated Solr installation,

00:00:05.990 --> 00:00:08.070
and they're rolling out the update as we speak.

00:00:08.790 --> 00:00:11.930
Let's turn our attention to the second component of the search app,

00:00:11.940 --> 00:00:13.020
the web application.

00:00:15.260 --> 00:00:17.390
Unlike the Solr example that we just saw,

00:00:17.400 --> 00:00:20.580
Globomantics wrote this application themselves using JavaScript

00:00:20.840 --> 00:00:22.860
which means we have access to the source code.

00:00:23.970 --> 00:00:25.590
Of course, as is normal practice,

00:00:25.590 --> 00:00:28.600
they have used lots of third‑party libraries to help build this app.

00:00:29.920 --> 00:00:32.400
We need to find out how to get Dependency‑Check to

00:00:32.409 --> 00:00:35.840
accurately inventory and check all of those dependencies so

00:00:35.840 --> 00:00:37.280
that we can report back to the team.

00:00:39.040 --> 00:00:39.790
Along the way,

00:00:39.800 --> 00:00:41.660
we'll learn about a few command line options that

00:00:41.660 --> 00:00:45.450
we can use to finetune our scan, excluding directories,

00:00:45.460 --> 00:00:49.100
disabling analyzers, and separating development dependencies.

00:00:49.980 --> 00:00:50.900
Let's take a look.

00:00:53.340 --> 00:00:55.800
We've got the source code checked out on our laptop,

00:00:56.070 --> 00:00:57.870
and we're looking at the root folder of it here.

00:00:58.990 --> 00:01:02.240
We don't need to worry too much about how this JavaScript app works.

00:01:02.240 --> 00:01:03.760
This isn't a JavaScript course,

00:01:03.770 --> 00:01:06.170
and Dependency‑Check is going to handle all of that for us.

00:01:07.900 --> 00:01:10.270
Let's open a terminal in the current directory and run

00:01:10.270 --> 00:01:14.290
Dependency‑Check with the same basic arguments as before to see how

00:01:14.290 --> 00:01:16.990
well that default configuration works for our web app.

00:01:19.380 --> 00:01:21.570
Once again, it's going to take a few minutes to run.

00:01:25.140 --> 00:01:28.210
The first thing you'll notice about the report is that it's huge,

00:01:28.220 --> 00:01:30.920
almost 33 MB, and if we open it up,

00:01:30.930 --> 00:01:37.210
we can see a clue as to why the report shows 27,000 scanned dependencies.

00:01:38.730 --> 00:01:41.500
JavaScript projects do tend to have a lot of dependencies,

00:01:41.790 --> 00:01:43.430
but usually not quite that many.

00:01:43.820 --> 00:01:46.280
In this case, the true number is 1800,

00:01:46.290 --> 00:01:49.320
so Dependency‑Check is scanning a lot of files that it shouldn't be.

00:01:50.580 --> 00:01:53.440
If we scroll down to look at the list of vulnerable dependencies,

00:01:53.760 --> 00:01:56.720
we can also spot a few things here which are potentially unhelpful.

00:01:58.590 --> 00:02:01.400
You can see we have a report for dompurify version

00:02:01.400 --> 00:02:04.100
2.0.0 near the top of the list.

00:02:04.930 --> 00:02:08.199
But further down, we have more reports relating to dompurify,

00:02:08.210 --> 00:02:12.940
in this case, flagging specific JavaScript files from inside that same package.

00:02:14.380 --> 00:02:17.680
It isn't really giving us any new information, it's just generating noise.

00:02:19.420 --> 00:02:21.960
There is also a handful of false positives in this report that

00:02:21.960 --> 00:02:23.980
will distract us from the real vulnerabilities.

00:02:24.580 --> 00:02:31.050
For example, check out this report for WS, a WebSocket library version 6.2.2.

00:02:31.060 --> 00:02:33.440
Let's come down to the published vulnerabilities,

00:02:33.640 --> 00:02:37.790
and we've got 1 medium‑level report CVE‑2021‑32640,

00:02:37.790 --> 00:02:41.410
a resource exhaustion problem.

00:02:42.430 --> 00:02:46.860
Let's open up the last two references, the NVD and the GitHub security advisory.

00:02:47.910 --> 00:02:51.940
In the NVD, if we scroll down to known affected software configurations,

00:02:52.080 --> 00:02:58.700
we can see that the issue exists up to and excluding 6.2.2, so our version is

00:02:58.700 --> 00:03:02.150
actually the patched safe version according to the NVD.

00:03:02.800 --> 00:03:04.930
The GitHub page also confirms that.

00:03:05.530 --> 00:03:07.410
So the analyzer here has picked up that the

00:03:07.410 --> 00:03:09.120
vulnerability exists in this package,

00:03:09.120 --> 00:03:14.020
but it hasn't picked up that it is actually patched in the version that we have.

00:03:16.020 --> 00:03:17.430
So what's going on here?

00:03:18.200 --> 00:03:21.040
Well Dependency‑Check actually has three analyzers

00:03:21.040 --> 00:03:22.900
that scan JavaScript applications,

00:03:23.120 --> 00:03:26.290
they each have a specific use case that they work best on,

00:03:26.760 --> 00:03:30.500
but remember, by default, all analyzers run on a scan,

00:03:30.910 --> 00:03:33.730
even if they're not really the best fit for the current project.

00:03:36.500 --> 00:03:40.360
The Node Audit Analyzer works only for JavaScript projects which use

00:03:40.360 --> 00:03:43.190
the npm package manager for dependency management.

00:03:44.510 --> 00:03:48.610
It will take your dependency list as calculated by npm and submit that

00:03:48.610 --> 00:03:53.030
data to the npm Audit API to check for vulnerabilities that's backed by

00:03:53.030 --> 00:03:55.370
the GitHub security advisory database.

00:03:55.550 --> 00:03:59.750
So if your project uses npm, this is probably the best analyzer for you.

00:04:01.570 --> 00:04:05.010
The Node.js analyzer is similar to the Node Audit Analyzer,

00:04:05.020 --> 00:04:06.490
which can be a little confusing.

00:04:07.100 --> 00:04:10.510
It works with files from npm and Yarn package managers,

00:04:10.520 --> 00:04:14.610
and it will check against the NVD and the Sonatype databases.

00:04:15.720 --> 00:04:16.750
In my experience,

00:04:16.820 --> 00:04:19.970
the Node.js analyzer isn't quite as accurate as the

00:04:19.970 --> 00:04:22.410
Node Audit Analyzer for npm projects.

00:04:23.170 --> 00:04:24.710
So I'd recommend that if you can,

00:04:24.720 --> 00:04:29.620
you use the Node Audit Analyzer and disable the Node.js analyzer.

00:04:30.660 --> 00:04:31.480
In our demo,

00:04:31.490 --> 00:04:34.840
the false positive that we saw for the WS library was

00:04:34.840 --> 00:04:37.240
generated by the Node.js analyzer,

00:04:37.570 --> 00:04:40.920
while the Node Audit Analyzer correctly reports no known

00:04:40.920 --> 00:04:43.500
vulnerabilities on our version of that package.

00:04:45.950 --> 00:04:50.470
Finally, the Retire.js analyzer is really focused on client‑side code.

00:04:51.130 --> 00:04:54.510
It's going to look through your project for JavaScript files that it recognizes

00:04:54.510 --> 00:04:58.060
as belonging to vulnerable dependencies and it does that by checking against

00:04:58.060 --> 00:05:01.120
the database maintained by the Retire.js project.

00:05:02.060 --> 00:05:05.830
If you have copies of third‑party libraries saved directly in your code

00:05:05.830 --> 00:05:08.310
base rather than being served through a package manager,

00:05:08.680 --> 00:05:12.890
a copy of jQuery for example, then Retire.js will spot those files.

00:05:14.080 --> 00:05:18.370
In our case, though, Retire.js was also scanning the node modules directory.

00:05:19.770 --> 00:05:22.710
Node modules is where the node package manager places all the

00:05:22.710 --> 00:05:25.560
downloaded npm packages for our application.

00:05:26.520 --> 00:05:30.350
An individual npm package consists of multiple files and

00:05:30.350 --> 00:05:34.370
Retire.js was checking every single 1, all 27,000.

00:05:35.360 --> 00:05:38.610
That's why we had such a big report file and that's also why we had

00:05:38.610 --> 00:05:41.360
multiple reports for the same dompurify package.

00:05:42.880 --> 00:05:46.640
Since the node modules are already being covered by the Node Audit Analyzer,

00:05:46.960 --> 00:05:51.090
we can safely exclude that folder from the scan and make those problems go away.

00:05:53.450 --> 00:05:55.130
Let's look at the new command that we'll run.

00:05:55.630 --> 00:05:58.970
We'll want Dependency‑Check ‑‑scan current directory,

00:06:00.180 --> 00:06:04.610
then ‑‑disableNodeJS to skip the Node.js analyzer,

00:06:04.880 --> 00:06:06.620
that's case sensitive by the way.

00:06:08.010 --> 00:06:11.720
Then we'll pass an exclude argument with ‑‑exclude

00:06:12.010 --> 00:06:13.750
and the node_modules directory.

00:06:14.510 --> 00:06:14.790
Here,

00:06:14.790 --> 00:06:19.060
the quotes and the asterisks make sure that we properly exclude all files from

00:06:19.060 --> 00:06:21.590
node_modules no matter where we're running this command from.

00:06:24.340 --> 00:06:25.630
Let's go ahead and run that.

00:06:26.280 --> 00:06:28.340
The scan is quite a bit quicker now,

00:06:28.350 --> 00:06:31.320
and the resulting report is now also a sensible file size.

00:06:33.270 --> 00:06:34.600
If we open that report up,

00:06:34.610 --> 00:06:36.470
the first thing that you'll see is the number of

00:06:36.470 --> 00:06:38.710
dependencies found is actually now too small.

00:06:38.720 --> 00:06:41.510
It says 14, when we know it should be in the thousands.

00:06:42.010 --> 00:06:44.370
Well, don't worry, the scanners actually work just fine.

00:06:44.380 --> 00:06:47.980
This is a known limitation with the Node Audit Analyzer where packages

00:06:47.980 --> 00:06:50.300
without known vulnerabilities don't get counted.

00:06:52.140 --> 00:06:54.220
Coming down to our list of vulnerable dependencies,

00:06:54.220 --> 00:06:56.620
you can see it's a little smaller than it was before.

00:06:57.090 --> 00:06:59.470
We still have the dompurify package listed,

00:06:59.710 --> 00:07:02.020
but we don't have the duplicated reports for the

00:07:02.030 --> 00:07:03.650
individual JavaScript files now.

00:07:05.120 --> 00:07:09.670
Also gone is the WS package which we identified as a false positive,

00:07:10.040 --> 00:07:13.250
along with a couple of other false positive packages that we didn't talk about.

00:07:14.930 --> 00:07:18.950
By disabling the Node.js analyzer and excluding the node_modules directory,

00:07:18.960 --> 00:07:22.640
we have improved the accuracy of this JavaScript scan quite a bit.

00:07:22.920 --> 00:07:25.870
That's going to make this report much more meaningful and much more

00:07:25.870 --> 00:07:28.150
useful for the Globomantics development team.
