An application may keep one connection open so the browser and server can exchange messages repeatedly. WebSocket is a protocol for that exchange. In the HTTP/1.1 model here, an upgrade handshake starts the connection; later messages carry application actions such as editing a note.
Accepting the connection does not authorize every message. Authentication identifies the session, and authorization decides whether its sender may perform each action on each object. This fictional policy says A may edit only notes owned by A. The server must apply that policy when processing an edit message.
Before you begin
- Recommended first
- Notes: scope, command, result, time, HTTP methods, headers, status codes, cookies, How a web app is put together, Same-origin policy, Clickjacking
- Estimated time
- 16 min reading, 16 min activity. Setup and optional practice may take longer.
- Where you work
- Use the fictional page source, requests and policy models printed here in any current desktop or mobile browser. No server, login, framed account page or socket connection is required.
- Without a lab
- Read each source fragment or model and predict its result in notes. Identify the boundary, the supporting fact and one limit, then compare with the activity rubric. This does not reproduce a browser exchange. Reading works without JavaScript. Checking requires JavaScript and a secure context; saving additionally requires usable browser storage.
After this lesson you can:
- Separate the upgrade from the messages that follow.
- Apply the ownership rule to A's read of note 7.
01Example
Worked message: A edits note 7, owned by A. The activity message is A reading note 7, owned by A.
Upgrade accepted. Messages may follow.
Worked message: A edits note 7, owner A.
The acceptance is not a grant over every note.02The handshake is not the edit
The worked edit names sender A and owner A, so it satisfies the edit rule. The activity changes the action to read. Notice the evidence limit: an edit-only rule does not establish a read policy. You can identify the sender, action and owner, but should not invent permission for an action the policy does not define.
Validate the handshake's origin and session as appropriate, then authorize and validate later messages. Session expiry can matter after the connection starts. These are separate checks at different boundaries. The printed handshake omits protocol details and is not a complete request to transmit or evidence of an observed socket connection.
Treat an accepted upgrade as the start of a connection, and apply the ownership rule to each later message.Model. A teaching model drawn by hand. It shows the idea, not real tool output.
Read the full explanation below.
Playback is optional. Step through at your own pace.
An accepted upgrade opens the message lane.
Follow the explanation
- An accepted upgrade opens the message lane.
- The later edit message must match owner A.
Read every state and value
1. An accepted upgrade opens the message lane.
- Messages shown
- upgrade
- Current message
- upgrade
- Policy decisions
- Status: permitted-model · Status: pending
- Participant roles
- Actor: Client A; Text: A supplies the worked edit of note 7. · Actor: WebSocket service; Text: Upgrade acceptance does not grant every note. · Actor: Note ownership policy; Text: Note 7 owner is A; each message needs a separate owner check.
2. The later edit message must match owner A.
- Messages shown
- upgrade · A edits note 7 · owner
- Current message
- owner
- Policy decisions
- Status: permitted-model · Status: permitted-model
- Participant roles
- Actor: Client A; Text: A supplies the worked edit of note 7. · Actor: WebSocket service; Text: This owner match does not grant edits to other notes. · Actor: Note ownership policy; Text: Worked message: A edits note 7, owner A.
03Decide the activity message
Read the evidence before comparing with the activity rubric. Do not open a socket.
Teaching model of a connection start. Not a captured handshake.
This card does not depend on a status number.
Request shape
GET /notes
Host: 127.0.0.1:8000
Upgrade: websocket
Connection: Upgrade
Response shape
the server accepts the upgrade
After acceptance, the connection carries messages.
The acceptance does not grant every later message.
{
"rule": "A may edit only notes whose owner is A",
"worked": {"from": "A", "action": "edit", "note": 7, "owner": "A"},
"activity": {"from": "A", "action": "read", "note": 7, "owner": "A"}
}
- Copy the edit rule and identify which action it covers.
- Read the activity sender, action, note and owner. Compare the activity action with the action named in the rule.
- Rubric: A is reading note 7 owned by A. The printed edit rule alone does not decide whether that read is permitted; a read policy is missing.
- Stop at that stated uncertainty. No WebSocket connection is required.
04Client-side case
Allow about fifteen minutes for the self-review case. For each row, state whether the decision belongs at a DOM insertion, a browser origin/framing boundary or a server action check. Explain one limit of the evidence. Core topics help prepare for later stages, while the map and advanced topics remain part of full Web security completion.
Original fictional client-side self-review. About fifteen minutes.
1. A paragraph must display the characters <b>tea</b>. Identify which kind of insertion keeps them as text and why.
2. POST /notes/12 carries the login cookie and token copper; the session expects silver. Apply the matching rule.
3. A browser preflight names an origin different from the response allow-origin. State the mismatch and what this does not establish about authorization.
4. An untrusted site tries to embed the notes page. Compare the parent policy with the color policy.
5. A connected socket from A sends an edit for note 7, owned by A. Apply the edit rule.
Rubric: text insertion preserves characters; the mismatched token fails; the preflight fails this origin check but does not supply an action-permission result; the parent policy restricts embedding; the same-owner edit satisfies the rule.
For each answer, cite the relevant fact and state that this is a model, not a live browser exchange.
05Optional challenge
Say what should happen to later messages if the session on the card has expired. The rubric is: the connection's earlier acceptance does not keep those messages authorized. About ten minutes.
06Fresh cases for the checks
Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.
Socket case A: fresh connection/message modelOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.
S1: the server accepts a connection upgrade for authenticated Lina.
S2: Lina sends an edit message for note 33, owner Lina.
S3: Lina sends an edit message for note 34, owner Oren.
S4: Lina sends a read message for note 35, owner Lina.
Policy supplied here: Lina may edit only notes owned by Lina. No read policy is supplied.
No socket connection or message was sent.
07Explain your evidence
Optional written self-check: explain one decision using the supplied case. No tool run is required.
Check your explanation: separate connection acceptance from message authorization; cite action and stored owner; avoid inventing a read policy from an edit rule; identify later validation and session-expiry checks.
08Common mistakes
If you allow every message because the upgrade was accepted, you skipped the per-message rule.
If you use an edit of note 7 as the activity, the activity action is a read. The owner is still A.
If you invent a status code, the card does not give you one.
References
- RFC 6455: The WebSocket Protocol
Sections 1 and 4 explain connection establishment and the later message exchange. The printed handshake remains an incomplete teaching model.
- PortSwigger: WebSockets
Explains this mechanism, its impact and defenses. Required reasoning uses the original evidence printed on this page.