Open to everyone Reading, lesson 52 of 100, 2 min read
How web applications work
The parts of a web application
When you use a website such as this learning platform, several parts work together:
| Part | Role |
|---|---|
| Browser (client) | Shows pages, runs JavaScript, stores cookies |
| Web server | Receives HTTP requests and returns responses |
| Application code | Decides what to do with each request: checks who you are, reads data, builds the page |
| Database | Stores accounts, courses, results |
| Other services | Email, payment providers, file storage |
Requests and responses
The browser sends an HTTP request:
POST /login HTTP/1.1
Host: school.example
Content-Type: application/x-www-form-urlencoded
Cookie: session=...
email=ada%40example.org&password=...The server replies with a status code (200 OK, 302 redirect, 403 forbidden, 404 not found, 500 server error), headers and a body.
Sessions and cookies
HTTP forgets everything between requests. To remember that you signed in, the server gives the browser a session cookie: a long random value that refers to your session on the server. Whoever holds that cookie is you to the website, until the session ends. That is why stealing cookies is as useful to attackers as stealing passwords.
Good cookies are marked:
Secure: only sent over HTTPS;HttpOnly: not readable by JavaScript;SameSite: not sent with requests started from other websites.
The golden rule of web security
Never trust the client. Everything the browser sends (form fields, hidden fields, cookies, headers, the address itself) can be changed by the user or an attacker with simple tools. Checks done only in the browser (for example, JavaScript that blocks a too-long name) are for convenience, not security. The server must check everything again.
Note
Your browser's developer tools (press F12 on a computer) show every request and response a page makes. Open them on any site you use and look at the Network tab.