[{"id":"websocketsadvanced-001","courseId":"websockets-advanced","domain":"opening-handshake","topic":"Purpose of the accept proof","prompt":"A client's handshake carries a Sec-WebSocket-Key. Put these steps the server takes to build its Sec-WebSocket-Accept reply in the order it performs them.","hint":"Each stage needs what the stage before it produced.","explain":"A server can show it speaks the protocol by running the client's input through a fixed recipe of mechanical transformations. Each transformation needs the output of the one before it.","source":"https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers","interaction":{"type":"sort","items":[{"text":"Join the client's Sec-WebSocket-Key with the magic string 258EAFA5-E914-47DA-95CA-C5AB0DC85B11","why":"The key and the fixed magic string must be combined before anything can be hashed."},{"text":"Take the SHA-1 hash of the joined string","why":"The hash is computed over the combined input, so it can only follow the join."},{"text":"Take the base64 encoding of that hash","why":"Encoding is applied to the finished hash, turning it into the text the server returns."},{"text":"Send it in the Sec-WebSocket-Accept header of the 101 response","why":"The derived value goes out last, in the reply that completes the handshake."}]},"options":[],"answer":"o:abcd","explanation":"The server builds Sec-WebSocket-Accept by concatenating the client's key with a magic string, taking the SHA-1 hash, and base64-encoding the result. This makes support obvious to the client and prevents a server from accepting a WebSocket connection while reading the data as HTTP.","concept":"The server builds Sec-WebSocket-Accept by concatenating the client's key with a magic string, taking the SHA-1 hash, and base64-encoding the result. This makes support obvious to the client and prevents a server from accepting a WebSocket connection while reading the data as HTTP.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Sec-WebSocket-Accept is derived from the client's key by a fixed recipe, which is how the client confirms WebSocket support."]},{"id":"websocketsadvanced-002","courseId":"websockets-advanced","domain":"opening-handshake","topic":"Security role of Sec-WebSocket-Key","prompt":"A colleague says the Sec-WebSocket-Key header stops a stranger from forging a WebSocket handshake, because only the real client can produce it. Which statement describes this header correctly?","hint":"Ask whether the value is a secret, or just computed from public rules.","explain":"A header can be designed to show deliberate intent without being a credential. A proof of who is asking needs something the sender holds privately, so ask whether this field has any such secret.","source":"https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Protocol_upgrade_mechanism","interaction":{"type":"single"},"options":[{"id":"a","text":"It is a secret the server issues, so only the client holding it can complete the upgrade.","whyNot":"The client adds this key itself; the server does not issue it, and the key proves no identity."},{"id":"b","text":"It only shows the client means to open a WebSocket; its value comes from a public algorithm, so it gives no real security.","why":"The key is derived by a defined algorithm anyone can run, so it confirms intent to upgrade rather than proving identity."},{"id":"c","text":"It encrypts the handshake so that intermediaries cannot read the request headers.","whyNot":"The key is a plain header value; it does not encrypt anything in the request."},{"id":"d","text":"It authenticates the user, so the server can tie the connection to a logged-in account.","whyNot":"The key identifies no user; any authentication has to come from separate headers or the application."}],"answer":"b","explanation":"The key is computed with an algorithm defined in the WebSocket specification, so it does not provide security. It helps stop non-WebSocket clients from inadvertently requesting a WebSocket connection.","concept":"The key is computed with an algorithm defined in the WebSocket specification, so it does not provide security. It helps stop non-WebSocket clients from inadvertently requesting a WebSocket connection.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Sec-WebSocket-Key blocks accidental non-WebSocket requests; it is not a defense against deliberate attackers."]},{"id":"websocketsadvanced-003","courseId":"websockets-advanced","domain":"opening-handshake","topic":"Forged Origin headers","prompt":"Your server checks the Origin header on every WebSocket handshake. Which TWO statements about this check are correct?","hint":"Think about which senders follow browser rules and which do not.","explain":"A header set by the browser can be a useful signal, but it only counts as proof if no other sender could write it. Consider who controls the bytes a client puts into its request.","source":"https://www.rfc-editor.org/rfc/rfc6455#section-10.2","interaction":{"type":"multiple","tellCount":true},"options":[{"id":"a","text":"A matching Origin proves the request came from a real browser.","whyNot":"Non-browser agents can send a faked Origin, so a matching value proves nothing about the sender."},{"id":"b","text":"Every browser sends an Origin header on a WebSocket handshake.","why":"All browsers send Origin, which is why a server can use it to check where a request came from."},{"id":"c","text":"Origin is a secret token, so the server can trust it as a login credential.","whyNot":"Origin is a plain header that a non-browser client can fake, so it cannot serve as a credential."},{"id":"d","text":"Answering a mismatched Origin with 403 Forbidden is a valid way to refuse the handshake.","why":"The server can send 403 Forbidden when it does not like the Origin, which is effective against cross-site hijacking."},{"id":"e","text":"Browsers send Origin only for logged-in users, so anonymous visitors never include it.","whyNot":"All browsers send an Origin header, whether or not anyone is logged in."},{"id":"f","text":"Non-browser clients are blocked from sending Origin, so the header is always reliable.","whyNot":"Non-browser agents can send a faked Origin, so the header cannot be relied on alone."}],"answer":"bd","explanation":"All browsers send Origin, so a server can compare it and answer a mismatch with 403 Forbidden, which is effective against cross-site WebSocket hijacking. Non-browser agents can fake Origin, so it proves nothing alone.","concept":"All browsers send Origin, so a server can compare it and answer a mismatch with 403 Forbidden, which is effective against cross-site WebSocket hijacking. Non-browser agents can fake Origin, so it proves nothing alone.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["Origin filters browser traffic; it does not authenticate a client, since a non-browser agent can fake it."]},{"id":"websocketsadvanced-004","courseId":"websockets-advanced","domain":"opening-handshake","topic":"Extended CONNECT for WebSocket over HTTP/2","prompt":"A developer moves a WebSocket handshake to HTTP/2 and sends an extended CONNECT request. The request still carries Connection: Upgrade and Upgrade: websocket from the HTTP/1.1 version. What is wrong?","hint":"Ask which header fields only make sense for one HTTP/1.1 connection.","explain":"A protocol built for one TCP connection can rely on fields that describe that whole connection. A multiplexed protocol carries many streams, so a request that opens one must be reshaped.","source":"https://www.rfc-editor.org/rfc/rfc8441#section-5","interaction":{"type":"single"},"options":[{"id":"a","text":"Nothing; HTTP/2 ignores these fields and passes them through unchanged.","whyNot":"HTTP/2 does not allow connection-wide fields like these, so they must not be sent in the request."},{"id":"b","text":"The method should be GET, with the upgrade fields kept as they are.","whyNot":"Extended CONNECT replaces the GET-based request, so the method is CONNECT."},{"id":"c","text":"Those two fields must be removed; HTTP/2 does not allow connection-wide fields like them.","why":"Connection and Upgrade are not part of HTTP/2 and must not be included in the CONNECT request."},{"id":"d","text":"Keep both fields, but write their names in lowercase, as HTTP/2 requires.","whyNot":"Lowercase names are required in HTTP/2, but these two fields must be left out entirely, not renamed."}],"answer":"c","explanation":"Under HTTP/2 the extended CONNECT replaces the GET-based upgrade. Connection and Upgrade are not part of HTTP/2 and must not be included; :protocol set to websocket identifies the protocol instead.","concept":"Under HTTP/2 the extended CONNECT replaces the GET-based upgrade. Connection and Upgrade are not part of HTTP/2 and must not be included; :protocol set to websocket identifies the protocol instead.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["On HTTP/2 a WebSocket opens with an extended CONNECT carrying :protocol websocket, and HTTP/1.1 upgrade fields are dropped."]},{"id":"websocketsadvanced-005","courseId":"websockets-advanced","domain":"opening-handshake","topic":"SETTINGS_ENABLE_CONNECT_PROTOCOL","prompt":"Statement: After a server receives SETTINGS_ENABLE_CONNECT_PROTOCOL with the value 1 from a client, the server must start using extended CONNECT for its own requests.","hint":"Consider which peer the setting actually gives permission to.","explain":"Some protocol settings are opt-ins: one peer announces it accepts a new kind of request, and that announcement changes what the other peer may do. Ask which peer the announcement empowers.","source":"https://www.rfc-editor.org/rfc/rfc8441#section-3","interaction":{"type":"true-false"},"options":[{"id":"a","text":"True","whyNot":"The server's receipt of the parameter has no impact; it is the client that may use extended CONNECT after it."},{"id":"b","text":"False","why":"Receiving the setting changes nothing for the server; it only lets a client use the extended form when creating streams."}],"answer":"b","explanation":"SETTINGS_ENABLE_CONNECT_PROTOCOL set to 1 lets a client use Extended CONNECT when creating streams. Receipt of this parameter by a server does not have any impact.","concept":"SETTINGS_ENABLE_CONNECT_PROTOCOL set to 1 lets a client use Extended CONNECT when creating streams. Receipt of this parameter by a server does not have any impact.","rev":1,"updatedAt":"2026-10-26","kind":"scenario","takeaways":["SETTINGS_ENABLE_CONNECT_PROTOCOL opts clients in to Extended CONNECT; a server receiving it has no impact."]}]