- Identify the core technologies used by web applications.
- Describe HTTP requests, responses, and stateless communication.
- Explain how HTML, CSS, JavaScript, and the DOM work together.
- Determine whether two URLs have the same origin or are merely same-site.
- Explain how cookies create sessions and how cookie flags protect them.
- Describe the roles of HTTPS, HSTS, framing controls, and traffic-inspection tools.
Start with the Web’s Building Blocks
Web applications combine document structure, presentation rules, executable behavior, and HTTP communication.
Understanding web attacks begins with understanding how ordinary web applications operate. These foundations prepare you to study vulnerabilities such as cross-site scripting, cross-site request forgery, clickjacking, and tabnabbing.
Three technologies form the main parts of a web application:
- HTML (Hypertext Markup Language)supplies the page’s structure and content.
- CSS (Cascading Style Sheets)determines presentation, including colors, fonts, sizes, and layout.
- JavaScriptprovides dynamic behavior such as form validation, animation, and live page updates.
Follow an HTTP Exchange
A browser sends a text-based request, and the server returns a text-based response.
Clicking a link or entering a URL causes the browser to build an HTTP request and send it to the chosen server. A simple request can look like this:
GET /index.html HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 ...
Referer: [external-link-removed]- Theverb, such as GET or POST, states the requested action.
- TheURLidentifies the destination resource.
- Theprotocol versionidentifies the HTTP version in use.
- Request headerscarry extra details. For example, User-Agent identifies the browser, while Referer can tell the server which page led to the request.
After processing the request, the server returns an HTTP response:
HTTP/1.1 200 OK
Server: Apache
Set-Cookie: sessionId=abc123; Path=/
Content-Type: text/html
<html>
<body>
<h1>Hello World</h1>
</body>
</html>- Thestatus codereports the result. For example, 200 OK indicates success, while 404 indicates that a resource was not found.
- Response headerscan identify the server, set a cookie, and tell the browser how to interpret the body through Content-Type.
- Theresponse bodycontains the returned data, which may be HTML, JavaScript, an image, or another kind of data.
If HTTP treats every request independently, what does a site need in order to recognize an authenticated user on the next request?
It needs a separate state mechanism. Web applications commonly use a cookie that the browser returns with later requests so the server can identify the session.
See How the Browser Builds a Page
HTML supplies elements, CSS controls rendering, and JavaScript changes the document through the DOM.
An HTML response is organized into elements, also called tags. Consider this heading element:
<h1 id="title" style="color: red;">Hello World</h1>- The
<h1>tag starts a top-level heading. - Attributes such as
idandstylerefine the element’s identity, appearance, or behavior. - The literal text
Hello Worldis the displayed content. - The closing tag
</h1>finishes the element.
CSS adds presentation rules to that structure. The following rule gives the page a blue background and makes its default text white:
body {
background-color: blue;
color: white;
}A style sheet may appear inside the HTML document or be loaded from a separate file.
JavaScript supplies executable behavior and can be placed inside<script>tags:
<script>
document.getElementById('title').innerHTML = 'Goodbye World';
</script>Because client-side JavaScript runs in the user’s browser, it can act within that web application as the user can: it may read or modify visible data, submit forms, and read cookies unless access is restricted.
Apply the Same-Origin Boundary
The same-origin policy confines JavaScript access according to scheme, host, and port.
Unrestricted JavaScript access across websites would let code on a malicious page reach information in another site, such as a bank page open for an authenticated user. The same-origin policy provides the central browser boundary that prevents this kind of access.
- Scheme: the protocol, such as
httporhttps. - Host: the domain name, such as
example.org. - Port: for example,
80for HTTP or443for HTTPS by default.
Two URLs share an origin only when all three components match exactly. The path after those components does not determine the origin.
| URLs | Origin result | Reason |
|---|---|---|
https://example.org/a and https://example.org/b | Same origin | Scheme, host, and port match. |
https://example.org and http://example.org | Different origins | The schemes differ. |
https://example.org and https://example.org:8080 | Different origins | The ports differ. |
<!-- Attacker's page -->
<iframe id="mail" src="[external-link-removed]"></iframe>
<script>
var iframe = document.getElementById('mail');
// This line tries to access the content inside the iframe
var emails = iframe.contentDocument.body.innerHTML;
</script>A site can add another defense with theX-Frame-Optionsresponse header. Values such asDENYorSAMEORIGINtell the browser to refuse disallowed iframe embedding.
The same-origin policy stops an attacker’s page from reading your email. Does that alone stop the attacker’s site from causing your browser to send a request to another site with your cookies?
No. Preventing cross-origin reading is different from preventing an unwanted authenticated request. The latter is the concern behind cross-site request forgery.
Distinguish Same-Site from Same-Origin
Same-site comparisons operate at the registrable-domain level rather than matching scheme, host, and port.
For example,www.example.comandblog.example.comare same-site because both belong toexample.com. By contrast,example.comandattacker.comare cross-site.
This distinction matters because browser protections, especially cookie behavior, increasingly depend on whether a request is same-site or cross-site.
Turn Stateless Requests into Sessions
Cookies let a browser return stored data to a domain, enabling the server to recognize a session.
Because HTTP does not preserve state by itself, a server needs another way to connect multiple requests to the same session. A cookie is a small value that the server asks the browser to store.
- On the first visit, the server includes a
Set-Cookieheader in its response. - The browser saves the cookie and associates it with the server’s domain.
- On later requests to that domain, the browser automatically places the value in a
Cookierequest header. - The server reads the value, identifies the user, and retrieves session state such as the user’s authenticated identity.
Set-Cookie: sessionId=abc123; Path=/; HttpOnly; SecureCookie: sessionId=abc123This mechanism supports features such as authentication and shopping carts. It is also security-sensitive: anyone who steals a session cookie may impersonate its user without knowing the password.
A server can add protective flags when it sets a cookie:
HttpOnlyhides the cookie from JavaScript, so it travels only with HTTP(S) requests. This prevents an XSS payload from reading it.Securelimits transmission to encrypted HTTPS connections, preventing the cookie from being sent over unencrypted HTTP where network traffic could be sniffed.SameSitegoverns cross-site transmission.Laxallows cookies during top-level navigation, such as following a link, while blocking uses such as cross-site images or iframes.Strictblocks all cross-site use.Nonepermits cross-site use but requiresSecure.
Protect the Communication Channel
HTTPS encrypts web traffic, while HSTS directs browsers to keep using HTTPS.
Web traffic should be encrypted with HTTPS, which carries HTTP over TLS. This applies to public websites and internal applications alike.
Strict-Transport-Security: max-age=31536000; includeSubDomainsLet’s Encrypt is a free certificate authority that provides trusted SSL/TLS certificates and offers a straightforward way to obtain valid certificates.
Inspect What the Browser and Server Exchange
Developer tools and debugging proxies expose HTTP traffic, headers, cookies, and page structure.
Security learning becomes concrete when you inspect the requests and responses moving between a browser and server. Several tools provide this view:
- Browser developer toolsshow the HTML through Inspect and display HTTP requests, responses, headers, cookies, and timing in the Network panel.
- Fiddleris a free Windows debugging proxy that presents HTTP and HTTPS traffic and supports inspecting or changing requests and responses.
- Burp Suiteis a widely used security-testing tool with a free community edition, an intercepting proxy, a repeater, and other features.
- ZAP (Zed Attack Proxy)is OWASP’s open-source alternative to Burp Suite.
These tools reveal server output, including headers such asSet-Cookie,X-Frame-Options, andContent-Type. They also let you change requests and observe the response.
Open the Network panel in your browser’s developer tools, visit a website, and inspect its requests. Can you locate cookies and security-related response headers?
Look at the request and response headers for entries such as Cookie, Set-Cookie, X-Frame-Options, Content-Type, or Strict-Transport-Security when the site provides them.
Connect the Foundations to Later Attacks
Common web attacks misuse the same browser, JavaScript, cookie, framing, and HTTP mechanisms introduced here.
These fundamentals provide the basis for understanding specific web application vulnerabilities:
- Cross-Site Scripting (XSS)injects malicious scripts that bypass the same-origin policy.
- Cross-Site Request Forgery (CSRF)tricks a browser into sending unwanted requests with cookies.
- Clickjackingconceals interface controls beneath transparent layers.
- Tabnabbinguses changed content in a background tab for phishing.
Each attack works through mechanisms already introduced here, including JavaScript, cookies, HTTP headers, and origin boundaries. Knowing those mechanisms makes both the attacks and their defenses easier to follow.
Common misconceptions
Watch out: HTTP automatically remembers a user’s previous requests and authentication state.
Instead: HTTP is stateless. A separate mechanism such as a cookie links later requests to a stored session.
Watch out: Two same-site URLs must also have the same origin.
Instead: Same-site depends on the shared registrable domain. Same-origin requires scheme, host, and port all to match exactly.
Watch out: The same-origin policy prevents every cross-site request.
Instead: It prevents JavaScript from reading or modifying cross-origin content, but unwanted requests involving cookies are a separate concern addressed when studying CSRF.
Lesson recap
- HTML structures a page, CSS controls its appearance, and JavaScript changes it through the DOM.
- A user agent exchanges text-based HTTP requests and responses with a web server.
- The same-origin policy confines JavaScript access according to scheme, host, and port; same-site instead uses the registrable domain.
- Cookies add session state to stateless HTTP and should be protected with HttpOnly, Secure, and SameSite settings.
- X-Frame-Options restricts framing, while HTTPS and HSTS protect transport.
- Browser developer tools, Fiddler, Burp Suite, and ZAP help reveal and inspect web traffic.