WEBVTT

1
00:00:00.450 --> 00:00:02.670
Finding a bug is half the job.

2
00:00:02.840 --> 00:00:05.390
Knowing the fix makes your reports better,

3
00:00:05.390 --> 00:00:07.000
and your own code safer.

4
00:00:07.850 --> 00:00:10.220
Why does SQL injection happen?

5
00:00:10.390 --> 00:00:12.770
The app builds its database query by

6
00:00:12.770 --> 00:00:15.830
gluing the user's input into the query text.

7
00:00:16.000 --> 00:00:18.210
The database receives one string,

8
00:00:18.210 --> 00:00:20.480
and cannot tell which part is your

9
00:00:20.480 --> 00:00:23.040
query and which part is their input.

10
00:00:23.210 --> 00:00:25.960
So input can change what the query does.

11
00:00:26.810 --> 00:00:28.970
The fix is a prepared statement.

12
00:00:29.140 --> 00:00:31.030
The app sends the shape of the

13
00:00:31.030 --> 00:00:33.370
query first, with a placeholder where

14
00:00:33.370 --> 00:00:34.470
the value goes.

15
00:00:34.640 --> 00:00:36.970
Then it sends the value separately.

16
00:00:37.140 --> 00:00:39.180
The database treats it as data,

17
00:00:39.180 --> 00:00:41.380
and never as part of the query.

18
00:00:42.230 --> 00:00:44.250
A fix is not done until you

19
00:00:44.250 --> 00:00:45.070
prove it.

20
00:00:45.240 --> 00:00:46.920
Run the same attack again:

21
00:00:46.920 --> 00:00:48.030
it should fail.

22
00:00:48.200 --> 00:00:50.430
Run the scanner again: it should find

23
00:00:50.430 --> 00:00:51.060
nothing.

24
00:00:51.230 --> 00:00:53.180
And check the page still works for

25
00:00:53.180 --> 00:00:54.130
a normal user.

26
00:00:54.980 --> 00:00:57.150
So: keep input out of the query,

27
00:00:57.150 --> 00:00:58.590
then prove the fix.

28
00:00:58.760 --> 00:01:00.420
In the lab, you will fix the

29
00:01:00.420 --> 00:01:02.730
injection in the training app's source,

30
00:01:02.730 --> 00:01:04.810
and show that the scanner no longer

31
00:01:04.810 --> 00:01:05.500
finds it.
