1
00:00:02,350 --> 00:00:04,930
So that were cross site scripting attacks,

2
00:00:04,990 --> 00:00:12,220
the most dangerous attack pattern when we talk about Javascript code. They only affect browser side Javascript

3
00:00:12,220 --> 00:00:12,630
code

4
00:00:12,670 --> 00:00:18,460
but since this is the part where you typically run a lot of Javascript code, it is a thing you definitely

5
00:00:18,460 --> 00:00:21,580
have to watch out for it and you have to be aware of. Now with that

6
00:00:21,580 --> 00:00:25,090
however, let's move on to cross site request forgery.

7
00:00:25,090 --> 00:00:26,440
What is this attack?

8
00:00:26,470 --> 00:00:32,110
It can be related to cross site scripting attacks but it doesn't have to be. The idea behind cross site

9
00:00:32,110 --> 00:00:38,980
request forgery is that people trick you into clicking on a link that leads to a prepared page where

10
00:00:38,980 --> 00:00:45,270
they abuse your local cookies to then send a request to the page you would normally talk to as well,

11
00:00:45,310 --> 00:00:47,470
let's say your online banking backend

12
00:00:47,920 --> 00:00:52,960
but since you are coming from a prepared page, you then do something there automatically without you

13
00:00:52,960 --> 00:00:58,740
recognizing that you don't want to do, for example send money to someone you don't want to send,

14
00:00:58,750 --> 00:01:03,340
maybe that even as possible to happen behind the scenes without you noticing.

15
00:01:03,340 --> 00:01:09,190
So this attack pattern also depends on injected content, so injected Javascript code but it can

16
00:01:09,190 --> 00:01:14,050
also be just HTML content which submits a form to the trusted server,

17
00:01:14,050 --> 00:01:19,510
the problem is that the form is part of an untrusted page which you might not recognize if the URL

18
00:01:19,510 --> 00:01:20,920
look similar

19
00:01:20,920 --> 00:01:26,160
and then requests on your behalf with your cookies can be made to the trustworthy server,

20
00:01:26,260 --> 00:01:30,980
so the only danger and the only problem is that this is all happening from a malicious site.

21
00:01:31,240 --> 00:01:38,110
So actions might be executed on the trustworthy page with your data without you knowing that it happens

22
00:01:38,620 --> 00:01:41,870
and therefore you might want to protect against that.

23
00:01:41,890 --> 00:01:46,630
Let's have a closer look at this pattern, though I do talk about it in more detail and also how to prevent

24
00:01:46,630 --> 00:01:46,910
it

25
00:01:47,050 --> 00:01:51,370
in my Node.js course because this is more a server side issue.

26
00:01:51,370 --> 00:01:58,890
You need to protect against CSRF attacks on the server side by using a mechanism which is a CSRF token

27
00:01:58,960 --> 00:02:05,080
and again I do discuss this in my Node.js course where we work on the server side on the backend all

28
00:02:05,080 --> 00:02:06,070
the time.

29
00:02:06,070 --> 00:02:09,410
So CSRF stands for cross site request forgery

30
00:02:09,430 --> 00:02:14,350
and the idea is that if you're the user of a web app and you have some backend, let's say the online

31
00:02:14,350 --> 00:02:18,440
banking site which uses Node.js or any other programming language,

32
00:02:18,460 --> 00:02:25,390
this is not exclusive to Javascript, uses any programming language and it talks to database, the server.

33
00:02:25,390 --> 00:02:28,540
Now you are visiting the frontend of this page,

34
00:02:28,540 --> 00:02:34,450
let's say that the user interface of your online banking site and now when you have such a setup, typically

35
00:02:34,450 --> 00:02:38,590
the server-side application identifies you with a so-called session,

36
00:02:38,590 --> 00:02:44,170
so you logged in and then the server side generates this session object, stores session data on the

37
00:02:44,170 --> 00:02:47,950
server and sends you the session ID which is stored in a cookie,

38
00:02:47,950 --> 00:02:54,800
that's a typical authentication setup you have in web pages where frontend and backend work together.

39
00:02:54,820 --> 00:03:00,560
Now then you might be sending an intended request, for example to send money to be and all is good.

40
00:03:00,580 --> 00:03:06,580
The problem is that if you now visit a fake site because someone sends you a link to it, which looks

41
00:03:06,580 --> 00:03:15,310
like the trustworthy site but which isn't, then you visit this page and there, people send a request to

42
00:03:15,310 --> 00:03:21,700
the trustworthy backend, therefore the browser attaches cookies that belong to this trustworthy backend

43
00:03:21,850 --> 00:03:25,480
which is your session ID for example and everything works.

44
00:03:25,480 --> 00:03:31,600
The problem just is since you're on a fake site, the request might be one that is intended by the fake site

45
00:03:31,630 --> 00:03:38,620
but not by you, for example to send money to C and this request will succeed because you sent the right

46
00:03:38,620 --> 00:03:42,880
cookie, the right session ID and you sent it through the right backend.

47
00:03:42,910 --> 00:03:45,840
So again more details can be found in a Node.js course

48
00:03:45,850 --> 00:03:51,070
but this is also a potential tech pattern but not directly linked to Javascript.

49
00:03:51,070 --> 00:03:56,530
It can be implemented with cross site scripting attacks but it can also be implemented by using such

50
00:03:56,530 --> 00:04:00,290
a fake site which does not require cross site scripting attacks.

51
00:04:00,370 --> 00:04:04,530
So therefore this is not really a Javascript security thing,

52
00:04:04,600 --> 00:04:08,440
it's more a server side or general web application security thing

53
00:04:08,440 --> 00:04:13,600
and therefore I do discuss it in more detail in my Node.js course where we write a lot of server side

54
00:04:13,600 --> 00:04:13,990
code.
