[{"data":1,"prerenderedAt":1933},["ShallowReactive",2],{"announcement":3,"i-tabler:sun":11,"i-tabler:moon":16,"i-tabler:menu-2":18,"i-tabler:x":20,"i-simple-icons:youtube":22,"i-simple-icons:github":24,"i-simple-icons:x":26,"i-simple-icons:linkedin":28,"i-tabler:arrow-up-right":31,"post-resolved-perfect-cors-zero-protection":33,"post-nav-resolved-perfect-cors-zero-protection":1891,"post-ads":1897,"video-resolved-perfect-cors-zero-protection":1898,"i-simple-icons:reddit":1905,"i-tabler:link":1907,"i-tabler:copy":1909,"i-tabler:focus-centered":1911,"i-tabler:arrows-maximize":1913,"i-tabler:device-desktop":1915,"i-tabler:browser":1917,"i-tabler:key":1919,"i-tabler:shield-off":1921,"i-tabler:alert-octagon":1923,"i-tabler:alert-circle":1925,"i-tabler:server":1927,"i-tabler:affiliate":1929,"i-tabler:database":1931},{"startsAt":4,"endsAt":5,"scramble":6,"cta":7,"message":10},"2026-11-25T10:00:00-03:00","2026-12-22","Hey, check out the latest article:",{"href":8,"label":9},"\u002Fresolved-perfect-cors-zero-protection","Read it","Resolved: Perfect CORS, Zero Protection.",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":15},0,24,false,"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M8 12a4 4 0 1 0 8 0a4 4 0 1 0-8 0m-5 0h1m8-9v1m8 8h1m-9 8v1M5.6 5.6l.7.7m12.1-.7l-.7.7m0 11.4l.7.7m-12.1-.7l-.7.7\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":17},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M12 3h.393a7.5 7.5 0 0 0 7.92 12.446A9 9 0 1 1 12 2.992z\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":19},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M4 6h16M4 12h16M4 18h16\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":21},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M18 6L6 18M6 6l12 12\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":23},"\u003Cpath fill=\"currentColor\" d=\"M23.498 6.186a3.02 3.02 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.02 3.02 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.02 3.02 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.02 3.02 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814M9.545 15.568V8.432L15.818 12z\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":25},"\u003Cpath fill=\"currentColor\" d=\"M12 .297c-6.63 0-12 5.373-12 12c0 5.303 3.438 9.8 8.205 11.385c.6.113.82-.258.82-.577c0-.285-.01-1.04-.015-2.04c-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729c1.205.084 1.838 1.236 1.838 1.236c1.07 1.835 2.809 1.305 3.495.998c.108-.776.417-1.305.76-1.605c-2.665-.3-5.466-1.332-5.466-5.93c0-1.31.465-2.38 1.235-3.22c-.135-.303-.54-1.523.105-3.176c0 0 1.005-.322 3.3 1.23c.96-.267 1.98-.399 3-.405c1.02.006 2.04.138 3 .405c2.28-1.552 3.285-1.23 3.285-1.23c.645 1.653.24 2.873.12 3.176c.765.84 1.23 1.91 1.23 3.22c0 4.61-2.805 5.625-5.475 5.92c.42.36.81 1.096.81 2.22c0 1.606-.015 2.896-.015 3.286c0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":27},"\u003Cpath fill=\"currentColor\" d=\"M14.234 10.162L22.977 0h-2.072l-7.591 8.824L7.251 0H.258l9.168 13.343L.258 24H2.33l8.016-9.318L16.749 24h6.993zm-2.837 3.299l-.929-1.329L3.076 1.56h3.182l5.965 8.532l.929 1.329l7.754 11.09h-3.182z\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":29,"hidden":30},"\u003Cpath fill=\"currentColor\" d=\"M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037c-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85c3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433a2.06 2.06 0 0 1-2.063-2.065a2.064 2.064 0 1 1 2.063 2.065m1.782 13.019H3.555V9h3.564zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0z\"\u002F>",true,{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":32},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M17 7L7 17M8 7h9v9\"\u002F>",{"id":34,"title":35,"body":36,"categories":1869,"cover":1872,"coverImage":1883,"date":4,"description":1884,"draft":14,"extension":1885,"meta":1886,"navigation":30,"noindex":14,"path":8,"readingTime":1887,"seo":1888,"slug":1889,"stem":1889,"updatedAt":1887,"youtubeId":42,"__hash__":1890},"blog\u002Fresolved-perfect-cors-zero-protection.md","Resolved: Perfect CORS, Zero Protection",{"type":37,"value":38,"toc":1851},"minimark",[39,43,47,50,53,56,59,70,75,78,81,98,134,147,150,154,157,180,183,233,255,260,264,267,288,295,298,302,305,344,347,353,359,366,465,472,479,482,485,488,492,495,573,576,634,642,679,682,699,703,706,846,849,852,856,862,881,888,891,894,973,976,1011,1014,1017,1021,1033,1036,1043,1112,1115,1119,1126,1129,1137,1145,1149,1152,1155,1158,1161,1176,1179,1192,1195,1198,1202,1205,1208,1211,1217,1223,1226,1229,1235,1239,1242,1258,1264,1270,1273,1277,1280,1329,1332,1335,1339,1345,1742,1759,1765,1769,1777,1780,1783,1789,1793,1847],[40,41],"post-media",{"video":42},"TnALrApXdkw",[44,45,46],"p",{},"A website you have never heard of can read your private documents. You do not click anything on it. You do not sign into it. You land on a page, and it reads them.",[44,48,49],{},"The part that stayed with me is that the app it came from was not broken. Every permission check ran. The CORS allowlist was configured properly, with exactly one origin on it. I went after a document the obvious way and the server shut me out.",[44,51,52],{},"Then I asked for the same document a second way, and it handed over the whole thing.",[44,54,55],{},"That bug was high severity, and it paid a four digit bounty. What fixed it was one check, on one endpoint, that nobody had ever written.",[44,57,58],{},"This is the first article in Resolved, a series where I go back through my own resolved reports, pick one, and walk you through the whole thing from the first request to the patch.",[60,61,67],"sponsor",{"cta":62,"href":63,"logo":64,"name":65,"untracked":66},"Try ego lite","https:\u002F\u002Flink.ego.app\u002FAmrSec","egolite","ego lite","true",[44,68,69],{},"Stop babysitting tabs. ego lite is a browser for AI agents, so Claude Code drives the real thing, signed in as you, reaching the pages that only exist after you log in. Several agents run at once and none of them touch the tab you are in. Mac and Windows, your browsing data stays on your machine, free.",[71,72,74],"h2",{"id":73},"how-the-app-is-built","How The App Is Built",[44,76,77],{},"The app was a documents workspace. Sidebar full of your files, editor in the middle, everything saving as you type and waiting for you on whatever device you sign in from next.",[44,79,80],{},"It was built the way most of them are built. Two parts.",[82,83,84,92],"ul",{},[85,86,87,91],"li",{},[88,89,90],"strong",{},"The front end."," The interface you look at. It stores nothing at all.",[85,93,94,97],{},[88,95,96],{},"The backend."," A separate service on its own subdomain, holding the accounts, the sessions and every document.",[99,100,105],"pre",{"code":101,"language":102,"meta":103,"className":104,"style":103},"flowchart LR\n    U[\"Your browser\"] --> F[\"Front end on app.example.lab\"]\n    F -->|\"every request for data is cross-origin\"| B[\"Backend on api.example.lab\"]\n    B --> S[(\"Accounts, sessions, documents\")]\n","mermaid","","shiki shiki-themes vitesse-dark vitesse-light",[106,107,108,116,122,128],"code",{},[109,110,113],"span",{"class":111,"line":112},"line",1,[109,114,115],{},"flowchart LR\n",[109,117,119],{"class":111,"line":118},2,[109,120,121],{},"    U[\"Your browser\"] --> F[\"Front end on app.example.lab\"]\n",[109,123,125],{"class":111,"line":124},3,[109,126,127],{},"    F -->|\"every request for data is cross-origin\"| B[\"Backend on api.example.lab\"]\n",[109,129,131],{"class":111,"line":130},4,[109,132,133],{},"    B --> S[(\"Accounts, sessions, documents\")]\n",[44,135,136,137,146],{},"That split is where all of this starts. An origin is a scheme, a host and a port, and ",[138,139,145],"a",{"href":140,"rel":141,"target":144},"https:\u002F\u002Fdatatracker.ietf.org\u002Fdoc\u002Fhtml\u002Frfc6454?utm_source=amrelsagaei.com&utm_medium=referral",[142,143],"noopener","noreferrer","_blank","all three have to match",". Here the scheme matched and the port matched. The host did not.",[44,148,149],{},"So every single request the front end made for your own data crossed an origin boundary. That is the only reason the backend carried CORS rules at all. Strip them out and the browser stops letting the app read its own API.",[71,151,153],{"id":152},"the-session-cookie-that-covers-both-domains","The Session Cookie That Covers Both Domains",[44,155,156],{},"One login had to work across both names, so the cookie came back scoped to the parent domain:",[99,158,161],{"code":159,"language":160,"meta":103,"className":104,"style":103},"Set-Cookie: ntl_session=...; Path=\u002F; Domain=.example.lab; Max-Age=31536000; Secure; SameSite=None; HttpOnly\nSet-Cookie: csrf_token=...; Path=\u002F; Domain=.example.lab; Max-Age=31536000; Secure; SameSite=None\n","http",[106,162,163,173],{},[109,164,165,169],{"class":111,"line":112},[109,166,168],{"class":167},"sR8n-","Set-Cookie:",[109,170,172],{"class":171},"sRRDT"," ntl_session=...; Path=\u002F; Domain=.example.lab; Max-Age=31536000; Secure; SameSite=None; HttpOnly\n",[109,174,175,177],{"class":111,"line":118},[109,176,168],{"class":167},[109,178,179],{"class":171}," csrf_token=...; Path=\u002F; Domain=.example.lab; Max-Age=31536000; Secure; SameSite=None\n",[44,181,182],{},"Three attributes decide the rest of this article.",[184,185,186,199],"table",{},[187,188,189],"thead",{},[190,191,192,196],"tr",{},[193,194,195],"th",{},"Attribute",[193,197,198],{},"What it does here",[200,201,202,213,223],"tbody",{},[190,203,204,210],{},[205,206,207],"td",{},[106,208,209],{},"Domain=.example.lab",[205,211,212],{},"Scopes the cookie to the parent domain, so the front end and the backend both receive it",[190,214,215,220],{},[205,216,217],{},[106,218,219],{},"Secure",[205,221,222],{},"Restricts it to TLS",[190,224,225,230],{},[205,226,227],{},[106,228,229],{},"SameSite=None",[205,231,232],{},"Attaches it to requests started by any other site",[44,234,235,242,243,246,247,250,251,254],{},[138,236,239],{"href":237,"rel":238,"target":144},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FHTTP\u002FReference\u002FHeaders\u002FSet-Cookie?utm_source=amrelsagaei.com&utm_medium=referral",[142,143],[106,240,241],{},"SameSite"," controls whether a cookie rides along on a request another site caused. ",[106,244,245],{},"Strict"," never sends it. ",[106,248,249],{},"Lax"," sends it only on a top-level navigation. ",[106,252,253],{},"None"," always sends it.",[44,256,257,259],{},[106,258,253],{}," was the correct choice. The front end sits on a different origin to the backend, so anything stricter breaks the product on day one. Hold onto it anyway.",[71,261,263],{"id":262},"two-ways-into-one-document","Two Ways Into One Document",[44,265,266],{},"Open one document with a proxy running and two requests land in your history.",[99,268,270],{"code":269,"language":160,"meta":103,"className":104,"style":103},"GET \u002Fdocuments\u002F2998236137      HTTP\u002F1.1   -> 200 OK\nGET \u002Fdocuments\u002F2998236137\u002Fws   HTTP\u002F1.1   -> 101 Switching Protocols\n",[106,271,272,281],{},[109,273,274,277],{"class":111,"line":112},[109,275,276],{"class":167},"GET",[109,278,280],{"class":279},"sG2Fq"," \u002Fdocuments\u002F2998236137      HTTP\u002F1.1   -> 200 OK\n",[109,282,283,285],{"class":111,"line":118},[109,284,276],{"class":167},[109,286,287],{"class":279}," \u002Fdocuments\u002F2998236137\u002Fws   HTTP\u002F1.1   -> 101 Switching Protocols\n",[44,289,290,291,294],{},"Same backend, same document, same cookie. One returns JSON. The other returns ",[106,292,293],{},"101 Switching Protocols",", which is the server agreeing to stop speaking HTTP on that connection and speak something else instead.",[44,296,297],{},"Two doors into the same room. Work through one completely before you touch the other, because jumping between them is how you end up confusing yourself.",[71,299,301],{"id":300},"what-cors-actually-blocks","What CORS Actually Blocks",[44,303,304],{},"Send the JSON request to your repeater untouched and the response carries two headers worth reading:",[99,306,308],{"code":307,"language":160,"meta":103,"className":104,"style":103},"HTTP\u002F1.1 200 OK\nAccess-Control-Allow-Origin: https:\u002F\u002Fapp.example.lab\nAccess-Control-Allow-Credentials: true\n",[106,309,310,328,336],{},[109,311,312,315,318,322,325],{"class":111,"line":112},[109,313,314],{"class":167},"HTTP",[109,316,317],{"class":279},"\u002F",[109,319,321],{"class":320},"sUQhE","1.1",[109,323,324],{"class":320}," 200",[109,326,327],{"class":171}," OK\n",[109,329,330,333],{"class":111,"line":118},[109,331,332],{"class":167},"Access-Control-Allow-Origin:",[109,334,335],{"class":171}," https:\u002F\u002Fapp.example.lab\n",[109,337,338,341],{"class":111,"line":124},[109,339,340],{"class":167},"Access-Control-Allow-Credentials:",[109,342,343],{"class":171}," true\n",[44,345,346],{},"The browser asks a question on your behalf here. Some page is about to receive this response. Is the origin it sits on cleared to read it?",[44,348,349,352],{},[106,350,351],{},"Access-Control-Allow-Origin"," is the answer, and it names exactly one origin. Nothing else gets in.",[44,354,355,358],{},[106,356,357],{},"Access-Control-Allow-Credentials"," answers the second half, which is whether the request was allowed to carry cookies at all. A browser needs both of them before it will release a credentialed response to a cross-origin page.",[44,360,361,362,365],{},"Now change ",[106,363,364],{},"Origin"," to a domain you control and send it again.",[99,367,369],{"code":368,"language":160,"meta":103,"className":104,"style":103},"HTTP\u002F1.1 200 OK\n\n{\"docId\":2998236137,\"ownerId\":3401776219,\"title\":\"Q4 account review\",\"body\":\"...\"}\n",[106,370,371,383,388],{},[109,372,373,375,377,379,381],{"class":111,"line":112},[109,374,314],{"class":167},[109,376,317],{"class":279},[109,378,321],{"class":320},[109,380,324],{"class":320},[109,382,327],{"class":171},[109,384,385],{"class":111,"line":118},[109,386,387],{"emptyLinePlaceholder":30},"\n",[109,389,390,394,398,402,404,407,410,413,415,418,420,422,425,427,429,432,434,436,439,442,444,446,448,451,453,455,457,460,462],{"class":111,"line":124},[109,391,393],{"class":392},"somML","{",[109,395,397],{"class":396},"sIkdJ","\"",[109,399,401],{"class":400},"s6_DI","docId",[109,403,397],{"class":396},[109,405,406],{"class":392},":",[109,408,409],{"class":320},"2998236137",[109,411,412],{"class":392},",",[109,414,397],{"class":396},[109,416,417],{"class":400},"ownerId",[109,419,397],{"class":396},[109,421,406],{"class":392},[109,423,424],{"class":320},"3401776219",[109,426,412],{"class":392},[109,428,397],{"class":396},[109,430,431],{"class":400},"title",[109,433,397],{"class":396},[109,435,406],{"class":392},[109,437,397],{"class":438},"sy_C3",[109,440,441],{"class":171},"Q4 account review",[109,443,397],{"class":438},[109,445,412],{"class":392},[109,447,397],{"class":396},[109,449,450],{"class":400},"body",[109,452,397],{"class":396},[109,454,406],{"class":392},[109,456,397],{"class":438},[109,458,459],{"class":171},"...",[109,461,397],{"class":438},[109,463,464],{"class":392},"}\n",[44,466,467,468,471],{},"Status ",[106,469,470],{},"200",". Full document. Both CORS headers gone.",[44,473,474,475,478],{},"This is the part people have backwards. ",[88,476,477],{},"The server did not block you."," It never does. It processed the request, returned the data, and withheld only its permission for your page to look at what it sent.",[44,480,481],{},"Discarding the response is the browser's job, not the server's.",[44,483,484],{},"Which means CORS will never look like a block inside your proxy. If you only test through a repeater you will not see it, and you will not miss it either.",[44,486,487],{},"So the JSON side is fine. Configured properly, enforced properly, nothing there to write up.",[71,489,491],{"id":490},"the-websocket-handshake-line-by-line","The WebSocket Handshake, Line By Line",[44,493,494],{},"A WebSocket does not start life as a WebSocket. It starts as an ordinary GET.",[99,496,498],{"code":497,"language":160,"meta":103,"className":104,"style":103},"GET \u002Fdocuments\u002F2998236137\u002Fws HTTP\u002F1.1\nHost: api.example.lab\nUpgrade: websocket\nConnection: Upgrade\nSec-WebSocket-Key: 9fyqhjFGlA\u002FIVnIRwP2Umw==\nSec-WebSocket-Version: 13\nOrigin: https:\u002F\u002Fapp.example.lab\nCookie: ntl_session=...\n",[106,499,500,514,522,530,538,547,556,564],{},[109,501,502,504,507,509,511],{"class":111,"line":112},[109,503,276],{"class":167},[109,505,506],{"class":279}," \u002Fdocuments\u002F2998236137\u002Fws ",[109,508,314],{"class":167},[109,510,317],{"class":279},[109,512,513],{"class":320},"1.1\n",[109,515,516,519],{"class":111,"line":118},[109,517,518],{"class":167},"Host:",[109,520,521],{"class":171}," api.example.lab\n",[109,523,524,527],{"class":111,"line":124},[109,525,526],{"class":167},"Upgrade:",[109,528,529],{"class":171}," websocket\n",[109,531,532,535],{"class":111,"line":130},[109,533,534],{"class":167},"Connection:",[109,536,537],{"class":171}," Upgrade\n",[109,539,541,544],{"class":111,"line":540},5,[109,542,543],{"class":167},"Sec-WebSocket-Key:",[109,545,546],{"class":171}," 9fyqhjFGlA\u002FIVnIRwP2Umw==\n",[109,548,550,553],{"class":111,"line":549},6,[109,551,552],{"class":167},"Sec-WebSocket-Version:",[109,554,555],{"class":171}," 13\n",[109,557,559,562],{"class":111,"line":558},7,[109,560,561],{"class":167},"Origin:",[109,563,335],{"class":171},[109,565,567,570],{"class":111,"line":566},8,[109,568,569],{"class":167},"Cookie:",[109,571,572],{"class":171}," ntl_session=...\n",[44,574,575],{},"Every line is doing a job:",[82,577,578,586,594,608,616,627],{},[85,579,580,585],{},[88,581,582],{},[106,583,584],{},"Upgrade: websocket"," asks the server to move this connection off HTTP and onto the WebSocket protocol.",[85,587,588,593],{},[88,589,590],{},[106,591,592],{},"Connection: Upgrade"," tells every proxy and load balancer in between that this specific connection is being switched, so nothing pools it or reuses it afterwards.",[85,595,596,601,602,607],{},[88,597,598],{},[106,599,600],{},"Sec-WebSocket-Version: 13"," is the protocol version from ",[138,603,606],{"href":604,"rel":605,"target":144},"https:\u002F\u002Fdatatracker.ietf.org\u002Fdoc\u002Fhtml\u002Frfc6455?utm_source=amrelsagaei.com&utm_medium=referral",[142,143],"RFC 6455",". Thirteen is the only one in use.",[85,609,610,615],{},[88,611,612],{},[106,613,614],{},"Sec-WebSocket-Key"," is sixteen random bytes, base64 encoded.",[85,617,618,623,624,626],{},[88,619,620],{},[106,621,622],{},"Cookie"," rides along because of ",[106,625,229],{},".",[85,628,629,633],{},[88,630,631],{},[106,632,364],{}," is the browser naming the site that caused the request.",[44,635,636,638,639,406],{},[106,637,614],{}," gets misread constantly. It is not authentication. The server appends a fixed GUID from the RFC, hashes the result with SHA-1, and returns it as ",[106,640,641],{},"Sec-WebSocket-Accept",[99,643,646],{"code":644,"language":645,"meta":103,"className":104,"style":103},"base64(sha1(key + \"258EAFA5-E914-47DA-95CA-C5AB0DC85B11\"))\n","python",[106,647,648],{},[109,649,650,653,656,659,661,664,668,671,674,676],{"class":111,"line":112},[109,651,652],{"class":279},"base64",[109,654,655],{"class":392},"(",[109,657,658],{"class":279},"sha1",[109,660,655],{"class":392},[109,662,663],{"class":279},"key ",[109,665,667],{"class":666},"sfIIG","+",[109,669,670],{"class":438}," \"",[109,672,673],{"class":171},"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",[109,675,397],{"class":438},[109,677,678],{"class":392},"))\n",[44,680,681],{},"All that proves is the other end speaks WebSocket and you are not looking at a cached response. It protects nothing and identifies nobody.",[44,683,684,686,687,690,691,694,695,698],{},[106,685,364],{}," is the one that counts. It names the page that triggered the request, not the address being requested, and ",[88,688,689],{},"a page cannot set it",". Not from ",[106,692,693],{},"fetch",", not from ",[106,696,697],{},"new WebSocket",". The browser writes it and locks it. That makes it the only value on the request a server can actually trust.",[71,700,702],{"id":701},"what-the-server-sends-before-you-ask","What The Server Sends Before You Ask",[44,704,705],{},"Open the stream before touching anything and there is a single message, server to client:",[99,707,710],{"code":708,"language":709,"meta":103,"className":104,"style":103},"{\n  \"doc\": { \"ops\": [{ \"insert\": \"Calderwell account review, Q4\\n...\" }] },\n  \"doc_len\": 419,\n  \"vsn\": 4,\n  \"title\": \"Q4 account review\",\n  \"op\": \"init\"\n}\n","json",[106,711,712,717,772,789,805,823,842],{},[109,713,714],{"class":111,"line":112},[109,715,716],{"class":392},"{\n",[109,718,719,722,725,727,729,732,734,737,739,741,744,746,749,751,753,755,758,762,764,766,769],{"class":111,"line":118},[109,720,721],{"class":396},"  \"",[109,723,724],{"class":400},"doc",[109,726,397],{"class":396},[109,728,406],{"class":392},[109,730,731],{"class":392}," {",[109,733,670],{"class":396},[109,735,736],{"class":400},"ops",[109,738,397],{"class":396},[109,740,406],{"class":392},[109,742,743],{"class":392}," [{",[109,745,670],{"class":396},[109,747,748],{"class":400},"insert",[109,750,397],{"class":396},[109,752,406],{"class":392},[109,754,670],{"class":438},[109,756,757],{"class":171},"Calderwell account review, Q4",[109,759,761],{"class":760},"se4ZP","\\n",[109,763,459],{"class":171},[109,765,397],{"class":438},[109,767,768],{"class":392}," }]",[109,770,771],{"class":392}," },\n",[109,773,774,776,779,781,783,786],{"class":111,"line":124},[109,775,721],{"class":396},[109,777,778],{"class":400},"doc_len",[109,780,397],{"class":396},[109,782,406],{"class":392},[109,784,785],{"class":320}," 419",[109,787,788],{"class":392},",\n",[109,790,791,793,796,798,800,803],{"class":111,"line":130},[109,792,721],{"class":396},[109,794,795],{"class":400},"vsn",[109,797,397],{"class":396},[109,799,406],{"class":392},[109,801,802],{"class":320}," 4",[109,804,788],{"class":392},[109,806,807,809,811,813,815,817,819,821],{"class":111,"line":540},[109,808,721],{"class":396},[109,810,431],{"class":400},[109,812,397],{"class":396},[109,814,406],{"class":392},[109,816,670],{"class":438},[109,818,441],{"class":171},[109,820,397],{"class":438},[109,822,788],{"class":392},[109,824,825,827,830,832,834,836,839],{"class":111,"line":549},[109,826,721],{"class":396},[109,828,829],{"class":400},"op",[109,831,397],{"class":396},[109,833,406],{"class":392},[109,835,670],{"class":438},[109,837,838],{"class":171},"init",[109,840,841],{"class":438},"\"\n",[109,843,844],{"class":111,"line":558},[109,845,464],{"class":392},[44,847,848],{},"Nothing went up. No subscribe frame, no fetch, no ID sent after connecting. The socket opened and the server volunteered the entire document.",[44,850,851],{},"That saves a round trip, which is why it was built this way. It also means the connection is the exploit. Open it and you have the data.",[71,853,855],{"id":854},"faking-where-the-request-came-from","Faking Where The Request Came From",[44,857,858,859,861],{},"Same move as before, this time on the handshake. Replay the upgrade with an ",[106,860,364],{}," you control.",[99,863,865],{"code":864,"language":160,"meta":103,"className":104,"style":103},"HTTP\u002F1.1 101 Switching Protocols\n",[106,866,867],{},[109,868,869,871,873,875,878],{"class":111,"line":112},[109,870,314],{"class":167},[109,872,317],{"class":279},[109,874,321],{"class":320},[109,876,877],{"class":320}," 101",[109,879,880],{"class":171}," Switching Protocols\n",[44,882,883,884,887],{},"It agreed. If an origin check existed on that endpoint, this is exactly where it would have fired and returned ",[106,885,886],{},"403"," before a single frame moved.",[44,889,890],{},"Read what that status line means. The server received a request announcing a foreign origin, saw a session cookie belonging to somebody with no relationship to that origin, and opened the connection anyway.",[44,892,893],{},"Then it gets worse, because you can start removing things.",[184,895,896,911],{},[187,897,898],{},[190,899,900,905,908],{},[193,901,902,904],{},[106,903,364],{}," sent",[193,906,907],{},"Result",[193,909,910],{},"Why it matters",[200,912,913,929,941,959],{},[190,914,915,920,926],{},[205,916,917],{},[106,918,919],{},"https:\u002F\u002Fattacker.test",[205,921,922,925],{},[106,923,924],{},"101",", document returned",[205,927,928],{},"The plain cross-site case",[190,930,931,934,938],{},[205,932,933],{},"Header deleted entirely",[205,935,936,925],{},[106,937,924],{},[205,939,940],{},"Allowlist code often reads a missing origin as \"not cross site\", which is backwards",[190,942,943,948,952],{},[205,944,945],{},[106,946,947],{},"null",[205,949,950,925],{},[106,951,924],{},[205,953,954,955,958],{},"Real browsers send this from sandboxed iframes, ",[106,956,957],{},"data:"," URLs and local files",[190,960,961,966,970],{},[205,962,963],{},[106,964,965],{},"https:\u002F\u002Fapp.example.lab.attacker.test",[205,967,968,925],{},[106,969,924],{},[205,971,972],{},"A check written with \"starts with\" passes this. The real origin is only a label on the front of an attacker domain",[44,974,975],{},"Test all four on every target. I have had all four pass on a server that looked, from the outside, like it was checking.",[99,977,979],{"code":978,"language":102,"meta":103,"className":104,"style":103},"flowchart TD\n    A[\"Handshake arrives carrying Origin\"] --> B{\"Is a check written?\"}\n    B -->|\"No check at all\"| C[\"101, first frame delivered\"]\n    B -->|\"Compares the whole value\"| D[\"403, no frame\"]\n    B -->|\"Uses starts with or contains\"| E[\"101, subdomain trick passes\"]\n    B -->|\"Treats absent or null as safe\"| F[\"101, delivered anyway\"]\n",[106,980,981,986,991,996,1001,1006],{},[109,982,983],{"class":111,"line":112},[109,984,985],{},"flowchart TD\n",[109,987,988],{"class":111,"line":118},[109,989,990],{},"    A[\"Handshake arrives carrying Origin\"] --> B{\"Is a check written?\"}\n",[109,992,993],{"class":111,"line":124},[109,994,995],{},"    B -->|\"No check at all\"| C[\"101, first frame delivered\"]\n",[109,997,998],{"class":111,"line":130},[109,999,1000],{},"    B -->|\"Compares the whole value\"| D[\"403, no frame\"]\n",[109,1002,1003],{"class":111,"line":540},[109,1004,1005],{},"    B -->|\"Uses starts with or contains\"| E[\"101, subdomain trick passes\"]\n",[109,1007,1008],{"class":111,"line":549},[109,1009,1010],{},"    B -->|\"Treats absent or null as safe\"| F[\"101, delivered anyway\"]\n",[44,1012,1013],{},"Two doors, one document, one cookie, the same authorization code sitting behind both. One of them tells the browser who is allowed to read the answer. The other never asks who is doing the asking.",[44,1015,1016],{},"Nothing failed here. Authorization ran on every request and returned the right answer each time. It simply answered a question nobody should have been able to put to it.",[71,1018,1020],{"id":1019},"why-cors-does-not-cover-websockets","Why CORS Does Not Cover WebSockets",[44,1022,1023,1024,1029,1030,1032],{},"The Same Origin Policy exists to keep one site out of another site's data. ",[138,1025,1028],{"href":1026,"rel":1027,"target":144},"https:\u002F\u002Ffetch.spec.whatwg.org\u002F?utm_source=amrelsagaei.com&utm_medium=referral#http-cors-protocol",[142,143],"CORS"," is the sanctioned way to loosen that, and the specification attaches it to ",[106,1031,693],{}," and XHR.",[44,1034,1035],{},"The JSON request ran straight into that. The browser went looking for permission in the response headers, did not find its own origin named, and threw away data it was already holding.",[44,1037,1038,1039,1042],{},"The WebSocket API sits outside that machinery. No preflight is defined, so no ",[106,1040,1041],{},"OPTIONS"," goes out ahead of the handshake. Nothing is asked and nothing is checked. Your browser will send that upgrade to any host from any page.",[99,1044,1046],{"code":1045,"language":102,"meta":103,"className":104,"style":103},"sequenceDiagram\n    participant P as Hostile page\n    participant B as Browser\n    participant S as Document backend\n    P->>B: fetch the document\n    B->>S: GET with session cookie\n    S-->>B: 200 and the document, no ACAO header\n    B--xP: TypeError, response discarded\n    P->>B: open a WebSocket\n    B->>S: Upgrade request with session cookie\n    S-->>B: 101 Switching Protocols\n    S-->>P: first frame, the whole document\n",[106,1047,1048,1053,1058,1063,1068,1073,1078,1083,1088,1094,1100,1106],{},[109,1049,1050],{"class":111,"line":112},[109,1051,1052],{},"sequenceDiagram\n",[109,1054,1055],{"class":111,"line":118},[109,1056,1057],{},"    participant P as Hostile page\n",[109,1059,1060],{"class":111,"line":124},[109,1061,1062],{},"    participant B as Browser\n",[109,1064,1065],{"class":111,"line":130},[109,1066,1067],{},"    participant S as Document backend\n",[109,1069,1070],{"class":111,"line":540},[109,1071,1072],{},"    P->>B: fetch the document\n",[109,1074,1075],{"class":111,"line":549},[109,1076,1077],{},"    B->>S: GET with session cookie\n",[109,1079,1080],{"class":111,"line":558},[109,1081,1082],{},"    S-->>B: 200 and the document, no ACAO header\n",[109,1084,1085],{"class":111,"line":566},[109,1086,1087],{},"    B--xP: TypeError, response discarded\n",[109,1089,1091],{"class":111,"line":1090},9,[109,1092,1093],{},"    P->>B: open a WebSocket\n",[109,1095,1097],{"class":111,"line":1096},10,[109,1098,1099],{},"    B->>S: Upgrade request with session cookie\n",[109,1101,1103],{"class":111,"line":1102},11,[109,1104,1105],{},"    S-->>B: 101 Switching Protocols\n",[109,1107,1109],{"class":111,"line":1108},12,[109,1110,1111],{},"    S-->>P: first frame, the whole document\n",[44,1113,1114],{},"That is not a browser bug. It is the protocol behaving as specified. Which leaves the server a single way to learn where a handshake originated, and nothing obliges it to look. Where no one wrote the comparison, no comparison runs.",[71,1116,1118],{"id":1117},"why-samesite-is-not-the-fix","Why SameSite Is Not The Fix",[44,1120,1121,1122,1125],{},"Set that cookie to ",[106,1123,1124],{},"SameSite=Lax"," and the browser withholds it from the handshake, since an upgrade request is not a top-level navigation. That is a genuine mitigation, and it is why classic cross-site WebSocket hijacking has become harder to land.",[44,1127,1128],{},"Do not write it down as the fix.",[44,1130,1131,1133,1134,1136],{},[106,1132,241],{}," is evaluated on the registrable domain, not the origin. Every subdomain of the app counts as the same site. One forgotten subdomain serving attacker-controlled content, one subdomain takeover, and ",[106,1135,249],{}," hands the cookie over.",[44,1138,1139,1141,1142,1144],{},[106,1140,241],{}," governs who gets to attempt the connection. Only an ",[106,1143,364],{}," comparison refuses it.",[71,1146,1148],{"id":1147},"finding-other-peoples-document-ids","Finding Other People's Document IDs",[44,1150,1151],{},"Everything so far used a document ID copied out of my own account. The obvious objection is that a random website would never know it.",[44,1153,1154],{},"It does not need to.",[44,1156,1157],{},"The IDs were ten digits and never sequential, so counting upwards gets you nothing. But the allocator was time based, driven by a single counter shared across every account on the system. Create eight documents two seconds apart and the whole run lands inside a band a couple of hundred wide.",[44,1159,1160],{},"That turns an unguessable ID into a bounded search:",[1162,1163,1164,1167,1170,1173],"ol",{},[85,1165,1166],{},"Sign up for a normal account on the service.",[85,1168,1169],{},"Save one document of your own.",[85,1171,1172],{},"Read the ID that comes back. That is where the counter is sitting right now.",[85,1174,1175],{},"Step backwards from there, in a window matching when the target was active.",[44,1177,1178],{},"The hostile page did exactly that with an ordinary account of its own. No ID from me at all.",[44,1180,1181,1182,1185,1186,1191],{},"The server then did the sorting. An ID the session could not read closed with code ",[106,1183,1184],{},"4004"," and the owner's user ID in the message. An ID it could read returned the document. The ",[138,1187,1190],{"href":1188,"rel":1189,"target":144},"https:\u002F\u002Fdatatracker.ietf.org\u002Fdoc\u002Fhtml\u002Frfc6455?utm_source=amrelsagaei.com&utm_medium=referral#section-7.4.2",[142,143],"4000 to 4999 range is reserved by RFC 6455 for private use",", so that code is the application's own decision. Somebody wrote that branch.",[44,1193,1194],{},"A distinguishable error is an oracle. It separated readable documents from unreadable ones, on behalf of a page that should never have been able to ask.",[44,1196,1197],{},"Be honest about scale when you write this up. A busy service burns through that counter, so a document created an hour earlier can sit many thousands of positions behind the present. You target the window the person was active in. Recent records are always the cheapest to reach.",[71,1199,1201],{"id":1200},"reading-documents-from-another-website","Reading Documents From Another Website",[44,1203,1204],{},"A proxy proves the server's behaviour. It does not prove impact, and a report that stops there gets closed, because anybody can send anything from a repeater.",[44,1206,1207],{},"So run both requests again from an ordinary page on an unrelated domain, with nothing installed and nothing intercepting.",[44,1209,1210],{},"Over HTTP the page receives this, and nothing else:",[99,1212,1215],{"code":1213,"language":1214,"meta":103},"TypeError: Failed to fetch\n","text",[106,1216,1213],{},[44,1218,1219,1220,1222],{},"No status, no headers, no body. The request went out and the server returned ",[106,1221,470],{},", but the browser discarded it before any JavaScript could touch it.",[44,1224,1225],{},"Over the socket, the same ID returns the title, the length and the full body, straight into the page.",[44,1227,1228],{},"Identical browser, identical session, identical cookie. One variable moved, and it was the protocol.",[1230,1231],"attack-path",{":edges":1232,":nodes":1233,"title":1234},"[{\"from\":\"page\",\"to\":\"browser\",\"label\":\"loads in\"},{\"from\":\"browser\",\"to\":\"cookie\",\"label\":\"attaches\"},{\"from\":\"cookie\",\"to\":\"cors\",\"label\":\"rides along\"},{\"from\":\"cookie\",\"to\":\"handshake\",\"label\":\"rides along\"},{\"from\":\"cors\",\"to\":\"fetch\",\"label\":\"blocks the read\"},{\"from\":\"handshake\",\"to\":\"backend\",\"label\":\"upgrades\"},{\"from\":\"backend\",\"to\":\"oracle\",\"label\":\"answers\"},{\"from\":\"oracle\",\"to\":\"store\",\"label\":\"reaches\"}]","[{\"id\":\"page\",\"kind\":\"asset\",\"title\":\"Hostile page\",\"subtitle\":\"unrelated domain, nothing installed\"},{\"id\":\"browser\",\"kind\":\"browser\",\"title\":\"Your browser\",\"subtitle\":\"already signed in\"},{\"id\":\"cookie\",\"kind\":\"secret\",\"title\":\"ntl_session\",\"subtitle\":\"Domain=.example.lab, SameSite=None\"},{\"id\":\"cors\",\"kind\":\"defense\",\"title\":\"CORS on the JSON API\",\"subtitle\":\"one origin on the allowlist\"},{\"id\":\"fetch\",\"kind\":\"issue\",\"title\":\"TypeError, Failed to fetch\",\"subtitle\":\"200 returned, response discarded\"},{\"id\":\"handshake\",\"kind\":\"vector\",\"title\":\"WebSocket handshake\",\"subtitle\":\"no Origin check, no preflight defined\",\"badge\":\"High\"},{\"id\":\"backend\",\"kind\":\"server\",\"title\":\"api.example.lab\",\"subtitle\":\"101 Switching Protocols\"},{\"id\":\"oracle\",\"kind\":\"network\",\"title\":\"Close code 4004\",\"subtitle\":\"separates readable IDs from unreadable\"},{\"id\":\"store\",\"kind\":\"database\",\"title\":\"Document library\",\"subtitle\":\"title, length and full body in the first frame\"}]","one missing origin check on a handshake",[71,1236,1238],{"id":1237},"how-to-hunt-this-on-your-own-targets","How To Hunt This On Your Own Targets",[44,1240,1241],{},"Three steps, none of which need anything you do not already have.",[44,1243,1244,1247,1248,1250,1251,1253,1254,1257],{},[88,1245,1246],{},"Find the sockets."," Put the app behind a proxy and hunt for a ",[106,1249,924],{}," in the history. Work every screen deliberately, because a socket usually belongs to exactly one of them. Collaborative editors, support chat, notification trays, dashboards that refresh themselves. Then grep the bundles for ",[106,1252,697],{}," and ",[106,1255,1256],{},"wss:\u002F\u002F"," to catch endpoints you never reached by clicking.",[44,1259,1260,1263],{},[88,1261,1262],{},"Read the first frame before sending anything into it."," If user data arrives unprompted, you already have something worth chasing.",[44,1265,1266,1269],{},[88,1267,1268],{},"Replay the handshake."," Work through every row of the table above, not only the obvious one.",[44,1271,1272],{},"Then the step that decides whether any of this pays.",[71,1274,1276],{"id":1275},"proving-it-before-you-report","Proving It Before You Report",[44,1278,1279],{},"Run the controls in one batch, so every row shares the same session state:",[184,1281,1282,1292],{},[187,1283,1284],{},[190,1285,1286,1289],{},[193,1287,1288],{},"Control",[193,1290,1291],{},"What it rules out",[200,1293,1294,1302,1310,1318],{},[190,1295,1296,1299],{},[205,1297,1298],{},"Connect from the real origin",[205,1300,1301],{},"The session is live and the endpoint works",[190,1303,1304,1307],{},[205,1305,1306],{},"Connect with no cookie",[205,1308,1309],{},"The endpoint is not simply open to everybody",[190,1311,1312,1315],{},[205,1313,1314],{},"Connect to another account's document",[205,1316,1317],{},"Per-document authorization is real and enforced",[190,1319,1320,1323],{},[205,1321,1322],{},"Connect from a foreign origin",[205,1324,1325,1326,1328],{},"The only variable left is the ",[106,1327,364],{}," header",[44,1330,1331],{},"The first three are the ones that matter. They close off every explanation except the one you are claiming. Without them a triager can reasonably argue the endpoint was public all along.",[44,1333,1334],{},"I ran every one of them before writing a line of that report, and not for the report's benefit. I ran them because I did not yet believe my own finding. The side effect was that the triager had nothing left to push back on.",[71,1336,1338],{"id":1337},"the-one-check-that-fixes-it","The One Check That Fixes It",[44,1340,1341,1342,1344],{},"Apply the allowlist you already have at upgrade time, compare the whole origin, and reject a missing or ",[106,1343,947],{}," value explicitly.",[1346,1347,1348,1491],"code-group",{},[99,1349,1353],{"code":1350,"filename":1351,"language":1352,"meta":103,"className":104,"style":103},"server.on(\"upgrade\", (req, socket, head) => {\n  \u002F\u002F Session and per-document authorization run below.\n  \u002F\u002F Nothing looks at req.headers.origin.\n  wss.handleUpgrade(req, socket, head, (ws) => {\n    wss.emit(\"connection\", ws, req);\n  });\n});\n","Vulnerable","js",[106,1354,1355,1403,1409,1414,1449,1481,1486],{},[109,1356,1357,1361,1363,1367,1369,1371,1374,1376,1378,1381,1384,1386,1389,1391,1394,1397,1400],{"class":111,"line":112},[109,1358,1360],{"class":1359},"snInM","server",[109,1362,626],{"class":392},[109,1364,1366],{"class":1365},"swzfi","on",[109,1368,655],{"class":392},[109,1370,397],{"class":438},[109,1372,1373],{"class":171},"upgrade",[109,1375,397],{"class":438},[109,1377,412],{"class":392},[109,1379,1380],{"class":392}," (",[109,1382,1383],{"class":1359},"req",[109,1385,412],{"class":392},[109,1387,1388],{"class":1359}," socket",[109,1390,412],{"class":392},[109,1392,1393],{"class":1359}," head",[109,1395,1396],{"class":392},")",[109,1398,1399],{"class":392}," =>",[109,1401,1402],{"class":392}," {\n",[109,1404,1405],{"class":111,"line":118},[109,1406,1408],{"class":1407},"sy60D","  \u002F\u002F Session and per-document authorization run below.\n",[109,1410,1411],{"class":111,"line":124},[109,1412,1413],{"class":1407},"  \u002F\u002F Nothing looks at req.headers.origin.\n",[109,1415,1416,1419,1421,1424,1426,1428,1430,1432,1434,1436,1438,1440,1443,1445,1447],{"class":111,"line":130},[109,1417,1418],{"class":1359},"  wss",[109,1420,626],{"class":392},[109,1422,1423],{"class":1365},"handleUpgrade",[109,1425,655],{"class":392},[109,1427,1383],{"class":1359},[109,1429,412],{"class":392},[109,1431,1388],{"class":1359},[109,1433,412],{"class":392},[109,1435,1393],{"class":1359},[109,1437,412],{"class":392},[109,1439,1380],{"class":392},[109,1441,1442],{"class":1359},"ws",[109,1444,1396],{"class":392},[109,1446,1399],{"class":392},[109,1448,1402],{"class":392},[109,1450,1451,1454,1456,1459,1461,1463,1466,1468,1470,1473,1475,1478],{"class":111,"line":540},[109,1452,1453],{"class":1359},"    wss",[109,1455,626],{"class":392},[109,1457,1458],{"class":1365},"emit",[109,1460,655],{"class":392},[109,1462,397],{"class":438},[109,1464,1465],{"class":171},"connection",[109,1467,397],{"class":438},[109,1469,412],{"class":392},[109,1471,1472],{"class":1359}," ws",[109,1474,412],{"class":392},[109,1476,1477],{"class":1359}," req",[109,1479,1480],{"class":392},");\n",[109,1482,1483],{"class":111,"line":549},[109,1484,1485],{"class":392},"  });\n",[109,1487,1488],{"class":111,"line":558},[109,1489,1490],{"class":392},"});\n",[99,1492,1495],{"code":1493,"filename":1494,"language":1352,"meta":103,"className":104,"style":103},"const ALLOWED = new Set([\"https:\u002F\u002Fapp.example.lab\"]);\n\nserver.on(\"upgrade\", (req, socket, head) => {\n  const origin = req.headers.origin;\n  if (!origin || !ALLOWED.has(origin)) {\n    socket.write(\"HTTP\u002F1.1 403 Forbidden\\r\\n\\r\\n\");\n    socket.destroy();\n    return;\n  }\n  wss.handleUpgrade(req, socket, head, (ws) => {\n    wss.emit(\"connection\", ws, req);\n  });\n});\n","Patched",[106,1496,1497,1527,1531,1567,1592,1627,1651,1663,1670,1675,1707,1733,1737],{},[109,1498,1499,1502,1505,1508,1511,1514,1517,1519,1522,1524],{"class":111,"line":112},[109,1500,1501],{"class":666},"const",[109,1503,1504],{"class":1359}," ALLOWED",[109,1506,1507],{"class":392}," =",[109,1509,1510],{"class":666}," new",[109,1512,1513],{"class":1365}," Set",[109,1515,1516],{"class":392},"([",[109,1518,397],{"class":438},[109,1520,1521],{"class":171},"https:\u002F\u002Fapp.example.lab",[109,1523,397],{"class":438},[109,1525,1526],{"class":392},"]);\n",[109,1528,1529],{"class":111,"line":118},[109,1530,387],{"emptyLinePlaceholder":30},[109,1532,1533,1535,1537,1539,1541,1543,1545,1547,1549,1551,1553,1555,1557,1559,1561,1563,1565],{"class":111,"line":124},[109,1534,1360],{"class":1359},[109,1536,626],{"class":392},[109,1538,1366],{"class":1365},[109,1540,655],{"class":392},[109,1542,397],{"class":438},[109,1544,1373],{"class":171},[109,1546,397],{"class":438},[109,1548,412],{"class":392},[109,1550,1380],{"class":392},[109,1552,1383],{"class":1359},[109,1554,412],{"class":392},[109,1556,1388],{"class":1359},[109,1558,412],{"class":392},[109,1560,1393],{"class":1359},[109,1562,1396],{"class":392},[109,1564,1399],{"class":392},[109,1566,1402],{"class":392},[109,1568,1569,1572,1575,1577,1579,1581,1584,1586,1589],{"class":111,"line":130},[109,1570,1571],{"class":666},"  const",[109,1573,1574],{"class":1359}," origin",[109,1576,1507],{"class":392},[109,1578,1477],{"class":1359},[109,1580,626],{"class":392},[109,1582,1583],{"class":1359},"headers",[109,1585,626],{"class":392},[109,1587,1588],{"class":1359},"origin",[109,1590,1591],{"class":392},";\n",[109,1593,1594,1597,1599,1602,1604,1607,1610,1613,1615,1618,1620,1622,1625],{"class":111,"line":540},[109,1595,1596],{"class":167},"  if",[109,1598,1380],{"class":392},[109,1600,1601],{"class":666},"!",[109,1603,1588],{"class":1359},[109,1605,1606],{"class":666}," ||",[109,1608,1609],{"class":666}," !",[109,1611,1612],{"class":1359},"ALLOWED",[109,1614,626],{"class":392},[109,1616,1617],{"class":1365},"has",[109,1619,655],{"class":392},[109,1621,1588],{"class":1359},[109,1623,1624],{"class":392},"))",[109,1626,1402],{"class":392},[109,1628,1629,1632,1634,1637,1639,1641,1644,1647,1649],{"class":111,"line":549},[109,1630,1631],{"class":1359},"    socket",[109,1633,626],{"class":392},[109,1635,1636],{"class":1365},"write",[109,1638,655],{"class":392},[109,1640,397],{"class":438},[109,1642,1643],{"class":171},"HTTP\u002F1.1 403 Forbidden",[109,1645,1646],{"class":760},"\\r\\n\\r\\n",[109,1648,397],{"class":438},[109,1650,1480],{"class":392},[109,1652,1653,1655,1657,1660],{"class":111,"line":558},[109,1654,1631],{"class":1359},[109,1656,626],{"class":392},[109,1658,1659],{"class":1365},"destroy",[109,1661,1662],{"class":392},"();\n",[109,1664,1665,1668],{"class":111,"line":566},[109,1666,1667],{"class":167},"    return",[109,1669,1591],{"class":392},[109,1671,1672],{"class":111,"line":1090},[109,1673,1674],{"class":392},"  }\n",[109,1676,1677,1679,1681,1683,1685,1687,1689,1691,1693,1695,1697,1699,1701,1703,1705],{"class":111,"line":1096},[109,1678,1418],{"class":1359},[109,1680,626],{"class":392},[109,1682,1423],{"class":1365},[109,1684,655],{"class":392},[109,1686,1383],{"class":1359},[109,1688,412],{"class":392},[109,1690,1388],{"class":1359},[109,1692,412],{"class":392},[109,1694,1393],{"class":1359},[109,1696,412],{"class":392},[109,1698,1380],{"class":392},[109,1700,1442],{"class":1359},[109,1702,1396],{"class":392},[109,1704,1399],{"class":392},[109,1706,1402],{"class":392},[109,1708,1709,1711,1713,1715,1717,1719,1721,1723,1725,1727,1729,1731],{"class":111,"line":1102},[109,1710,1453],{"class":1359},[109,1712,626],{"class":392},[109,1714,1458],{"class":1365},[109,1716,655],{"class":392},[109,1718,397],{"class":438},[109,1720,1465],{"class":171},[109,1722,397],{"class":438},[109,1724,412],{"class":392},[109,1726,1472],{"class":1359},[109,1728,412],{"class":392},[109,1730,1477],{"class":1359},[109,1732,1480],{"class":392},[109,1734,1735],{"class":111,"line":1108},[109,1736,1485],{"class":392},[109,1738,1740],{"class":111,"line":1739},13,[109,1741,1490],{"class":392},[44,1743,1744,1747,1748,1751,1752,1755,1756,1758],{},[106,1745,1746],{},"ALLOWED.has(origin)"," is an exact match, which is what kills the ",[106,1749,1750],{},"starts with"," bypass. The explicit ",[106,1753,1754],{},"!origin"," test is what kills the absent and ",[106,1757,947],{}," cases.",[44,1760,1761,1762,1764],{},"With that in place the forged handshake returns ",[106,1763,886],{}," with no frame, every legitimate row still passes, and the application behaves exactly as it did before. The check costs the product nothing.",[71,1766,1768],{"id":1767},"why-this-keeps-happening","Why This Keeps Happening",[44,1770,1771,1772,1253,1774,626],{},"Nobody was careless on this target. The allowlist on the JSON API was correct and strict. Per-document authorization was real and enforced in both directions. The session cookie was ",[106,1773,219],{},[106,1775,1776],{},"HttpOnly",[44,1778,1779],{},"All of it was applied to one protocol.",[44,1781,1782],{},"That is most of what you are going to find out there. Not applications with no security on them. Applications with good security that only ever got wired into one of the ways in. Somebody locked the door they could see, and the second one was never on the list.",[44,1784,1785,1786,1788],{},"Pick an app you have already tested. Find the ",[106,1787,924],{},". Read what arrives in that first frame before you put anything into it.",[71,1790,1792],{"id":1791},"further-reading","Further Reading",[82,1794,1795,1801,1807,1813,1820,1827,1833,1840],{},[85,1796,1797],{},[138,1798,1800],{"href":604,"rel":1799,"target":144},[142,143],"RFC 6455: The WebSocket Protocol",[85,1802,1803],{},[138,1804,1806],{"href":140,"rel":1805,"target":144},[142,143],"RFC 6454: The Web Origin Concept",[85,1808,1809],{},[138,1810,1812],{"href":1026,"rel":1811,"target":144},[142,143],"Fetch Standard: the CORS protocol",[85,1814,1815],{},[138,1816,1819],{"href":1817,"rel":1818,"target":144},"https:\u002F\u002Fportswigger.net\u002Fweb-security\u002Fwebsockets\u002Fcross-site-websocket-hijacking?utm_source=amrelsagaei.com&utm_medium=referral",[142,143],"PortSwigger: Cross-site WebSocket hijacking",[85,1821,1822],{},[138,1823,1826],{"href":1824,"rel":1825,"target":144},"https:\u002F\u002Fowasp.org\u002Fwww-project-web-security-testing-guide\u002Flatest\u002F4-Web_Application_Security_Testing\u002F11-Client-side_Testing\u002F10-Testing_WebSockets?utm_source=amrelsagaei.com&utm_medium=referral",[142,143],"OWASP WSTG: Testing WebSockets",[85,1828,1829],{},[138,1830,1832],{"href":237,"rel":1831,"target":144},[142,143],"MDN: Set-Cookie and the SameSite attribute",[85,1834,1835],{},[138,1836,1839],{"href":1837,"rel":1838,"target":144},"https:\u002F\u002Fdeveloper.mozilla.org\u002Fen-US\u002Fdocs\u002FWeb\u002FHTTP\u002FGuides\u002FCORS?utm_source=amrelsagaei.com&utm_medium=referral",[142,143],"MDN: Cross-Origin Resource Sharing",[85,1841,1842],{},[138,1843,1846],{"href":1844,"rel":1845,"target":144},"https:\u002F\u002Fdocs.caido.io\u002F?utm_source=amrelsagaei.com&utm_medium=referral",[142,143],"Caido documentation",[1848,1849,1850],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html pre.shiki code .sR8n-, html code.shiki .sR8n-{--shiki-default:#4D9375;--shiki-light:#1E754F}html pre.shiki code .sRRDT, html code.shiki .sRRDT{--shiki-default:#C98A7D;--shiki-light:#B56959}html pre.shiki code .sG2Fq, html code.shiki .sG2Fq{--shiki-default:#DBD7CAEE;--shiki-light:#393A34}html pre.shiki code .sUQhE, html code.shiki .sUQhE{--shiki-default:#4C9A91;--shiki-light:#2F798A}html pre.shiki code .somML, html code.shiki .somML{--shiki-default:#666666;--shiki-light:#999999}html pre.shiki code .sIkdJ, html code.shiki .sIkdJ{--shiki-default:#B8A96577;--shiki-light:#99841877}html pre.shiki code .s6_DI, html code.shiki .s6_DI{--shiki-default:#B8A965;--shiki-light:#998418}html pre.shiki code .sy_C3, html code.shiki .sy_C3{--shiki-default:#C98A7D77;--shiki-light:#B5695977}html pre.shiki code .sfIIG, html code.shiki .sfIIG{--shiki-default:#CB7676;--shiki-light:#AB5959}html pre.shiki code .se4ZP, html code.shiki .se4ZP{--shiki-default:#C99076;--shiki-light:#A65E2B}html pre.shiki code .snInM, html code.shiki .snInM{--shiki-default:#BD976A;--shiki-light:#B07D48}html pre.shiki code .swzfi, html code.shiki .swzfi{--shiki-default:#80A665;--shiki-light:#59873A}html pre.shiki code .sy60D, html code.shiki .sy60D{--shiki-default:#758575DD;--shiki-light:#A0ADA0}",{"title":103,"searchDepth":124,"depth":124,"links":1852},[1853,1854,1855,1856,1857,1858,1859,1860,1861,1862,1863,1864,1865,1866,1867,1868],{"id":73,"depth":118,"text":74},{"id":152,"depth":118,"text":153},{"id":262,"depth":118,"text":263},{"id":300,"depth":118,"text":301},{"id":490,"depth":118,"text":491},{"id":701,"depth":118,"text":702},{"id":854,"depth":118,"text":855},{"id":1019,"depth":118,"text":1020},{"id":1117,"depth":118,"text":1118},{"id":1147,"depth":118,"text":1148},{"id":1200,"depth":118,"text":1201},{"id":1237,"depth":118,"text":1238},{"id":1275,"depth":118,"text":1276},{"id":1337,"depth":118,"text":1338},{"id":1767,"depth":118,"text":1768},{"id":1791,"depth":118,"text":1792},[1870,1871],"Bug Bounty","Penetration Testing",{"width":1873,"height":1874,"variants":1875,"lqip":1878,"social":1879},1920,1080,{"400":1876,"800":1877},"\u002Fimages\u002Fblog\u002Fresolved-perfect-cors-zero-protection\u002Fresolved-perfect-cors-zero-protection-400.webp","\u002Fimages\u002Fblog\u002Fresolved-perfect-cors-zero-protection\u002Fresolved-perfect-cors-zero-protection-800.webp","data:image\u002Fwebp;base64,UklGRmAAAABXRUJQVlA4IFQAAACwAwCdASoUAAsAPu1iqk2ppaQiMAgBMB2JQAAKUi\u002FulGjf36WqMAD+6ff9ONjJcDJLQwXx2yUQ8TWjj79c\u002Fbi\u002F4a0QzTt0vhEQPcscmEgkmLogAAA=",{"src":1880,"width":1881,"height":1882},"\u002Fimages\u002Fblog\u002Fresolved-perfect-cors-zero-protection\u002Fresolved-perfect-cors-zero-protection-og.jpg",1200,675,"\u002Fimages\u002Fblog\u002Fresolved-perfect-cors-zero-protection\u002Fresolved-perfect-cors-zero-protection.webp","A correctly configured CORS allowlist protected the JSON API and nothing at all protected the WebSocket. How one missing Origin check on a handshake leaked a whole document library.","md",{},null,{"title":35,"description":1884},"resolved-perfect-cors-zero-protection","RaUnP_rAKp8-VTd2kf45bcdq8qdtXozYGQZQ139pm9g",{"older":1892,"newer":1887,"total":1896},{"slug":1893,"title":1894,"date":1895,"position":118},"race-conditions-are-not-beginner-bugs","Race Conditions Are Not Beginner Bugs","2026-11-10T10:00:00-03:00",71,[],{"id":42,"title":35,"published":1899,"url":1900,"description":1901,"durationSeconds":1902,"thumbnail":1903,"thumbnailSrcset":1904},"2026-11-25T13:00:17+00:00","https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=TnALrApXdkw","Every permission check on this app ran, and every one of them came back with the right answer. The CORS allowlist had exactly one origin on it and it was enforced properly. A website with no connection to that app could still read a user's private documents, and all the victim had to do was open a page.",1660,"\u002Fimages\u002Fvideos\u002FTnALrApXdkw-400.webp","\u002Fimages\u002Fvideos\u002FTnALrApXdkw-400.webp 400w, \u002Fimages\u002Fvideos\u002FTnALrApXdkw-800.webp 800w, \u002Fimages\u002Fvideos\u002FTnALrApXdkw-1280.webp 1280w",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1906},"\u003Cpath fill=\"currentColor\" d=\"M12 0C5.373 0 0 5.373 0 12c0 3.314 1.343 6.314 3.515 8.485l-2.286 2.286A.72.72 0 0 0 1.738 24H12c6.627 0 12-5.373 12-12S18.627 0 12 0m4.388 3.199a1.999 1.999 0 1 1-1.947 2.46v.002a2.37 2.37 0 0 0-2.032 2.341v.007c1.776.067 3.4.567 4.686 1.363a2.802 2.802 0 1 1 2.908 4.753c-.088 3.256-3.637 5.876-7.997 5.876c-4.361 0-7.905-2.617-7.998-5.87a2.8 2.8 0 0 1 1.189-5.34c.645 0 1.239.218 1.712.585c1.275-.79 2.881-1.291 4.64-1.365v-.01a3.23 3.23 0 0 1 2.88-3.207a2 2 0 0 1 1.959-1.595m-8.085 8.376c-.784 0-1.459.78-1.506 1.797s.64 1.429 1.426 1.429s1.371-.369 1.418-1.385s-.553-1.841-1.338-1.841m7.406 0c-.786 0-1.385.824-1.338 1.841s.634 1.385 1.418 1.385c.785 0 1.473-.413 1.426-1.429c-.046-1.017-.721-1.797-1.506-1.797m-3.703 4.013c-.974 0-1.907.048-2.77.135a.222.222 0 0 0-.183.305a3.2 3.2 0 0 0 2.953 1.964a3.2 3.2 0 0 0 2.953-1.964a.222.222 0 0 0-.184-.305a28 28 0 0 0-2.769-.135\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1908},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m9 15l6-6m-4-3l.463-.536a5 5 0 0 1 7.071 7.072L18 13m-5 5l-.397.534a5.07 5.07 0 0 1-7.127 0a4.97 4.97 0 0 1 0-7.071L6 11\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1910},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M7 9.667A2.667 2.667 0 0 1 9.667 7h8.666A2.667 2.667 0 0 1 21 9.667v8.666A2.667 2.667 0 0 1 18.333 21H9.667A2.667 2.667 0 0 1 7 18.333z\"\u002F>\u003Cpath d=\"M4.012 16.737A2 2 0 0 1 3 15V5c0-1.1.9-2 2-2h10c.75 0 1.158.385 1.5 1\"\u002F>\u003C\u002Fg>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1912},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M11 12a1 1 0 1 0 2 0a1 1 0 1 0-2 0M4 8V6a2 2 0 0 1 2-2h2M4 16v2a2 2 0 0 0 2 2h2m8-16h2a2 2 0 0 1 2 2v2m-4 12h2a2 2 0 0 0 2-2v-2\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1914},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M16 4h4v4m-6 2l6-6M8 20H4v-4m0 4l6-6m6 6h4v-4m-6-2l6 6M8 4H4v4m0-4l6 6\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1916},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M3 5a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1zm4 15h10m-8-4v4m6-4v4\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1918},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M4 8h16M4 6a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2zm4-2v4\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1920},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m16.555 3.843l3.602 3.602a2.877 2.877 0 0 1 0 4.069l-2.643 2.643a2.877 2.877 0 0 1-4.069 0l-.301-.301l-6.558 6.558a2 2 0 0 1-1.239.578L5.172 21H4a1 1 0 0 1-.993-.883L3 20v-1.172a2 2 0 0 1 .467-1.284l.119-.13L4 17h2v-2h2v-2l2.144-2.144l-.301-.301a2.877 2.877 0 0 1 0-4.069l2.643-2.643a2.877 2.877 0 0 1 4.069 0M15 9h.01\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1922},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M17.67 17.667A12 12 0 0 1 12 21A12 12 0 0 1 3.5 6c.794.036 1.583-.006 2.357-.124m3.128-.926A12 12 0 0 0 12 3a12 12 0 0 0 8.5 3a12 12 0 0 1-1.116 9.376M3 3l18 18\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1924},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m12.802 2.165l5.575 2.389c.48.206.863.589 1.07 1.07l2.388 5.574c.22.512.22 1.092 0 1.604l-2.389 5.575c-.206.48-.589.863-1.07 1.07l-5.574 2.388c-.512.22-1.092.22-1.604 0l-5.575-2.389a2.04 2.04 0 0 1-1.07-1.07l-2.388-5.574a2.04 2.04 0 0 1 0-1.604l2.389-5.575c.206-.48.589-.863 1.07-1.07l5.574-2.388a2.04 2.04 0 0 1 1.604 0M12 8v4m0 4h.01\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1926},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M3 12a9 9 0 1 0 18 0a9 9 0 0 0-18 0m9-4v4m0 4h.01\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1928},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"M3 7a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v2a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3zm0 8a3 3 0 0 1 3-3h12a3 3 0 0 1 3 3v2a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3zm4-7v.01M7 16v.01\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1930},"\u003Cpath fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\" d=\"m5.931 6.936l1.275 4.249m5.607 5.609l4.251 1.275m-5.381-5.752l5.759-5.759M4 5.5a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0m13 0a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0m0 13a1.5 1.5 0 1 0 3 0a1.5 1.5 0 1 0-3 0m-13-3a4.5 4.5 0 1 0 9 0a4.5 4.5 0 1 0-9 0\"\u002F>",{"left":12,"top":12,"width":13,"height":13,"rotate":12,"vFlip":14,"hFlip":14,"body":1932},"\u003Cg fill=\"none\" stroke=\"currentColor\" stroke-linecap=\"round\" stroke-linejoin=\"round\" stroke-width=\"2\">\u003Cpath d=\"M4 6a8 3 0 1 0 16 0A8 3 0 1 0 4 6\"\u002F>\u003Cpath d=\"M4 6v6a8 3 0 0 0 16 0V6\"\u002F>\u003Cpath d=\"M4 12v6a8 3 0 0 0 16 0v-6\"\u002F>\u003C\u002Fg>",1795612063328]