Skip to content
Tutorials Center
My learning

Topics

Lesson 19 of 53 ยท Web Application Security

Web Application Security Basics

Review HTTP from a security view, learn the same-origin policy, cookie attributes, the OWASP Top 10 and how testing proxies work, with runnable origin-check models.

Almost every product you use now has a web interface or a web API, so web applications are where most attackers start. Before learning individual bug classes such as injection or cross-site scripting, you need a clear picture of the platform they live on: how HTTP messages look, what a browser is willing to share between sites, how cookies travel, and which categories of weakness show up again and again.

This lesson is that foundation. The real tools it mentions, such as intercepting proxies and scanners, cannot run on this site, so they appear as read-only descriptions. The runnable parts are stand-ins: small JavaScript models of the browser's origin rules and of a cookie jar, using made-up URLs. They explain the logic, but they are not the browser's real implementation.

What a web request carries

Method and path What you ask for.
Headers Cookies, content type, origin.
Body Form fields or JSON.
Response Status, headers, content.

Every part can be changed by the client, so every part must be validated by the server.

1 / 2

HTTP from a security point of view

You met HTTP in Networking Essentials for Security. Here is the same exchange with a security lens:

HTTP
POST /transfer HTTP/1.1
Host: bank.example
Cookie: session=...
Content-Type: application/x-www-form-urlencoded

to=1002&amount=50

The most important rule of web security follows directly: the client is not trusted. A browser sends what the page's form tells it to, but anyone can send any request with any headers and any body using a command-line tool or a proxy. Hidden form fields, JavaScript validation, disabled buttons, the Referer header, even the Origin header on requests that don't come from a browser, are all things an attacker controls. Client-side checks improve usability. Only server-side checks improve security.

Other details that matter: GET requests should never change state (links can be triggered by other sites), status codes should not leak internal details, and error pages should not print stack traces to visitors.

The same-origin policy

An origin is the combination of scheme, host and port. These three values decide whether two URLs belong to the same origin:

URL Same origin as https://shop.example/cart?
https://shop.example/pay Yes (only the path differs)
http://shop.example/cart No (scheme)
https://api.shop.example/cart No (host)
https://shop.example:8443/cart No (port)

The same-origin policy (SOP) says that a script running on one origin may not read data from another origin. This is why a page you visit cannot silently read your webmail in another tab, even though your browser is logged in to both. Notice what SOP does and doesn't do: it blocks reading responses, but a page can usually still send certain requests to other origins (a form post, an image load). That gap is the reason CSRF exists, covered in Cross-Site Scripting and CSRF Defense.

The model below parses URLs and decides whether they share an origin. It uses the standard URL object that both browsers and Node provide.

JS Same-origin check

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Two results are worth studying. https://shop.example:443/other is the same origin because 443 is the default port for HTTPS, so the URL object drops it. And the last URL looks like it starts with shop.example, but the host is shop.example.evil.test, which is a different site entirely. Checking origins with string prefixes such as startsWith("https://shop.example") is a classic bug, because it would accept that last URL. Always parse, then compare the parts.

CORS: a controlled exception

Sometimes a site wants another origin to read its responses, for example a front end on app.example calling an API on api.example. Cross-Origin Resource Sharing (CORS) lets the server opt in with headers such as Access-Control-Allow-Origin. The server should return an exact allowed origin from an allow-list. Two common mistakes are reflecting whatever Origin header arrives, and combining a wildcard with credentials. This model shows an allow-list policy:

JS CORS allow-list decision

Press Run (or Ctrl + Enter) to see the console output here.

No output.

CORS is enforced by the browser, not the server. A script run from the command line ignores it completely, so CORS is never a substitute for authentication.

Cookies and their flags

Cookies are small values the browser stores and attaches to later requests automatically. That automatic attachment is what makes them convenient and what makes them dangerous. Four attributes control most of the risk:

  • Secure: only send over HTTPS.
  • HttpOnly: scripts cannot read it through document.cookie.
  • SameSite=Lax or Strict: do not attach it to most cross-site requests.
  • Domain and Path: a cookie scoped to the parent domain is visible to every subdomain, including a forgotten test site.

