Lawfare Group → Knowledge Institute → Lawfare Academy
← CS 220 — Web Applications, SQL and Software Engineering
Weeks 1–2
The web request, semantic HTML and accessibility
Learning objectives
- Explain and trace the mechanisms in the web request, semantic html and accessibility.
- Apply the method to the worked example and changed-condition exercise.
- Identify assumptions, failure cases and the evidence needed to justify a result.
Current study directions: the original Academy lessons, preparation chapters, worked explanations and complete optional models on LawfareGroup.com provide the required conceptual preparation. Retained publisher/reference chapters, source exercises and their historical assignment directions are optional further study. Outside visits and assessments are optional. Independent subject review and observed learner testing remain pending. This current notice supersedes earlier textbook-supported study directions preserved below and in historical companion pages.
A web application crosses a network boundary. A browser sends a request; a server responds with a status, headers and a representation. HTML gives content semantic structure, CSS controls presentation and JavaScript adds behavior. A polished appearance does not establish that the underlying form is accessible or that its data is trustworthy.
Start from native elements. A button expresses an action, an anchor expresses navigation and a label associates a form control with its name. Replacing a button with a clickable div requires rebuilding keyboard and accessibility behavior that the native element already provides. Heading order should reflect document structure rather than font size. A user should understand a control without relying only on color, position or a mouse.
Browser validation improves feedback but does not protect the server. A client can bypass a form entirely and send a request directly. Validate submitted data again at the server boundary, including type, length, allowed values and relationships. Preserve entered values after an error where appropriate and identify the specific field needing correction. Test keyboard navigation, narrow screens and error states rather than only a successful desktop screenshot.
Worked reasoning The labels are explicitly connected to inputs by matching for and id attributes. Names determine submitted field names. min and step describe client constraints, but the server must still reject negative or fractional hours and overlong descriptions. This form is a markup example; it requires an implemented POST /orders handler before it can save anything.
Extended teaching and laboratory
A browser form is a client convenience. A caller can send a request without using that form, alter hidden fields or repeat a submission. The server must establish identity, permission and domain validity independently. Distinguish malformed input, unauthenticated requests, unauthorized object access and conflicts; they require different handling even if all must avoid exposing private details.
Accessibility is also part of the interface contract. A visual caption is not necessarily a programmatic label. Associate labels and controls, identify errors in text, and preserve usable focus after errors. Client validation can improve that experience while server validation remains authoritative.
Worked problem An order form contains a hidden owner_id and min=0 on hours. A signed-in customer changes owner_id to another customer and sends hours=−3. Design the acceptance boundary.
Step-by-step reasoning 1. Resolve the customer from a verified server session. Do not adopt the body owner_id as authority.
- Validate hours against the server’s type and range contract. A client-side minimum cannot establish that this request satisfies it.
- Reject the request before inserting a row. Return an understandable error without revealing another customer’s records.
- On the form, connect the error to the hours control and retain the submitted non-sensitive values. Test a raw HTTP request as well as the browser path.
From an address to a representation
Consider a fictional repair service whose visitor opens `/orders/new`. The browser resolves the host name to a network address, establishes the appropriate connection, and for HTTPS negotiates an encrypted connection with certificate validation. Encryption protects the connection under its security assumptions; it does not establish that the application validates an order. The browser sends an HTTP request with a method, target and headers. The server selects a route and returns a status, headers and a body. A document can trigger additional requests for style sheets, scripts and images. A visible page is therefore the result of several operations, any of which can fail separately.
GET requests retrieve a representation and should not implement a business mutation such as creating an order. A POST can submit a proposed operation, but its method alone supplies neither permission nor exactly-once execution. The earlier duplicate-submission investigation still applies. A URL path identifies a resource or route; a query string supplies parameters; a fragment selects a location inside the retrieved document and is not sent as part of an ordinary HTTP request target. A request for `/orders?status=open#results` sends the path and query, while the browser uses `results` locally as a fragment target.
Distinguish protocol observations from domain conclusions. A 200 response says the HTTP request succeeded according to the server's response, but the application must still define the body contract. A 201 can represent creation, a redirect can lead to a retrieval page, a 400 can report malformed input, a 401 an authentication requirement, a 403 denied access and a 409 a state conflict. These examples are choices within a documented API, not instructions to expose confidential details in an error. A network failure after a POST leaves the caller uncertain: the server might have committed before the response was lost. Retry using the operation identity policy already taught in the native lesson.
Build a document whose structure explains its purpose
HTML describes a document tree. An element usually has a start tag, content and an end tag; attributes configure that element. Nest elements according to their content rules and close them coherently. Browser error recovery can produce a tree different from the indentation you intended. Inspect the resulting document structure rather than treating a forgiving render as proof of correct markup. Void elements such as input do not wrap child content.
The document head contains metadata such as a useful title, character encoding and viewport configuration. The body contains the visible document. Use a main landmark for the principal content, headings for section relationships, paragraphs for prose and lists for parallel items. A heading is not merely a large-font paragraph. A table represents data with row/column relationships and headers; CSS layout, rather than a table of empty cells, should position unrelated page regions. An informative image needs alternative text that serves its role; a decorative image generally needs an empty alternative rather than an invented description.
```html <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width,initial-scale=1"> <title>Request a repair visit</title> </head> <body> <a href="#main">Skip to request form</a> <main id="main"> <h1>Request a repair visit</h1> <p id="instructions">Describe the work. This example saves nothing by itself.</p> <form method="post" action="/orders" aria-describedby="instructions"> <label for="description">Work description</label> <textarea id="description" name="description" maxlength="120" required></textarea> <label for="hours">Whole hours</label> <input id="hours" name="hours" type="number" min="0" step="1" required> <label for="priority">Preferred scheduling</label> <select id="priority" name="priority"> <option value="routine">Routine</option> <option value="review">Request staff review</option> </select> <button type="submit">Send request</button> </form> </main> </body> </html> ```
The explicit labels use the controls' IDs. The names determine the submitted field names; an ID alone does not supply a form-data name. The select submits its selected value, not necessarily the visible explanatory wording. A textarea holds longer text. A radio group can express one choice among alternatives, while checkboxes express independent selections; decide the data contract before choosing a control. Within a form, specify a non-submitting action as `type="button"` so that an incidental button does not unexpectedly submit. Native constraints help a visitor correct input, while the server repeats authoritative validation as the preserved lesson explains.
The HTML example is an inspectable document, not a complete application. Its POST requires an implemented route. A secure session design may also require a CSRF mechanism, taught in the later security preparation. Do not add a hidden owner field and mistake it for identity. Do not display a success message before the actual persistence response. The lesson's original trust-boundary cases supply those application decisions.
CSS selects boxes and resolves competing declarations
A CSS rule associates a selector with declarations. `label { display:block; }` selects label elements. `.request-panel` selects elements carrying that class, and `#main` selects an ID. A descendant selector expresses ancestry, not adjacency in the source file. Several declarations can apply to one property. The cascade considers origin, importance and layers before specificity and order; within otherwise equal competing ordinary author rules, higher specificity wins, and a later declaration breaks an equal-specificity tie. Avoid treating “last rule wins” as a complete cascade algorithm. Inherited properties such as ordinary text color can pass from an ancestor; an explicit declaration on the child can replace the inherited value. Not every property inherits.
Each laid-out box has content, padding, border and margin. Under ordinary content-box sizing, a 300-pixel declared width plus 16-pixel padding on each side and two 2-pixel borders occupies 336 pixels before margins. Under border-box sizing, that same declared width includes padding and borders, leaving 264 pixels for content. This arithmetic is a box-model illustration; actual layout still follows the containing block, display mode and other constraints. A fixed width that fits one viewport can overflow another.
```css * { box-sizing: border-box; } body { margin: 0; font: 1rem/1.6 system-ui; } main { max-width: 60rem; margin-inline: auto; padding: 1rem; } form { display: grid; gap: .75rem; } input, textarea, select, button { font: inherit; max-width: 100%; } textarea { min-height: 8rem; } button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid #175b87; } @media (min-width: 48rem) { form { grid-template-columns: 1fr 2fr; } button { grid-column: 2; } } ```
Normal flow places ordinary block content sequentially. Flexbox is useful for arranging a set along a principal axis, with wrapping when appropriate. Grid coordinates rows and columns; the example uses one column by default and two at a declared available-width breakpoint. Absolute positioning removes an element from normal flow and needs a deliberate containing-block plan; using fixed coordinates for every form control makes text enlargement fragile. Responsive design responds to content and available space rather than assigning one layout to every device sold under a particular name. The viewport metadata allows a mobile browser to use an appropriate layout viewport; it does not make an overflowing layout responsive by itself.
At a narrow width, the labels and controls follow document order in a single column. At the example's wider breakpoint, alternating labels and controls occupy two columns. If help text is inserted, the grid placement must be reconsidered: a new child can shift later cells. Styling must not make the visual order contradict the keyboard/read order. Use relative constraints, test long words and permit content growth. A screenshot at one width cannot establish usable reflow at another width or at enlarged text.
Accessible operation is observable behavior
Test the form using the keyboard alone. Focus should reach the link and controls in a sensible order, remain visibly identifiable, and activate native controls with their expected keys. A placeholder is not a durable replacement for a label. Explain a failed field in text, associate its help/error with the control and set `aria-invalid="true"` when appropriate; remove that state after correction. An error summary can link to affected controls. When dynamically adding an error summary, choose a focus/status-announcement strategy deliberately rather than moving focus after every keystroke. Retain safe submitted values so recovery does not require re-entering unrelated work.
Color, contrast, screen-reader naming, zoom/reflow and keyboard behavior require their own observations. A successful automated label check does not establish that an error message is understandable or that a real screen-reader user completed the task. Likewise a mouse click on a custom div does not establish keyboard activation. Prefer native semantics and add ARIA only to describe behavior the implementation actually supplies. These are educational evaluation criteria, not a claim that this draft has already passed a complete accessibility audit.
Optional changed record and complete reasoning
A colleague removes `name="hours"`, replaces its label with a placeholder, sets the panel's content width to 300 pixels with 16-pixel padding and 2-pixel borders, and displays green “saved” text as soon as Submit is clicked. The viewport has only 320 pixels of available width. Explain each independent failure, repair it and describe the evidence you would collect. Then change the response to a 409 after the connection briefly appears stalled.
**Model reasoning.** Without a name, the hours control contributes no ordinary named entry for that field in the form submission; restore the name and inspect the actual request. A disappearing placeholder fails to provide the persistent explicit label used in the original design; restore the connected label and check its accessible name. The content-box arithmetic gives 336 pixels before margins, exceeding the available 320; use a fitting fluid constraint and border-box policy, then verify the resulting layout at narrow width and enlarged text. Green text communicates no persistence proof and cannot be the only indication of state; display pending until the actual response, then an explicit saved or failed/conflict state. A 409 calls for authorized state review and a deliberate resolution path, not an unconditional automatic overwrite. If a response was lost rather than received, use a stable operation ID to reconcile the ambiguous outcome; do not manufacture another order to make the banner appear successful.
Evaluate the optional response on four equal criteria: correct document/submission semantics; box/layout mechanism and changed-width reasoning; accessible error/focus recovery; and request/persistence/identity reasoning. Preserve the original unit's authorization and retry models; this addition supplies their missing document/layout preparation.
Optional provenance: MDN Forms and buttons in HTML and Responsive web design. Fresh consultation for this draft was limited to their displayed introductions, prerequisites and learning outcomes; full sections and linked demonstrations were not reviewed. All teaching, markup and fictional records above are original Academy material.
Apply the idea
An order form contains a hidden owner_id and min=0 on hours. A signed-in customer changes owner_id to another customer and sends hours=−3. Design the acceptance boundary.
A valid request is repeated after the browser loses the response. Explain how to avoid accidentally creating two orders while preserving a legitimate second order.
Read the worked reasoning
Use a stable submission identifier with a uniqueness constraint and a stored payload fingerprint. An identical retry returns the original result. A conflicting payload under the same identifier is rejected. A legitimate new order receives a new identifier. Disabling the submit button alone cannot protect against network retries or multiple clients.
Check understanding
What protects the server from a bypassed form?
- The required attribute alone
Feedback
A custom HTTP client can omit browser validation.
- A green submit button
Feedback
Color communicates no server-side guarantee.
- Server-side validation and authorization
Feedback
Client controls are useful feedback but are not a trust boundary.
Further reading
Current study directions: the original Academy lessons, preparation chapters, worked explanations and complete optional models on LawfareGroup.com provide the required conceptual preparation. Retained publisher/reference chapters, source exercises and their historical assignment directions are optional further study. Outside visits and assessments are optional. Independent subject review and observed learner testing remain pending. This current notice supersedes earlier textbook-supported study directions preserved below and in historical companion pages.
Use the complete original preparation chapter, preserved investigation and optional changed-record reasoning for this unit. Earlier source directions remain in immutable edition 4.