Security in depth · Unit 20
Web applications
Follow a request through identity checks, resource permissions, interpreters, and browser protections.
ATT&CK TA0001 Initial Access
Helpful before thisWeb application architecturesAuthentication
After this lesson you can
- describe a request's purpose, data, and intended state change
- distinguish account proof, resource permission, and safe interpretation
- explain why browser protections complement server-side controls
Lessons in this unit
Browse 27 lessons in this topic
- HTTP and proxiesRead requests, understand cookies, and separate transport protection from application permissions.11 min
- Mapping a web surfaceBuild a useful inventory of resources, identities, data flows, and uncertainty.9 min
- Understanding client-side JavaScriptFollow data through browser code and distinguish public configuration from privileged secrets.9 min
- Cross-site scriptingUnderstand browser parsing contexts, safe rendering, and why one encoding rule cannot fit every destination.11 min
- SQL injectionKeep query structure separate from values, and distinguish prevention from permission and impact.9 min
- Command and argument injectionUnderstand the difference between shell parsing and a program interpreting its arguments.9 min
- Files, uploads, and path boundariesFollow uploaded content from naming to storage, processing, and authorized retrieval.9 min
- Server-side trust boundariesUnderstand URL fetchers, templates, XML, and deserialization as distinct trust decisions.9 min
- Authentication and accessSeparate identity, sessions, token validation, and permission for each resource.9 min
- APIs and GraphQLReview object permissions, property permissions, and resource cost across different API styles.9 min
- Securing common applicationsConnect product inventory, identity, advisories, and maintainable hardening decisions.9 min
- Sessions: what happens after sign-inFollow a login from a fresh session to renewal, revocation, and a safe goodbye.11 min
- Browser boundaries: origins, CORS, and CSRFSeparate who may read a response from who may send a request.11 min
- Authorization: a decision for every objectWhy a valid login and an unpredictable identifier still do not establish permission.11 min
- Keep data separate from instructionsFollow one piece of text through validation, a database query, and a page.11 min
- Business logic: valid steps, invalid outcomesReason about money, workflow state, repeated requests, and the rules a business must preserve.11 min
- Every request crosses a boundaryReview a booking change by separating accepted data from permitted actions.3 min
- Output safety depends on contextDecide why a safe display name does not automatically make a profile link safe.4 min
- Query structure and values are differentReview a search design without confusing bound values with selectable query structure.3 min
- Uploads are a lifecycle, not a checkboxFollow one uploaded document through acceptance, processing, and retrieval.4 min
- Server fetches need destination policySeparate permission to import a picture from permission to use the server’s network.4 min
- Cookies do not prove action intentReview a cookie-based change without treating session recognition as proof of intent.3 min
- Caches must preserve privacy boundariesChoose a cache policy that preserves a personalized page’s intended audience.3 min
- Retries should not repeat consequencesUse a reservation ledger to reason about retries after an uncertain response.4 min
- Check and update must agreeRead a two-worker timeline and protect the last available seat.4 min
- Errors need useful but limited detailTurn an uncertain booking failure into useful messages for two audiences.4 min
- Case study: review a document-access policyUse supplied roles, documents, and review notes to decide what the server should permit and what evidence is missing.11 min
A web application receives messages and makes decisions. A book reservation might require a valid session, permission to use the account, an available copy, and a consistent database update. Security includes all these rules and extends beyond the sign-in screen.
HTTP defines application messages and semantics. It uses an underlying transport; HTTP/3 uses QUIC, while earlier common deployments use TCP. HTTPS protects communication in transit but does not decide who may edit an object or whether an application implements its business rules correctly.
Read the request’s purpose
A request has a method, destination, headers, and sometimes a body. Those fields can carry identifiers, user text, session evidence, and choices. A field’s name does not establish that its value is trustworthy.
For a fictional reservation, identify the book, account context, and desired action. The server should derive trusted identity from validated session evidence, verify the relevant permissions, and apply its reservation rules. It should not assume that a submitted account label is proof.
A request map records purpose, inputs, state changes, data sensitivity, and access rules. It includes reads as well as writes: an unauthorized disclosure can occur without changing the underlying record. A successful response code alone proves neither correct authorization nor successful business processing.
Authentication and authorization
Authentication establishes confidence in an account context. A cookie can maintain a session; a JWT is a token format; an API key may identify an application; a certificate-based method proves possession under a trust configuration. None is a universal substitute for validation.
Authorization decides whether that actor may act on this resource now. It can apply to authenticated or anonymous users. Ownership, role, organization, workflow stage, and other policy inputs may matter. Hiding a button helps the interface but cannot enforce an API’s permissions.
A member can reserve books. Can they edit every reservation?
No. Permission to use a feature and permission over a particular object are separate decisions. The service must check the reservation's owner and any legitimate staff role for each protected action.
Data must remain data
Injection occurs when untrusted content affects instructions or syntax. The relevant interpreter determines the prevention: parameterized database operations, context-appropriate output encoding, safe APIs, and tightly constrained dynamic choices have different jobs.
There is no single escaping function that safely handles SQL, HTML, shell syntax, and every template language. Parameterization also does not automatically cover identifiers or other elements a database API cannot bind; those choices need suitable design and validation.
File access and server-side fetching have additional boundaries. A syntactically valid path or URL may identify a resource the application should not access. Restrict permitted resources and operations independently of parsing.
Browser protections have specific roles
The Same-origin policy limits cross-origin script access, especially reading responses. Some cross-origin requests and embedded resources are permitted. CORS allows servers to declare selected cross-origin browser access; it does not replace authentication or authorization, and a failed browser read does not prove a request had no effect.
Cookies have distinct protections. Secure restricts transport, HttpOnly restricts script access to the cookie, and SameSite influences cross-site sending. Their exact behavior depends on browser rules and configuration.
CSRF abuses credentials the browser attaches automatically to an unwanted request. Appropriate request tokens, origin checks, and cookie policy help establish request legitimacy. XSS involves unauthorized script execution in a browser context. It may perform actions or read available page data even when HttpOnly prevents directly reading a session cookie. Cookie theft is not its only possible impact.
Choose a deeper lesson
| Topic | Next lesson |
|---|---|
| Messages and workflows | HTTP and mapping |
| Browser behavior | JavaScript and XSS |
| Interpreters | SQL and command injection concepts |
| Resource boundaries | Files and server-side services |
| Identity and clients | Authentication and APIs |
| Session and object decisions | Session lifecycle and object authorization |
| Rules across requests | Business logic and race-safe state changes |
| Apply the ideas | Document access review: decide from supplied people, resources, and policy. |
| Packaged software | Common applications |
A useful finding connects the observed behavior to an intended rule, affected data or action, and a specific correction. Distinguish what was observed from assumptions, and preserve only the sanitized evidence needed to explain the problem.
Work a request through five decisions
Consider an invented library service. Member Lina asks to cancel reservation R42. The session record identifies Lina, R42 belongs to Jo, and the policy permits cancellation only by the reservation owner or a librarian. Lina has the member role. These supplied facts are enough to decide the permission question: deny this cancellation.
Authentication succeeded, but it supplied only one input to authorization. The identifier R42 selects the object; it does not establish a relationship to Lina. A server should evaluate the actor, action, resource, and current policy before applying a state change. It should also return only the information that the caller is permitted to receive.
PredictThe interface hides the cancel button for R42. Does that change the server’s decision?
The decision remains deny. Hiding an unavailable action helps users, but a client interface is not the authority for the service. The same policy must cover browser, mobile, and other supported clients.
Now add a permitted cancellation of Lina’s own reservation. Permission alone does not settle concurrency: the reservation might already have been fulfilled. The service needs a defined state transition and a consistent update. If it later renders Lina’s explanation, that text needs a suitable output context. If it caches the response, its sharing policy must match the audience.
A useful review follows the same request through five questions: who is acting, which object is involved, which action is allowed now, how data is interpreted, and where the result may be retained or shared. The supplied records establish the R42 decision; they do not demonstrate that the deployed code implements it. That requires implementation and verification evidence.
Terms you met
Check yourself
No timer. No penalties. Read the explanation and try again whenever you like.
This lesson’s questions have changed. Your reading progress is saved; review the updated questions.
-
Lina is a member; reservation R42 belongs to Jo. Only owners or librarians may cancel. What should the service do?
Show the answer
Correct answer: Deny cancellation because Lina satisfies neither permitted relationship. Apply the stated rule to the specific actor, action, and resource; a member role alone is insufficient.
-
Lina may cancel her own reservation, but it was fulfilled before the update. Which additional control addresses this?
Show the answer
Correct answer: Check and enforce the allowed state transition consistently with the update. A permitted actor still needs an operation that is valid in the current state, including concurrent changes.
-
A mobile client omits the website's hidden-button rule. Where should the cancellation policy remain effective?
Show the answer
Correct answer: At the service handling the protected operation for every supported client. Client presentation can vary while the service consistently enforces the resource rule.
-
A cancellation explanation is displayed as plain text. Which design best preserves that purpose?
Show the answer
Correct answer: Use a text-oriented renderer and separately retain the cancellation access checks. The rendering context and action authorization are independent requirements.
-
Which supplied record would distinguish whether the specific cross-origin operation changed server state?
Show the answer
Correct answer: A correlated application record showing the request's permission decision and resulting state. It connects the specific request to its application handling and effect, rather than inferring an outcome from a browser message.
Try it
- WriteWrite the decision for Lina and R42 using actor, action, resource, rule, and result. Then change one supplied fact to make cancellation permitted. Add one state-transition requirement and one record you would need to verify the server enforces the rule.