Session cookies, covered in Authentication, Sessions and Access Control Flaws, should use all of the first three. Cookies that store preferences, like a theme name, need less protection, but they must never hold anything secret or trusted, such as isAdmin=true.

The OWASP Top 10

The OWASP Top 10 is a regularly updated awareness list of the most critical web application risk categories, published by the Open Worldwide Application Security Project. The ordering and names change between editions, so treat the list as a map of themes rather than a checklist to memorize. The recurring themes are:

  • Broken access control: users acting outside their permissions (IDOR, missing role checks).
  • Cryptographic failures: weak or missing protection for data in transit and at rest.
  • Injection: untrusted data interpreted as commands or queries (see SQL Injection).
  • Insecure design: flaws in the plan itself that no code fix can patch.
  • Security misconfiguration: default accounts, verbose errors, open cloud storage.
  • Vulnerable and outdated components: libraries with known flaws.
  • Identification and authentication failures: weak login and session handling.
  • Software and data integrity failures: unsigned updates, risky deserialization (see SSRF, Path Traversal, Deserialization and Upload Risks).
  • Logging and monitoring failures: attacks nobody noticed.
  • Server-side request forgery: the server tricked into calling internal URLs.

The list is useful in three ways: as a vocabulary shared with developers, as an outline for a test plan, and as a source of training topics. It is not a complete list of everything that can go wrong.

Testing proxies, in concept

A testing proxy is a program that sits between your browser and a web application and shows you every request and response. You can pause a request, edit a header or field, and forward the changed version, or replay saved requests as a different user. It is the main tool of authorized web testing because it lets the tester see and control exactly what the server receives, rather than only what the page's form allows.

The usual setup in a lab is: browser configured to use the proxy at 127.0.0.1 on a chosen port, the proxy's own certificate trusted so HTTPS traffic can be inspected, and the target restricted to a deliberately vulnerable app in your home lab. No proxy can run here, so there is nothing to type. The points to remember are the idea (observe, modify, replay) and the rule: use it only on systems you are authorized to test.

Putting it together

A beginner's mental checklist for any web feature is short:

  1. What does the client send, and can the server cope with anything in each field?
  2. Who is allowed to do this, and is that checked on the server?
  3. What would another origin be able to read or trigger?
  4. What is logged if somebody abuses it?

The next lessons take the biggest bug classes one at a time and show the same pattern in each: understand it, model it, fix it, detect it.

The OWASP Top 10, category by category

The list above names the themes. This walkthrough gives each one a plain-language test idea and the core prevention, in the order of the recent editions (names and ranking shift between editions, so check the current OWASP publication before you cite one in a report). Test ideas apply only to systems you are authorized to assess.

1. Broken access control. Test: log in as user A, then request user B's records, an admin page or a different tenant's data by changing IDs, paths or methods; try the same actions while logged out. Prevent: deny by default, check ownership and role on the server for every request, never rely on hidden links or client-side checks. See Burp Suite Workflow for the repeat-and-compare method.

2. Cryptographic failures. Test: look for cleartext transport, old TLS versions, weak or unsalted password hashes, secrets in URLs, sensitive data stored unencrypted. Prevent: TLS everywhere, modern algorithms, slow salted password hashing, managed keys, minimal data retention (Cryptography for Hackers).

3. Injection. Test: submit characters that are special in the target language (a quote for SQL, angle brackets for HTML, shell metacharacters) and watch for errors or changed behavior. Prevent: parameterized queries, safe APIs, strict input validation and context-aware output encoding (SQL Injection, XSS and CSRF).

4. Insecure design. Test: ask whether the plan is sound: can a workflow be skipped, a limit bypassed, a reset flow abused? These are business logic flaws. Prevent: threat modeling at design time (Threat Modeling), secure design patterns, abuse-case tests.

