Web security · Lesson 1 of 2
How websites work
Clients, servers, HTML, JavaScript, databases, cookies and sessions explained for beginners, so web security finally makes sense.
⏱ 15 min🎯 Beginner🧪 Hands-on✅ 4-question quiz🎬 Video✓ Completed
By the end, you’ll be able to…
- Describe what happens between your browser and a web server
- Explain the front end, back end and database of a web app
- Explain how cookies keep you logged in, and why stolen cookies are dangerous
Key words
- Client
- The program asking for something. Usually your browser.
- Server
- The computer that answers requests and sends back pages or data.
- Front end
- What runs in your browser: HTML (structure), CSS (style) and JavaScript (behaviour).
- Back end
- Code running on the server that handles logins, saves data and talks to the database.
- Cookie
- A small piece of data a website asks your browser to store and send back with later requests.
- Session
- The website remembering that you’re logged in, usually through a session cookie.
A website is a conversation
Every time you open a page, your browser (the client) sends a request to a server, and the server sends back a response. A single page can involve dozens of these: one for the page, more for images, fonts, scripts and data.
- BrowserGET /profile
- Request+ cookie: session=…
- Server codewho is this? are they allowed?
- Databasefind this user’s profile
- Response200 OK + HTML
You met HTTP in HTTP, HTTPS & TLS. This lesson zooms in on what the website does with your request.
Three layers of a web app
- Front end (your browser)HTML = structure, CSS = style, JavaScript = behaviour
- Back end (the server)checks logins and permissions, runs the app’s rules
- Databasestores users, posts, orders, scores
Here’s the key idea: you control the front end. Anything running in your browser can be viewed and changed by you, using the browser’s developer tools. That’s why the back end must check everything again: prices, permissions, user IDs, everything.
Cookies and sessions: how you stay logged in
HTTP has no memory. Each request arrives on its own. So how does a site remember you’re logged in?
- You log inusername + password
- Server makes a sessionrandom ID: 7f3a…
- Set-Cookiebrowser stores it
- Every requestcookie sent back automatically
- Server recognises youuntil you log out or it expires
That wristband idea explains a big modern threat: if malware or an attacker steals your session cookie, they can sometimes use your account without your password or MFA code. That’s what infostealer malware goes after. Logging out of important sites, and the sites using protections like HttpOnly and Secure cookie settings, makes this harder.
Where JavaScript fits
JavaScript makes pages interactive: menus, games, live chat, this site’s practice terminal. Browsers run it in a sandbox with strict rules. A key one is the same-origin policy: a script from one website normally can’t read your data on another website. Many web attacks are about sneaking script into the wrong site, so it runs with that site’s permissions. You’ll meet that in the next lesson.
Look under the hood (safely)
Your own browser can show you all of this, on any site you visit:
- Press F12 (or right-click → Inspect) to open developer tools.
- Open the Network tab and reload the page. Every row is a request.
- Click one to see its headers: the method, status code, and any cookies sent.
- Open Application (Chrome) or Storage (Firefox) to see this site’s cookies.
Looking is fine. Changing requests to break into someone else’s account isn’t: that’s what legal labs like PortSwigger’s Web Security Academy are for.
🧪 Hands-on
Practice
Use curl (a command-line web client) to talk to a pretend web server. Everything here is simulated.
🎬 Watch
Video: The Internet: HTTP & HTML
Video by Code.org, hosted on YouTube. It loads only when you press play.
✅ Check yourself
Quick quiz
Every answer comes with an explanation, right or wrong. Your best score is saved in this browser.
🔗 Go further
Trustworthy resources
- MDN: An overview of HTTP Mozilla’s friendly explanation of requests and responses.
- MDN: Using HTTP cookies How cookies work, including Secure and HttpOnly.
- Chrome DevTools: Network panel How to inspect requests in your own browser.