5. Security misconfiguration. Test: default accounts, directory listings, verbose errors, unnecessary services, missing headers, open cloud storage (Server Misconfiguration). Prevent: hardened, repeatable baselines, minimal installs, automated configuration checks.

6. Vulnerable and outdated components. Test: identify frameworks, libraries and server versions (banners, file names, dependency lists) and look them up in vulnerability databases. Prevent: keep an inventory (software bill of materials), update on a schedule, remove unused dependencies, subscribe to advisories.

7. Identification and authentication failures. Test: weak password rules, no lockout or throttling, predictable session IDs, sessions that survive logout, flawed reset flows, tokens with bad validation (Authentication Flaws). Prevent: multi-factor authentication, rate limiting, secure session handling, safe recovery flows.

8. Software and data integrity failures. Test: unsigned updates, pipelines that pull code from untrusted places, deserialization of untrusted data. Prevent: signed artifacts, verified dependencies, protected build pipelines, avoiding native deserialization of untrusted input.

9. Security logging and monitoring failures. Test: do logins, access-control failures and high-value actions leave logs? Would anyone notice a burst of failures? Prevent: log the right events with context, centralize and protect logs, alert and rehearse the response (Logging, Monitoring and SIEM Basics).

10. Server-side request forgery (SSRF). Test: any feature that fetches a URL on the user's behalf: can it reach internal addresses or cloud metadata services? Prevent: allow-lists of destinations, blocking internal ranges, network segmentation, no raw responses returned to the user (SSRF).

The stand-in turns this into a coverage tracker you can reuse for a test plan: it lists which categories have been examined, and prints what is still open.

Node.js Track Top 10 coverage in a test plan

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Coverage of the Top 10 is a floor, not a ceiling: it keeps a test from forgetting a whole class of problem, but real applications have issues outside the list.

The OWASP Web Security Testing Guide

The Web Security Testing Guide (WSTG) is a free, structured testing manual. Each chapter groups checks: information gathering, configuration and deployment, identity management, authentication, authorization, session management, input validation, error handling, cryptography, business logic, client-side testing and API testing. Every test has an ID, an objective, how to test and how to fix. The guide takes a scientific approach: state a hypothesis, test it, record evidence, repeat, so that results are reproducible and a retest is possible.

Tools such as WFuzz (a fuzzer that substitutes wordlist values into parts of a request) support the input-validation and discovery tests. Fuzzing is loud and can disrupt services, so agree the rate and the target before running it, and use the WSTG checklist to report coverage.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which URL is a DIFFERENT origin from https://shop.example/cart?

    The scheme differs (http vs https). Paths, query strings and the default port 443 do not change the origin.
  2. 2. What does the same-origin policy mainly prevent?

    SOP restricts reading cross-origin data. Sending some cross-site requests is still possible, which is why CSRF defenses are needed.
  3. 3. Why is checking an origin with startsWith('https://shop.example') unsafe?

    String prefixes are not hostnames. Parse the URL and compare scheme, host and port exactly.
  4. 4. A page's JavaScript checks that the amount is positive. What does this tell you about security?

    Client-side validation is for user experience. The server must validate every field again.
  5. 5. Which cookie attribute stops JavaScript from reading the cookie?

    HttpOnly hides the cookie from document.cookie, limiting what an XSS bug can steal.

Summary

  • HTTP requests are fully controlled by the client, so servers must validate and authorize everything.
  • An origin is scheme + host + port; the same-origin policy blocks cross-origin reads, not all cross-origin sends.
  • Compare origins by parsing URLs, never by string prefixes.
  • CORS is a browser-enforced opt-in; use an exact allow-list and never rely on it as authentication.
  • Session cookies should be Secure, HttpOnly and SameSite.
  • The OWASP Top 10 is a map of recurring risk themes and a shared vocabulary.
  • Testing proxies let authorized testers observe, edit and replay requests; real ones cannot run on this site.

Next: SQL Injection: Understanding and Preventing It.