<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>network on 오늘도 개발을 한다.</title>
    <link>https://cloudsoswift.github.io/post/develop/network/</link>
    <description>오늘도 개발을 한다. (network)</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>ko-kr</language>
    
    <atom:link href="https://cloudsoswift.github.io/post/develop/network/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>[Network] 웹소켓 알아보기 (w. WebSocket API)</title>
      <link>https://cloudsoswift.github.io/post/develop/network/websocket-common/</link>
      <pubDate>Wed, 11 Dec 2024 07:54:11 +0900</pubDate>
      
      <guid>https://cloudsoswift.github.io/post/develop/network/websocket-common/</guid>
      <description>&lt;h1 id=&#34;서론&#34; &gt;서론
&lt;span&gt;
    &lt;a href=&#34;#%ec%84%9c%eb%a1%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;p&gt;&lt;a href=&#34;https://github.com/orm712/CS-712&#34;&gt;CS 스터디&lt;/a&gt;에서 11월 21일 발표한 &lt;a href=&#34;https://github.com/orm712/CS-712/blob/main/08-JAVASCRIPT/15_WebSocket/Readme.md&#34;&gt;WebSocket과 WebSocket API&lt;/a&gt;에 대해 정리한 문서를 블로그에 공유하고자 한다.&lt;/p&gt;
&lt;h1 id=&#34;웹소켓websocket이란&#34; &gt;웹소켓(WebSocket)이란?
&lt;span&gt;
    &lt;a href=&#34;#%ec%9b%b9%ec%86%8c%ec%bc%93websocket%ec%9d%b4%eb%9e%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc6455&#34;&gt;웹소켓(RFC 6455)&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;2011년 등장한 프로토콜&lt;/li&gt;
&lt;li&gt;통제된 환경에서 &lt;code&gt;신뢰할 수 없는 코드(untrusted code, 브라우저가 신뢰하지 않는 서드-파티나, 웹사이트로부터 읽어들인 코드)&lt;/code&gt;를 실행하는 &lt;code&gt;클라이언트&lt;/code&gt;와, 해당 코드의 통신을 허용한 &lt;code&gt;원격 호스트&lt;/code&gt;간의 &lt;strong&gt;&lt;code&gt;양방향 통신&lt;/code&gt;&lt;/strong&gt; 을 가능케하는 프로토콜
&lt;ul&gt;
&lt;li&gt;이를통해 궁극적으로 서버와 양방향 통신이 필요한 브라우저 기반 애플리케이션이 &lt;code&gt;XMLHttpRequest&lt;/code&gt;, &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;과 같은 여러 HTTP 연결에 의존하지 않는 방법을 제공하는 것이 목표&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;웹 브라우저에서 일반적으로 사용되는 &lt;code&gt;출처(Origin) 기반 보안 모델&lt;/code&gt;을 사용&lt;/li&gt;
&lt;li&gt;TCP 위에 계층화 되어 있으며, 오프닝 핸드셰이크와 메시지 프레이밍으로 구성됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;등장-배경&#34; &gt;등장 배경
&lt;span&gt;
    &lt;a href=&#34;#%eb%93%b1%ec%9e%a5-%eb%b0%b0%ea%b2%bd&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;기존의 경우, 클라이언트 - 서버 양방향 통신이 필요한 경우 &lt;code&gt;업스트림 알림(클라이언트에서 서버로 전송하는 알림)&lt;/code&gt;을 전송하는 동시에, 서버에 &lt;code&gt;새로운 값을 폴링&lt;/code&gt;하는 요청을 보내야 했기 때문에, &lt;strong&gt;&lt;code&gt;HTTP 통신이 남발&lt;/code&gt;&lt;/strong&gt; 되었음&lt;/li&gt;
&lt;li&gt;이는 다음과 같은 문제를 야기함
&lt;ol&gt;
&lt;li&gt;서버는 &lt;strong&gt;각 클라이언트에 대해&lt;/strong&gt; &lt;code&gt;정보를 보내기 위한 연결&lt;/code&gt;, &lt;code&gt;정보를 받기 위한 연결&lt;/code&gt;을 포함하는 &lt;code&gt;여러 TCP 연결&lt;/code&gt;을 설정해야 함&lt;/li&gt;
&lt;li&gt;각 &lt;code&gt;클라이언트-서버 메시지&lt;/code&gt;들은 &lt;code&gt;HTTP 헤더&lt;/code&gt;를 가지므로 &lt;strong&gt;&lt;code&gt;오버헤드가 발생&lt;/code&gt;&lt;/strong&gt; 함&lt;/li&gt;
&lt;li&gt;&lt;code&gt;클라이언트 측 스크립트&lt;/code&gt;는 &lt;code&gt;요청&lt;/code&gt;과 &lt;code&gt;응답의 흐름을 추적&lt;/code&gt;하기 위해, &lt;code&gt;발신 연결(outgoing connections)&lt;/code&gt;에서 &lt;code&gt;수신 연결(incoming connections)&lt;/code&gt;로의 &lt;strong&gt;&lt;code&gt;매핑을 유지&lt;/code&gt;&lt;/strong&gt; 해야 함&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;웹소켓은 양방향 트래픽을 위한 &lt;code&gt;단일 TCP 연결&lt;/code&gt;을 사용해 이를 해결하고자 함
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://websockets.spec.whatwg.org/&#34;&gt;웹소켓 API(WSAPI)&lt;/a&gt;와 결합해 &lt;code&gt;HTTP 폴링&lt;/code&gt;의 대안을 제공&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;기존에 존재하는 &lt;code&gt;HTTP 환경&lt;/code&gt;의 &lt;code&gt;맥락&lt;/code&gt;은 살리되, 처음부터 양방향 통신을 위해 고안되지 않은 &lt;code&gt;HTTP를 대체&lt;/code&gt;할 수 있도록 설계됨
&lt;ul&gt;
&lt;li&gt;따라서 HTTP 포트인 &lt;code&gt;80&lt;/code&gt; 및 &lt;code&gt;443&lt;/code&gt;에서 &lt;code&gt;동작&lt;/code&gt;하며 &lt;code&gt;HTTP 프록시&lt;/code&gt;와 &lt;code&gt;중개자(intermediaries)&lt;/code&gt;를 지원하도록 설계됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;구성&#34; &gt;구성
&lt;span&gt;
    &lt;a href=&#34;#%ea%b5%ac%ec%84%b1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;웹소켓&lt;/code&gt;은 연결 수립을 위한 &lt;code&gt;핸드셰이크&lt;/code&gt;와, 이후 이뤄지는 &lt;code&gt;데이터 전송&lt;/code&gt; 두 가지로 이루어짐&lt;/li&gt;
&lt;li&gt;주고받는 &lt;code&gt;메시지&lt;/code&gt;는 하나 이상의 &lt;code&gt;프레임&lt;/code&gt;으로 이루어짐
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;프레임&lt;/code&gt;에 포함될 수 있는 데이터는 여러 유형이 존재하며, &lt;code&gt;한 메시지&lt;/code&gt;에 속하는 &lt;code&gt;각 프레임&lt;/code&gt;은 &lt;code&gt;동일한 유형의 데이터&lt;/code&gt;를 지님&lt;/li&gt;
&lt;li&gt;&lt;code&gt;데이터 유형&lt;/code&gt;으로는 &lt;code&gt;텍스트 데이터(UTF-8)&lt;/code&gt;, &lt;code&gt;이진 데이터&lt;/code&gt;
, &lt;code&gt;제어 프레임(연결 닫기와 같은 신호를 전달하기 위해 프로토콜 수준에서 사용 됨)&lt;/code&gt; 등이 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;핸드셰이크&#34; &gt;핸드셰이크
&lt;span&gt;
    &lt;a href=&#34;#%ed%95%b8%eb%93%9c%ec%85%b0%ec%9d%b4%ed%81%ac&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;오프닝-핸드셰이크&#34; &gt;오프닝 핸드셰이크
&lt;span&gt;
    &lt;a href=&#34;#%ec%98%a4%ed%94%84%eb%8b%9d-%ed%95%b8%eb%93%9c%ec%85%b0%ec%9d%b4%ed%81%ac&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;연결을 수립하기 위한 &lt;code&gt;오프닝 핸드셰이크&lt;/code&gt;는 &lt;code&gt;HTTP 기반 서버 SW, 중개자&lt;/code&gt;와 호환되도록 설계됨
&lt;ul&gt;
&lt;li&gt;즉, &lt;code&gt;HTTP 클라이언트가 사용하는 포트&lt;/code&gt;와 &lt;code&gt;동일한 포트&lt;/code&gt; 사용&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;먼저 클라이언트 측에서 연결 수립을 위해 요청을 전송함&lt;/li&gt;
&lt;li&gt;이때, HTTP 버전이 &lt;code&gt;1.1&lt;/code&gt;인지, &lt;code&gt;2&lt;/code&gt;인지에 따라 방식이 다름
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HTTP/1.1&lt;/code&gt;&lt;img src=&#34;HTTP-1.1-Websocket.png&#34; alt=&#34;HTTP-1.1-Websocket.png&#34;&gt;
&lt;ul&gt;
&lt;li&gt;먼저 클라이언트 측에서 &lt;code&gt;GET&lt;/code&gt; 메서드로 &lt;code&gt;HTTP Upgrade 요청&lt;/code&gt;을 전송
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&amp;lt;!-- 예시 요청 --&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;GET /chat HTTP/1.1
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Host: server.example.com
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Upgrade: websocket
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Connection: Upgrade
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Origin: http://example.com
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Sec-WebSocket-Protocol: chat, superchat
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Sec-WebSocket-Version: 13
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;웹소켓이 나온 &lt;strong&gt;2011년도&lt;/strong&gt;에는 아직 &lt;code&gt;HTTP/2(2015)&lt;/code&gt;가 등장하지 않았기 때문에, &lt;code&gt;HTTP/1.1&lt;/code&gt;에 사용되는 &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade&#34;&gt;&lt;code&gt;Upgrade&lt;/code&gt;헤더&lt;/a&gt;를 사용&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Upgrade&lt;/code&gt; 헤더는 &lt;code&gt;HTTP/1.1&lt;/code&gt;에서 이미 설정된 &lt;code&gt;클라이언트/서버 연결&lt;/code&gt;을 다른 프로토콜로 업그레이드 하기 위해 사용되며, 다음과 같은 형태로 작성됨
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Connection: upgrade
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Upgrade: protocol_name[/protocol_version]
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;연결이 더 지속될 지 알아야 하므로 &lt;code&gt;Connection&lt;/code&gt; 헤더도 함께 사용됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;서버는 핸드셰이크를 수신했음을 증명하기 위해, 두 가지 값을 가져와 합친 뒤 응답을 만들어 냄
&lt;ul&gt;
&lt;li&gt;먼저 클라이언트 핸드셰이크 요청의 &lt;code&gt;Sec-WebSocket-Key&lt;/code&gt; 헤더 값을 가져옴&lt;/li&gt;
&lt;li&gt;이후 문자열 형식의 &lt;code&gt;GUID(전역 고유 식별자)&lt;/code&gt;인 &lt;code&gt;258EAFA5-E914-47DA-95CA-C5AB0DC85B11&lt;/code&gt; 와 연결함
&lt;ul&gt;
&lt;li&gt;해당 값은 웹소켓을 이해하지 못하는 서버에서도 사용될 가능성이 아주 낮은, 웬만해서는 고유한 값임&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;이후 연결한 문자열 값을 SHA-1 해시한 값을 서버 측 핸드셰이크로 전달함&lt;/li&gt;
&lt;li&gt;예시
&lt;ul&gt;
&lt;li&gt;위에서 사용된 &lt;code&gt;Sec-WebSocket-Key&lt;/code&gt; 헤더 값인 &lt;code&gt;dGhlIHNhbXBsZSBub25jZQ==&lt;/code&gt;에 &lt;code&gt;258EAFA5-E914-47DA-95CA-C5AB0DC85B11&lt;/code&gt;을 연결해 &lt;code&gt;dGhlIHNhbXBsZSBub25jZQ==258EAFA5-E914-47DA-95CA- C5AB0DC85B11&lt;/code&gt; 라는 문자열을 생성&lt;/li&gt;
&lt;li&gt;이후 이를 SHA-1 해싱해 &lt;code&gt;0xb3 0x7a 0x4f 0x2c 0xc0 0x62 0x4f 0x16 0x90 0xf6 0x46 0x06 0xcf 0x38 0x59 0x45 0xb2 0xbe 0xc4 0xea&lt;/code&gt; 라는 값을 생성함&lt;/li&gt;
&lt;li&gt;이 값을 base64 인코딩하여 &lt;code&gt;s3pPLMBiTxaQ9kYGzzhZRbK+xOo=&lt;/code&gt; 라는 값으로 변환한 뒤, &lt;code&gt;Sec-WebSocket-Accept&lt;/code&gt; 필드로 전달&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;그리고 서버에서 핸드셰이크가 완료된 경우에는 &lt;code&gt;101&lt;/code&gt;을, 완료되지 않은 경우 이외의 값을 상태코드로 갖는 다음과 같은 형태의 응답을 반환함
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-html&#34; data-lang=&#34;html&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;HTTP/1.1 101 Switching Protocols
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Upgrade: websocket
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Connection: Upgrade
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HTTP/2&lt;/code&gt;&lt;img src=&#34;HTTP-2-Websocket.png&#34; alt=&#34;HTTP-2-Websocket.png&#34;&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HTTP/2&lt;/code&gt;의 멀티플렉싱 특성에 의해, &lt;code&gt;Upgrade&lt;/code&gt;, &lt;code&gt;Connection&lt;/code&gt;과 같은 헤더나 &lt;code&gt;101 응답코드&lt;/code&gt;와 같이 연결-전반적으로 사용되는 헤더 및 상태 코드를 허용하지 않음&lt;/li&gt;
&lt;li&gt;따라서 &lt;code&gt;HTTP/2&lt;/code&gt; 환경에서 &lt;code&gt;웹소켓&lt;/code&gt;을 사용하기 위한 &lt;code&gt;부트스트랩&lt;/code&gt;이 만들어짐
&lt;ul&gt;
&lt;li&gt;이는 &lt;code&gt;HTTP 메서드&lt;/code&gt; 중 하나인 &lt;code&gt;CONNECT&lt;/code&gt;를 &lt;code&gt;확장&lt;/code&gt;해, 단일 &lt;code&gt;HTTP/2 스트림&lt;/code&gt;에 &lt;code&gt;웹소켓용 데이터&lt;/code&gt;를 전달할 수 있는 &lt;code&gt;터널&lt;/code&gt;을 만듦&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;확장된 CONNECT 메서드&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CONNECT&lt;/code&gt;를 통해 생성한 터널에서 어떤 프로토콜을 사용할 지 나타내는 새로운 &lt;code&gt;의사-헤더 필드&lt;/code&gt;인 &lt;code&gt;:protocol&lt;/code&gt;을 사용
&lt;ul&gt;
&lt;li&gt;해당 필드에 포함될 수 있는 값은 &lt;a href=&#34;https://www.iana.org/assignments/http-upgrade-tokens/http-upgrade-tokens.xhtml&#34;&gt;Hypertext Transfer Protocol (HTTP) Upgrade Token Registry&lt;/a&gt;에 포함된 값&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:protocol&lt;/code&gt;을 포함한 요청에는 대항 URI의 &lt;code&gt;:scheme&lt;/code&gt;, &lt;code&gt;:path&lt;/code&gt; &lt;code&gt;의사-헤더 필드&lt;/code&gt;도 반드시 포함되어야 함&lt;/li&gt;
&lt;li&gt;&lt;code&gt;:protocol&lt;/code&gt;을 포함한 요청에서는 &lt;code&gt;:authority&lt;/code&gt; 필드가 기존과 다르게 해석 됨
&lt;ul&gt;
&lt;li&gt;연결한 호스트와 포트(&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7540#section-8.3&#34;&gt;RFC 7540 #8.3&lt;/a&gt;)가 아닌, 대상 URI의 권한(&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.3&#34;&gt;RFC 7540 #8.1.2.3&lt;/a&gt;)으로 해석됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HTTP/1.1&lt;/code&gt;의 GET 기반 요청처럼, 클라이언트 측에서 &lt;code&gt;CONNECT&lt;/code&gt; 메서드 요청을 통해 연결 수립을 요청
&lt;ul&gt;
&lt;li&gt;해당 요청은 &lt;code&gt;:protocol&lt;/code&gt; 필드를 반드시 포함해야 하며, &lt;code&gt;websocket&lt;/code&gt; 값을 가져야 함&lt;/li&gt;
&lt;li&gt;목표 URI의 스키마의 맨 앞은 &lt;code&gt;wss(htttp)&lt;/code&gt; 또는 &lt;code&gt;ws(http)&lt;/code&gt;여야 하며, 나머지는 웹소켓 URI와 동일&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HTTP/1.1&lt;/code&gt;과 달리 &lt;code&gt;Upgrade&lt;/code&gt;, &lt;code&gt;Connection&lt;/code&gt;, &lt;code&gt;Host&lt;/code&gt; 헤더를 사용하지 않으며, &lt;code&gt;Host&lt;/code&gt; 정보는 &lt;code&gt;:authority&lt;/code&gt;의 일부로 전달됨
&lt;ul&gt;
&lt;li&gt;또한, &lt;code&gt;Sec-WebSocket-Key&lt;/code&gt; 및 &lt;code&gt;Sec-WebSocket- Accept&lt;/code&gt; 헤더에 대한 처리가 &lt;code&gt;:protocol&lt;/code&gt; 필드로 대체되어 이뤄지지 않음&lt;/li&gt;
&lt;li&gt;반면 &lt;code&gt;Origin&lt;/code&gt;,  &lt;code&gt;Sec-WebSocket-Version&lt;/code&gt;, &lt;code&gt;Sec-WebSocket-Protocol&lt;/code&gt;, &lt;code&gt;Sec-WebSocket-Extensions&lt;/code&gt; 필드는 사용되나 &lt;code&gt;HTTP/1.1&lt;/code&gt;과 달리 &lt;code&gt;HTTP/2&lt;/code&gt;에서는 소문자로 작성되어야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;클로징-핸드셰이크&#34; &gt;클로징 핸드셰이크
&lt;span&gt;
    &lt;a href=&#34;#%ed%81%b4%eb%a1%9c%ec%a7%95-%ed%95%b8%eb%93%9c%ec%85%b0%ec%9d%b4%ed%81%ac&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;연결을 종료하기 위해서는 클라이언트, 서버 두 피어 중 한 측(A)에서 &lt;code&gt;제어 시퀀스(control sequence)&lt;/code&gt;가 포함된 &lt;code&gt;제어 프레임&lt;/code&gt;을 전송해 &lt;code&gt;클로징 핸드셰이크&lt;/code&gt;를 시작할 수 있음&lt;/li&gt;
&lt;li&gt;이를 수신한 다른 피어(B)는 응답으로 &lt;code&gt;닫기 프레임(close frame)&lt;/code&gt;을 전송함&lt;/li&gt;
&lt;li&gt;응답을 수신한 피어(A)는 연결을 닫으며, 서로는 더 이상 데이터를 보내지도, 수신하지도 않음&lt;/li&gt;
&lt;li&gt;이러한 별도의 &lt;code&gt;클로징 핸드셰이크&lt;/code&gt;는, &lt;code&gt;TCP 클로징 핸드셰이크(FIN/ACK)&lt;/code&gt;가 프록시 및 중개자에 의해 신뢰성이 낮아진다는 점을 보완하기 위해 사용됨&lt;/li&gt;
&lt;li&gt;&lt;code&gt;HTTP/2&lt;/code&gt;에서도 이와 유사한 형태로 스트림 클로저가 이뤄지며, TCP 수준 클로저는 &lt;code&gt;HTTP/2&lt;/code&gt; 데이터 프레임의 &lt;code&gt;END_STREAM&lt;/code&gt; 플래그로 표현됨&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;기본-데이터-프레임-구조&#34; &gt;기본 데이터 프레임 구조
&lt;span&gt;
    &lt;a href=&#34;#%ea%b8%b0%eb%b3%b8-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ed%94%84%eb%a0%88%ec%9e%84-%ea%b5%ac%ec%a1%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;&lt;img src=&#34;WebSocket-Data-Frame.png&#34; alt=&#34;WebSocket-Data-Frame.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;웹소켓 프로토콜에서 &lt;code&gt;데이터 전달&lt;/code&gt;을 목적으로 사용되는 &lt;code&gt;프레임&lt;/code&gt;은 위와 같은 구조로 이루어져 있음&lt;/li&gt;
&lt;li&gt;클라이언트에서 서버로 전송되는 모든 프레임은 &lt;code&gt;네트워크 중개자(ex. 프록시)&lt;/code&gt;의 &lt;code&gt;가로채기&lt;/code&gt;와 같은 행위를 차단하고, &lt;code&gt;보안 관련 이유&lt;/code&gt;로 &lt;strong&gt;&lt;code&gt;마스킹&lt;/code&gt;&lt;/strong&gt; 이 필수적임
&lt;ul&gt;
&lt;li&gt;이는 웹소켓이 TLS와 함께 이뤄지는지 여부와 상관 없이 항상 수행&lt;/li&gt;
&lt;li&gt;서버는 마스킹되지 않은 프레임을 수신할 경우 연결을 닫아야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;주요 필드
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;FIN&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;현재 프레임이 메시지의 &lt;code&gt;마지막 조각(Fragment)&lt;/code&gt;임을 나타내는 플래그&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;opcode&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;페이로드 데이터의 유형을 나타내는 값
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;%x0&lt;/code&gt;: 연속 프레임&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%x1&lt;/code&gt;: 텍스트 프레임&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%x2&lt;/code&gt;: 이진 프레임&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%x8&lt;/code&gt;: 연결 종료&lt;/li&gt;
&lt;li&gt;&lt;code&gt;%x9&lt;/code&gt;: 핑 / &lt;code&gt;%xA&lt;/code&gt;: 퐁&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;masking key&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;클라이언트에서 서버로 전송되는 모든 프레임은 이 32비트 &lt;code&gt;마스킹 키&lt;/code&gt;로 마스킹 됨&lt;/li&gt;
&lt;li&gt;클라이언트는 매 번 허용된 32비트 값 집합에서 새로운 마스킹 키를 선택해, 프레임을 마스킹해야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;payload data&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;애플리케이션 데이터&lt;/code&gt;와, 그와 연결된 &lt;code&gt;확장 데이터&lt;/code&gt;로 이뤄짐
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;확장 데이터&lt;/code&gt;: 오프닝 핸드셰이크때 사전 협의된 길이와 방법대로 사용되는 추가 데이터&lt;/li&gt;
&lt;li&gt;&lt;code&gt;애플리케이션 데이터&lt;/code&gt;: &lt;code&gt;확장 데이터&lt;/code&gt; 다음 프레임의 나머지 공간을 차지하는 데이터&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;javascript의-websocket&#34; &gt;Javascript의 WebSocket
&lt;span&gt;
    &lt;a href=&#34;#javascript%ec%9d%98-websocket&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;Javascript에서는 &lt;code&gt;Web API&lt;/code&gt; 중 &lt;code&gt;브라우저 API&lt;/code&gt;에서 제공되는 &lt;code&gt;WebSocket API&lt;/code&gt;를 활용해 브라우저와 서버간 양방향 통신을 열 수 있음&lt;/li&gt;
&lt;li&gt;&lt;code&gt;WebSocket API&lt;/code&gt;는 웹소켓 연결 및 통신을 위한 두 가지 메커니즘인 &lt;code&gt;WebSocket&lt;/code&gt; 인터페이스와 &lt;code&gt;WebSocketStream&lt;/code&gt; 인터페이스를 제공
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WebSocket&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;안정적이며, 대부분의 브라우저 및 서버에서 지원됨&lt;/li&gt;
&lt;li&gt;다만, &lt;code&gt;배압(Backpressure)&lt;/code&gt;을 지원하지 않기 때문에 &lt;em&gt;애플리케이션이 처리할 수 있는 속도보다 빠르게 메시지가 도착&lt;/em&gt;할 경우 &lt;code&gt;메시지를 버퍼링&lt;/code&gt;해 &lt;code&gt;메모리를 가득 채우거나&lt;/code&gt;, &lt;code&gt;CPU 사용률이 100%&lt;/code&gt;가 되어 애플리케이션이 정상 동작하지 않을 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;WebSocketStream&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WebSocket&lt;/code&gt;의 &lt;code&gt;Promise&lt;/code&gt;기반 대안으로, &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Streams_API&#34;&gt;&lt;code&gt;Stream API&lt;/code&gt;&lt;/a&gt;를 사용해 메시지 수신 및 전송을 처리함
&lt;ul&gt;
&lt;li&gt;따라서 소켓 연결이 &lt;code&gt;Stream Backpressure&lt;/code&gt; 자동으로 활용하여 읽기 및 쓰기 속도를 조절할 수 있고, 이를 통해 병목 현상을 방지할 수 있음&lt;/li&gt;
&lt;li&gt;그러나, &lt;code&gt;WebSocketStream&lt;/code&gt;은 비표준으로, &lt;code&gt;크로미움 기반 브라우저&lt;/code&gt;(ex. Chrome, Edge, &amp;hellip;)을 제외한 나머지 브라우저들(Safari, Firefox)은 지원하지 않고 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;websocket-api&#34; &gt;WebSocket API
&lt;span&gt;
    &lt;a href=&#34;#websocket-api&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;h3 id=&#34;연결-생성하기&#34; &gt;연결 생성하기
&lt;span&gt;
    &lt;a href=&#34;#%ec%97%b0%ea%b2%b0-%ec%83%9d%ec%84%b1%ed%95%98%ea%b8%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;웹소켓 연결을 생성하기 위해서는, &lt;code&gt;WebSocket&lt;/code&gt; 생성자를 호출하면 됨&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// WebSocket 생성자는 url, 또는 url과 protocol을 인자로 받음
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// 1. new WebSocket(url)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// url은 ws, wss, http, https 중 하나의 스키마를 사용해야 함
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// 또한, Node.js나 Deno같은 JS 런타임에서는 http, https를 비롯해 상대 URL을 지원하지 않음
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;new&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;WebSocket&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;ws://somewhere.net&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// 2. new WebSocket(url, protocols)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// protocols는 웹소켓의 서브 프로토콜을 나타내는 문자열(또는 문자열 배열)
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// 연결당 하나의 서브 프로토콜만 선택할 수 있으며, 허용되는 값은 `Sec-WebSocket-Protocol HTTP`에서 지정할 수 있는 값임
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;new&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;WebSocket&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;ws://somewhere.net&amp;#34;&lt;/span&gt;, [&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;soap&amp;#34;&lt;/span&gt;]);
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;생성된 &lt;code&gt;WebSocket&lt;/code&gt; 객체의 프로퍼티를 통해 어떤 호스트와 통신하는지, 서브 프로토콜은 무엇인지를 알 수 있음
&lt;ul&gt;
&lt;li&gt;서브 프로토콜은 &lt;a href=&#34;https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name&#34;&gt;IANA의 WebSocket Subprotocol Name Registry&lt;/a&gt;에 포함된 것으로 사용 가능&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;console&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;log&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;url&lt;/span&gt;) &lt;span style=&#34;color:#75715e&#34;&gt;// &amp;#39;ws://somewhere.net&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;console&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;log&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;protocol&lt;/span&gt;) &lt;span style=&#34;color:#75715e&#34;&gt;// [&amp;#39;soap&amp;#39;]
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;이벤트-처리하기&#34; &gt;이벤트 처리하기
&lt;span&gt;
    &lt;a href=&#34;#%ec%9d%b4%eb%b2%a4%ed%8a%b8-%ec%b2%98%eb%a6%ac%ed%95%98%ea%b8%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;생성된 웹소켓 연결에서 발생하는 이벤트를 처리하기 위해, &lt;code&gt;addEventListener&lt;/code&gt;를 사용하거나, &lt;code&gt;WebSocket&lt;/code&gt;의 &lt;code&gt;on이벤트이름&lt;/code&gt; 프로퍼티에 이벤트 리스너를 할당해줄 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;open연결-생성&#34; &gt;open(연결 생성)
&lt;span&gt;
    &lt;a href=&#34;#open%ec%97%b0%ea%b2%b0-%ec%83%9d%ec%84%b1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;onopen&lt;/code&gt;: 웹소켓 연결이 열렸을 때, 발동되는 이벤트리스너&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;onopen&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;e&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;alert&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;웹소켓 연결이 생성되었습니다. &amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;send&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;Hello there!&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;이벤트리스너에게 전달되는 &lt;code&gt;Event&lt;/code&gt;는 일반 &lt;code&gt;Event&lt;/code&gt;임&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;message데이터-수신&#34; &gt;message(데이터 수신)
&lt;span&gt;
    &lt;a href=&#34;#message%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%88%98%ec%8b%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;onmessage&lt;/code&gt;: 웹소켓 연결을 통해 데이터가 수신될 때, 발동되는 이벤트리스너&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;onmessage&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;e&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;alert&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;서버로부터 다음과 같은 메시지가 수신되었습니다.&amp;#34;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;alert&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;`메시지: &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;e&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;data&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;`&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;MessageEvent&lt;/code&gt;:  &lt;code&gt;message&lt;/code&gt; 이벤트리스너에게 전달되는 이벤트
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;data&lt;/code&gt;: &lt;code&gt;메시지 발신자(emitter)&lt;/code&gt;가 보내온 데이터. &lt;code&gt;WebSocket.binaryType&lt;/code&gt;에 따라 &lt;code&gt;data&lt;/code&gt;의 유형이 달라짐
&lt;ul&gt;
&lt;li&gt;메시지 유형이 &lt;code&gt;text&lt;/code&gt;인 경우, &lt;code&gt;data&lt;/code&gt;는 문자열 값&lt;/li&gt;
&lt;li&gt;메시지 유형이 &lt;code&gt;binary&lt;/code&gt;인 경우, &lt;code&gt;data&lt;/code&gt;의 유형은 &lt;code&gt;WebSocket.binaryType&lt;/code&gt;에 따라 달라짐
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;binaryType&lt;/code&gt;이 &lt;code&gt;arraybuffer&lt;/code&gt;인 경우, &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer&#34;&gt;&lt;code&gt;ArrayBuffer&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;binaryType&lt;/code&gt;이 &lt;code&gt;blob&lt;/code&gt;인 경우, &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Blob&#34;&gt;&lt;code&gt;Blob&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;origin&lt;/code&gt;: 메시지 &lt;code&gt;발신자의 출처&lt;/code&gt;를 나타내는 문자열&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;error에러-발생&#34; &gt;error(에러 발생)
&lt;span&gt;
    &lt;a href=&#34;#error%ec%97%90%eb%9f%ac-%eb%b0%9c%ec%83%9d&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;onerror&lt;/code&gt;: 데이터가 안보내진다거나 하는 오류로 웹소켓 연결이 닫힐 때, 발동되는 이벤트리스너&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;onerror&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;error&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;alert&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;`다음과 같은 에러가 발생했습니다. &lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;error&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;`&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;이벤트리스너에게 전달되는 &lt;code&gt;Event&lt;/code&gt;는 일반 &lt;code&gt;Event&lt;/code&gt;임&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;close연결-종료&#34; &gt;close(연결 종료)
&lt;span&gt;
    &lt;a href=&#34;#close%ec%97%b0%ea%b2%b0-%ec%a2%85%eb%a3%8c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;onclose&lt;/code&gt;: 웹소켓 연결이 닫힐 때, 발동되는 이벤트리스너&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;socket&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;onclose&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;e&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#a6e22e&#34;&gt;e&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;wasClean&lt;/span&gt;) {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	&lt;span style=&#34;color:#75715e&#34;&gt;// 연결이 정상적으로 종료된 경우
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;alert&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;`연결이 정상적으로 종료되었습니다(code=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;event&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;code&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt; reason=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;${&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;event&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;reason&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;}&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;)`&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  } &lt;span style=&#34;color:#66d9ef&#34;&gt;else&lt;/span&gt; {
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;	&lt;span style=&#34;color:#75715e&#34;&gt;// 프로세스가 죽거나, 네트워크 장애와 같은 이유로 연결이 닫힌 경우
&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;&lt;/span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;alert&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;커넥션이 죽었습니다.&amp;#39;&lt;/span&gt;);
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  }
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;};
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CloseEvent&lt;/code&gt;: &lt;code&gt;close&lt;/code&gt; 이벤트리스너에게 전달되는 이벤트
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;code&lt;/code&gt;: &lt;code&gt;1000~4999&lt;/code&gt; 사이의 &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent/code&#34;&gt;웹소켓 연결 종료 코드&lt;/a&gt; 를 나타내는 &lt;code&gt;unsigned short&lt;/code&gt; 값&lt;/li&gt;
&lt;li&gt;&lt;code&gt;reason&lt;/code&gt;: &lt;code&gt;서버가 연결을 종료한 이유&lt;/code&gt;를 나타내는 문자열&lt;/li&gt;
&lt;li&gt;&lt;code&gt;wasClean&lt;/code&gt;: 연결이 정상적으로 닫혔는지 여부를 나타내는 부울 값&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;메시지-전송과-연결-닫기&#34; &gt;메시지 전송과 연결 닫기
&lt;span&gt;
    &lt;a href=&#34;#%eb%a9%94%ec%8b%9c%ec%a7%80-%ec%a0%84%ec%86%a1%ea%b3%bc-%ec%97%b0%ea%b2%b0-%eb%8b%ab%ea%b8%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WebSocket&lt;/code&gt; 객체에는 데이터를 전송할 수 있는 &lt;code&gt;send()&lt;/code&gt; 메서드와 연결을 종료할 수 있는 &lt;code&gt;close&lt;/code&gt; 메서드가 존재&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;메시지-전송httpsdevelopermozillaorgen-usdocswebapiwebsocketsend&#34; &gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/send&#34;&gt;메시지 전송&lt;/a&gt;
&lt;span&gt;
    &lt;a href=&#34;#%eb%a9%94%ec%8b%9c%ec%a7%80-%ec%a0%84%ec%86%a1httpsdevelopermozillaorgen-usdocswebapiwebsocketsend&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;WebSocket.send()&lt;/code&gt; 메서드를 통해 사용자가 서버로 데이터를 전송할 수 있음
&lt;ul&gt;
&lt;li&gt;정확히는, 전송할 데이터를 &lt;code&gt;대기열&lt;/code&gt;에 넣고, &lt;code&gt;bufferedAmount&lt;/code&gt; 값을 늘림&lt;/li&gt;
&lt;li&gt;만약 데이터를 전송할 수 없는 경우, 소켓은 자동으로 닫힘&lt;/li&gt;
&lt;li&gt;연결이 &lt;code&gt;CONNECTING&lt;/code&gt; 상태라면 브라우저가 예외를 던지고, &lt;code&gt;CLOSING&lt;/code&gt; 또는 &lt;code&gt;CLOSED&lt;/code&gt; 상태라면 데이터를 자동으로 삭제함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;send()&lt;/code&gt;는 &lt;code&gt;data&lt;/code&gt;라는 하나의 인자만 받으며, &lt;code&gt;data&lt;/code&gt;의 타입은 다음 중 하나여야 함
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;string&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;UTF-8로 인코딩되어 버퍼에 추가되며, 이를 나타내는데 필요한 바이트 수만큼 &lt;code&gt;bufferedAmount&lt;/code&gt;가 증가함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer&#34;&gt;&lt;code&gt;ArrayBuffer&lt;/code&gt;&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;타입이 지정된 배열 객체(typed array object)&lt;/code&gt;가 사용하는 &lt;code&gt;바이너리 데이터&lt;/code&gt;를 전송할 수 있으며, 이는 버퍼에 추가되고 해당 바이너리 데이터 바이트 수 만큼 &lt;code&gt;bufferedAmount&lt;/code&gt;가 증가함
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ArrayBuffer&lt;/code&gt;는 다른 언어에서 &lt;code&gt;Byte Array&lt;/code&gt;라고 일컫는, byte들의 배열임
&lt;ul&gt;
&lt;li&gt;내용을 직접 조작할 순 없으나, 후술할 &lt;code&gt;typed Array&lt;/code&gt; 객체나 &lt;code&gt;DataView&lt;/code&gt; 객체를 통해 버퍼의 내용을 읽고 쓸 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Blob&#34;&gt;&lt;code&gt;Blob&lt;/code&gt;&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;불변 로우 데이터&lt;/code&gt;로 이뤄진, &lt;code&gt;파일&lt;/code&gt;과 유사한 객체인 &lt;code&gt;Blob&lt;/code&gt;의 &lt;code&gt;로우 데이터&lt;/code&gt;가 버퍼에 추가되며(이때, &lt;code&gt;Blob.type&lt;/code&gt;은 &lt;code&gt;무시&lt;/code&gt;됨), &lt;code&gt;bufferedAmount&lt;/code&gt;는 해당 로우 데이터의 바이트 크기만큼 증가함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TypedArray&lt;/code&gt;/&lt;code&gt;DataView&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Javascript Typed Array(ex. Int8Array, Int16Array, ...)&lt;/code&gt;가 가지고 있는 바이너리 데이터들이 버퍼에 추가되며, 필요한 바이트 수만큼 &lt;code&gt;bufferedAmount&lt;/code&gt;가 증가함&lt;/li&gt;
&lt;li&gt;또는, &lt;code&gt;이진 ArrayBuffer&lt;/code&gt;에서 여러 넘버 타입을 읽고 쓸 수 있게 해주는 저수준 인터페이스인 &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView&#34;&gt;&lt;code&gt;DataView&lt;/code&gt;&lt;/a&gt;도 인자로 사용할 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;연결-닫기&#34; &gt;연결 닫기
&lt;span&gt;
    &lt;a href=&#34;#%ec%97%b0%ea%b2%b0-%eb%8b%ab%ea%b8%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;연결 피어 중 한 측에서 연결을 닫고 싶을때, &lt;code&gt;WebSocket.close()&lt;/code&gt; 메서드를 통해 연결을 종료할 수 있음
&lt;ul&gt;
&lt;li&gt;만약 &lt;code&gt;클로징 핸드셰이크&lt;/code&gt; 전에 메시지를 보내거나, 여전히 보내고 있다면 이러한 메시지들이 모두 전송된 뒤에 핸드셰이크가 시작됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;close()&lt;/code&gt;는 옵셔널 인자인 &lt;code&gt;code&lt;/code&gt;와 &lt;code&gt;reason&lt;/code&gt; 인자를 받음
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;code&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;종료 이유를 나타내는 &lt;code&gt;웹소켓 연결 종료 코드&lt;/code&gt; 정수값&lt;/li&gt;
&lt;li&gt;값을 지정하지 않으면, 일반 종료의 경우 &lt;code&gt;1000&lt;/code&gt;, 이외 연결 종료 사유가 있는 경우 그에 해당하는 &lt;code&gt;1001 ~ 1015&lt;/code&gt; 범위의 코드 값으로 설정됨&lt;/li&gt;
&lt;li&gt;&lt;code&gt;code&lt;/code&gt; 값이 설정되면, &lt;code&gt;reason&lt;/code&gt; 값도 설정되어야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;reason&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;사용자 지정 웹소켓 연결 종료 이유&lt;/code&gt;를 제공하는 문자열로, UTF-8로 인코딩되어야 하고 123바이트를 넘지 않아야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;예시&#34; &gt;예시
&lt;span&gt;
    &lt;a href=&#34;#%ec%98%88%ec%8b%9c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://jsfiddle.net/bmknight/RqbYB&#34;&gt;WebSockets Example - JSFiddle - Code Playground&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;해당 예제에서 주소를 &lt;code&gt;ws&lt;/code&gt;에서 &lt;code&gt;wss&lt;/code&gt;로 바꿔주면 정상 동작함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>[Network] TCP와 UDP 알아보기 (w. 흐름 제어, 혼잡 제어, CongWin, HTTP/3)</title>
      <link>https://cloudsoswift.github.io/post/develop/network/tcp-udp/</link>
      <pubDate>Fri, 01 Nov 2024 18:18:16 +0900</pubDate>
      
      <guid>https://cloudsoswift.github.io/post/develop/network/tcp-udp/</guid>
      <description>&lt;h1 id=&#34;서론&#34; &gt;서론
&lt;span&gt;
    &lt;a href=&#34;#%ec%84%9c%eb%a1%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;p&gt;&lt;a href=&#34;https://github.com/orm712/CS-712&#34;&gt;CS 스터디&lt;/a&gt;에서 10월 28일 발표한 &lt;a href=&#34;https://github.com/orm712/CS-712/blob/main/03-NETWORK/7_TCP-UDP/Readme.md&#34;&gt;&lt;strong&gt;TCP &amp;amp; UDP&lt;/strong&gt;&lt;/a&gt;에 대해 정리한 문서를 블로그에 공유하고자 한다.&lt;/p&gt;
&lt;h2 id=&#34;tcp와-udp에-대하여&#34; &gt;TCP와 UDP에 대하여
&lt;span&gt;
    &lt;a href=&#34;#tcp%ec%99%80-udp%ec%97%90-%eb%8c%80%ed%95%98%ec%97%ac&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP&lt;/code&gt;와 &lt;code&gt;UDP&lt;/code&gt;는 네트워크 계층 중 &lt;code&gt;전송 계층(transport-layer)&lt;/code&gt;에서 사용되는 프로토콜
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;전송 계층&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;프로세스 간 &lt;code&gt;논리적 통신(logical communication)&lt;/code&gt;이 이뤄지는 계층&lt;/li&gt;
&lt;li&gt;&lt;code&gt;네트워크 계층&lt;/code&gt;의 서비스들에 의존하고, 이들을 강화시키는 계층&lt;/li&gt;
&lt;li&gt;보내려는 메시지를 &lt;code&gt;전송 계층&lt;/code&gt;의 규격에 맞게 분할 후, 해야할 일을 헤더로 부착해 보내는 과정을 거침&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;tcp&#34; &gt;TCP
&lt;span&gt;
    &lt;a href=&#34;#tcp&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;요약&#34; &gt;요약
&lt;span&gt;
    &lt;a href=&#34;#%ec%9a%94%ec%95%bd&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;신뢰성&lt;/code&gt;(&lt;code&gt;reliable&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;순서&lt;/code&gt;에 맞게 전송하고자 함(&lt;code&gt;in-order&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;혼잡 제어&lt;/code&gt;, &lt;code&gt;흐름 제어&lt;/code&gt;, &lt;code&gt;연결 설정&lt;/code&gt;과 같은 기능 제공&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;주요-특징&#34; &gt;주요 특징
&lt;span&gt;
    &lt;a href=&#34;#%ec%a3%bc%ec%9a%94-%ed%8a%b9%ec%a7%95&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;1대1 통신&lt;/code&gt;&lt;/strong&gt;(&lt;code&gt;unicast&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;신뢰할 수 있고, 순차적인 바이트스트림&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;메시지 바운더리&lt;/code&gt; 없음 (전송되는 두 &lt;strong&gt;&lt;code&gt;메시지 사이의 구분&lt;/code&gt;&lt;/strong&gt; 이 &lt;strong&gt;없음&lt;/strong&gt;)
&lt;img src=&#34;sequence-number_ACK-number.png&#34; alt=&#34;sequence-number_ACK-number.png&#34;&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;송신 번호&lt;/code&gt;, &lt;code&gt;ACK 번호&lt;/code&gt;를 사용&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;파이프라인&lt;/code&gt; 사용&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;TCP &lt;code&gt;혼잡, 흐름 제어&lt;/code&gt;를 위한 &lt;code&gt;window size&lt;/code&gt;를 설정&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;전이중 데이터&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;동일한 연결 상에서 양방향 통신&lt;/li&gt;
&lt;li&gt;최대 세그먼트 크기(&lt;code&gt;MSS&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;연결지향적 통신&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;데이터 교환 전, &lt;code&gt;핸드셰이킹(제어 메시지 교환)&lt;/code&gt;으로 송신자-수신자 &lt;code&gt;상태 초기화&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;흐름 제어&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;송신자가 수신자를 &lt;code&gt;압도(overwhelm)&lt;/code&gt;하지 않음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;rttround-trip-time-왕복-시간&#34; &gt;RTT(Round Trip Time, 왕복 시간)
&lt;span&gt;
    &lt;a href=&#34;#rttround-trip-time-%ec%99%95%eb%b3%b5-%ec%8b%9c%ea%b0%84&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;&lt;em&gt;TCP의 효율적인 통신을 위해&lt;/em&gt;, 지정된 시간 내에 &lt;code&gt;ACK 신호&lt;/code&gt;나 &lt;code&gt;세그먼트&lt;/code&gt;를 수신하지 못한 경우, &lt;code&gt;연결 시간 초과(timeout)&lt;/code&gt;로 처리하고 연결을 종료해야 함.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;이때, &lt;code&gt;TCP timeout 시간&lt;/code&gt;은 RTT보다 길어야 함
&lt;ul&gt;
&lt;li&gt;하지만, RTT는 편차가 있을 수 있음&lt;/li&gt;
&lt;li&gt;너무 짧게 잡는다면, 재전송이 자주 발생함&lt;/li&gt;
&lt;li&gt;너무 길게 잡는다면, &lt;code&gt;세그먼트 손실&lt;/code&gt;에 대해 느리게 반응하게 됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;이때, &lt;code&gt;RTT의 편차&lt;/code&gt; 등을 어떻게 측정해야 할까?
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;SampleRTT&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;세그먼트 전송 후, &lt;code&gt;ACK 수신&lt;/code&gt;까지 측정된 시간 (재전송 무시)&lt;/li&gt;
&lt;li&gt;다만 &lt;code&gt;SampleRTT&lt;/code&gt; 역시 다양할 수 있으므로, 이들의 여러 최근 측정값을 평균내어 사용&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;RTT의 기준?&lt;img src=&#34;TCP-RTT.png&#34; alt=&#34;TCP-RTT.png&#34;&gt;
&lt;ul&gt;
&lt;li&gt;만약 ACK 수신 이전, &lt;code&gt;여러 번의 세그먼트 전송&lt;/code&gt;이 발생한 경우 &lt;code&gt;가장 처음 보낸 세그먼트를 기준&lt;/code&gt;으로 함&lt;/li&gt;
&lt;li&gt;만약 &lt;code&gt;동일한 세그먼트가 재전송&lt;/code&gt; 된 경우, &lt;code&gt;RTT 측정에 포함하지 않음&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;처음 보낸 세그먼트에 대한 ACK 인지, 재전송된 세그먼트에 대한 ACK인지 &lt;code&gt;구분할 수 없기 때문&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;신뢰할-수-있는-데이터-전송&#34; &gt;신뢰할 수 있는 데이터 전송
&lt;span&gt;
    &lt;a href=&#34;#%ec%8b%a0%eb%a2%b0%ed%95%a0-%ec%88%98-%ec%9e%88%eb%8a%94-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%a0%84%ec%86%a1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;&lt;img src=&#34;rdt-transport-to-app.png&#34; alt=&#34;rdt-transport-to-app.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;응용, 전송, 링크 계층에서 &lt;code&gt;신뢰성&lt;/code&gt;은 매우 중요한 개념으로, 각 계층마다 신뢰성 유지를 위해 데이터를 체크
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;신뢰성&lt;/code&gt;&lt;/strong&gt;: &lt;code&gt;비트 에러&lt;/code&gt;, &lt;code&gt;패킷 손실&lt;/code&gt; 없이 한 번만 전송하는 것&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;tcp에서의-rdt&#34; &gt;TCP에서의 RDT
&lt;span&gt;
    &lt;a href=&#34;#tcp%ec%97%90%ec%84%9c%ec%9d%98-rdt&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;ul&gt;
&lt;li&gt;TCP는 &lt;code&gt;RDT(Reliable Data Transfer, 신뢰성 있는 데이터 전송) 서비스&lt;/code&gt;를 IP의 신뢰성 없는 서비스 위에 구축함
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;파이프라인화된 세그먼트&lt;/code&gt; (연속으로 전송할 수 있음)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;누적 ACK&lt;/code&gt; (GoBackN과 유사)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;단일 재전송 타이머&lt;/code&gt; (데이터 보낸 시간 != timeout 시간 일 수 있음)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;재전송&lt;/code&gt;은 다음 두 경우 발생
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;timeout 이벤트&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;timeout이 발생한 경우, 이를 일으킨 세그먼트를 재전송&lt;/li&gt;
&lt;li&gt;타이머 재시작&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;중복된 ACK&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;이전에 ACK되지 않은 세그먼트를 ACK하는 경우&lt;/li&gt;
&lt;li&gt;어떤 패킷이 ACK되었다고 알려져있는지 갱신&lt;/li&gt;
&lt;li&gt;ACK되지 않은 세그먼트 아직 있으면 타이머 시작&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;흐름-제어&#34; &gt;흐름 제어
&lt;span&gt;
    &lt;a href=&#34;#%ed%9d%90%eb%a6%84-%ec%a0%9c%ec%96%b4&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;&lt;img src=&#34;flow-control.png&#34; alt=&#34;flow-control.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;흐름 제어&lt;/code&gt;: 빠른 발신자가 너무 많이, 너무 빨리 전송해 느린 수신자 버퍼가 넘치지 않도록(압도하지 않도록) 함&lt;/li&gt;
&lt;li&gt;수신자는 TCP 헤더에 &lt;code&gt;윈도우 크기(rwnd)&lt;/code&gt;를 포함시켜, 사용 가능한 버퍼 공간을 명시함 &lt;img src=&#34;rcvBuffer.png&#34; alt=&#34;rcvBuffer.png&#34;&gt;
&lt;ul&gt;
&lt;li&gt;소켓 옵션을 통해 설정된 &lt;code&gt;수신자 버퍼(RcvBuffer)&lt;/code&gt;크기 값으로, 보통 4096 byte가 디폴트&lt;/li&gt;
&lt;li&gt;대부분의 운영체제에서 이 크기를 &lt;code&gt;자동 조정&lt;/code&gt;함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;발신자는 &lt;code&gt;수신자의 윈도우 크기&lt;/code&gt; 만큼만 &lt;code&gt;ACK되지 않은(in-flight) 데이터&lt;/code&gt;를 보낼 수 있음
&lt;ul&gt;
&lt;li&gt;이는 수신자 버퍼가 넘치지 않도록 보장&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;stop-and-wait&#34; &gt;Stop-and-wait
&lt;span&gt;
    &lt;a href=&#34;#stop-and-wait&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;ul&gt;
&lt;li&gt;가장 간단한 형태의 흐름 제어 기법&lt;/li&gt;
&lt;li&gt;발신자가 하나의 패킷을 보낸 뒤, 수신자의 응답이 올 때까지 기다림
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ACK&lt;/code&gt; 를 수신하거나, 타임아웃이 발생하면 다시 패킷 전송&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;go-back-n&#34; &gt;Go-back-N
&lt;span&gt;
    &lt;a href=&#34;#go-back-n&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;p&gt;&lt;img src=&#34;go-back-n.png&#34; alt=&#34;go-back-n.png&#34;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;send_base: 보낸 패킷
nextseqnum: 보낼 예정인 패킷&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;N개의 &lt;code&gt;ACK되지 않은 패킷&lt;/code&gt;을 파이프라인을 통해 전송&lt;/li&gt;
&lt;li&gt;수신자는 &lt;code&gt;누적 ACK(cumulative ACK)&lt;/code&gt;만 전송&lt;/li&gt;
&lt;li&gt;발신자는 가장 &lt;strong&gt;오래된&lt;/strong&gt; &lt;code&gt;ACK되지 않은 패킷&lt;/code&gt;에 대한 타이머 갖고 있음
&lt;ul&gt;
&lt;li&gt;타임아웃 발생시, &lt;code&gt;모든 ACK되지 않은 패킷들&lt;/code&gt;을 재전송
&lt;ul&gt;
&lt;li&gt;즉, &lt;code&gt;가장 마지막으로 ACK 받은&lt;/code&gt; 시퀀스 번호로 돌아가 재전송&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;selective-repeat&#34; &gt;Selective Repeat
&lt;span&gt;
    &lt;a href=&#34;#selective-repeat&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;p&gt;&lt;img src=&#34;selective-repeat.png&#34; alt=&#34;selective-repeat.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;N개의 &lt;code&gt;ACK되지 않은 패킷&lt;/code&gt;을 파이프라인을 통해 전송&lt;/li&gt;
&lt;li&gt;수신자는 &lt;code&gt;각각의 패킷에 대한 ACK&lt;/code&gt;를 전송&lt;/li&gt;
&lt;li&gt;발신자는 각 패킷에 대한 타이머를 갖고있음
&lt;ul&gt;
&lt;li&gt;타임아웃 발생시, &lt;code&gt;해당 패킷만&lt;/code&gt; 재전송&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;수신자는 &lt;code&gt;순서를 지켜(in-order)&lt;/code&gt; 상위 계층에 패킷들을 전달하기 위해, &lt;code&gt;버퍼&lt;/code&gt; 사용
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;문제 생긴 패킷&lt;/em&gt; &lt;code&gt;다음의 패킷들&lt;/code&gt;을 버퍼에 저장, 또는 &lt;code&gt;순서에 맞지않는 패킷들&lt;/code&gt; 저장&lt;/li&gt;
&lt;li&gt;이후, 문제 생긴 패킷을 재전송받고, &lt;code&gt;일정 갯수의 패킷&lt;/code&gt;이 모이면 &lt;code&gt;상위 계층으로 전달&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;참고&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://computerscience.unicam.it/marcantoni/reti/applet/SelectiveRepeatProtocol/selRepProt.html&#34;&gt;Selective Repeat Protocol&lt;/a&gt; : Selective Repeat 흐름을 테스트해볼 수 있는 사이트&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;혼잡-제어&#34; &gt;혼잡 제어
&lt;span&gt;
    &lt;a href=&#34;#%ed%98%bc%ec%9e%a1-%ec%a0%9c%ec%96%b4&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;ul&gt;
&lt;li&gt;발신자가 혼잡함을 인식하는 기준
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;손실 이벤트(loss event)&lt;/code&gt;: &lt;code&gt;타임아웃&lt;/code&gt; 또는 &lt;code&gt;3번&lt;/code&gt;의 &lt;code&gt;중복된 ACK&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;TCP 발신자는 &lt;code&gt;손실 이벤트&lt;/code&gt; 발생시, 혼잡에 대응하기 위해 &lt;code&gt;혼잡 윈도우(Congestion Window, CongWin)&lt;/code&gt;의 크기를 조절해 대응&lt;/li&gt;
&lt;li&gt;&lt;code&gt;혼잡 제어&lt;/code&gt;를 위해 &lt;code&gt;AIMD&lt;/code&gt;, &lt;code&gt;slow start&lt;/code&gt;, &lt;code&gt;conservative after timeout events&lt;/code&gt; 3가지 메커니즘 존재&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;aimd&#34; &gt;AIMD
&lt;span&gt;
    &lt;a href=&#34;#aimd&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;p&gt;&lt;img src=&#34;AIMD.png&#34; alt=&#34;AIMD.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Additive Increase Multiplicative Decrease&lt;/code&gt;의 약어&lt;/li&gt;
&lt;li&gt;&lt;code&gt;혼잡 윈도우&lt;/code&gt;를 &lt;em&gt;혼잡이 감지되지 않을때&lt;/em&gt;는 &lt;code&gt;선형적으로 증가&lt;/code&gt;시키다, &lt;em&gt;혼잡이 감지되면&lt;/em&gt; &lt;code&gt;기하급수적으로 감소&lt;/code&gt;시키는 방식
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;손실이 감지될 때까지&lt;/em&gt;, 매 &lt;code&gt;RTT&lt;/code&gt;마다 &lt;code&gt;cwnd&lt;/code&gt;를 1 MSS씩 증가&lt;/li&gt;
&lt;li&gt;&lt;em&gt;손실이 발생하면&lt;/em&gt;, &lt;code&gt;cwnd&lt;/code&gt;를 절반으로 줄임&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;즉, &lt;code&gt;cwnd&lt;/code&gt;는 인식된 네트워크 혼잡 정도를 나타내는 함수라고 할 수 있음&lt;/li&gt;
&lt;li&gt;TCP 전송 속도 $rate \approx {cwnd \over RTT} bytes/sec$&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;slow-start&#34; &gt;Slow Start
&lt;span&gt;
    &lt;a href=&#34;#slow-start&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;p&gt;&lt;img src=&#34;Slow-Start.png&#34; alt=&#34;Slow-Start.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;연결 시작 이후, &lt;code&gt;손실 이벤트&lt;/code&gt; 발생 전까지 속도를 기하급수적으로 증가시키는 방식
&lt;ul&gt;
&lt;li&gt;초기 &lt;code&gt;cwnd&lt;/code&gt; = 1 MSS&lt;/li&gt;
&lt;li&gt;매 RTT마다 &lt;code&gt;cwnd&lt;/code&gt;는 2배씩 증가
&lt;ul&gt;
&lt;li&gt;정확히는 모든 &lt;code&gt;ACK 수신&lt;/code&gt;마다 &lt;code&gt;cwnd&lt;/code&gt;를 2배로 증가시킴&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;시작 값이 1이라 &lt;code&gt;Slow Start&lt;/code&gt;라는 이름이 붙었으며, 증가 속도는 빠름&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;conservative-after-timeout-events타임아웃-발생-후-보수적으로&#34; &gt;Conservative after timeout events(타임아웃 발생 후 보수적으로)
&lt;span&gt;
    &lt;a href=&#34;#conservative-after-timeout-events%ed%83%80%ec%9e%84%ec%95%84%ec%9b%83-%eb%b0%9c%ec%83%9d-%ed%9b%84-%eb%b3%b4%ec%88%98%ec%a0%81%ec%9c%bc%eb%a1%9c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;타임아웃&lt;/code&gt;으로 손실을 인식
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cwnd&lt;/code&gt;는 1로 세팅됨&lt;/li&gt;
&lt;li&gt;이후 &lt;code&gt;cwnd&lt;/code&gt;가 기하급수적으로 &lt;code&gt;임계값(threshold)&lt;/code&gt;까지 증가한 뒤, &lt;code&gt;선형적&lt;/code&gt;으로 증가&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3개의 중복 ACK&lt;/code&gt;로 손실을 인식 : &lt;code&gt;TCP RENO&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;중복 ACK&lt;/code&gt;는 네트워크가 아직 &lt;code&gt;세그먼트들을 전달할 수 있음&lt;/code&gt;을 나타냄&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cwnd&lt;/code&gt;를 &lt;code&gt;절반&lt;/code&gt;으로 줄인 뒤, &lt;code&gt;선형적&lt;/code&gt;으로 증가&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;타임아웃&lt;/code&gt; 또는 &lt;code&gt;3개의 중복 ACK&lt;/code&gt; 발생시 손실 인식 : &lt;code&gt;TCP Tahoe&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;인식시 &lt;code&gt;cwnd&lt;/code&gt;를 1로 설정&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;요약-1&#34; &gt;요약
&lt;span&gt;
    &lt;a href=&#34;#%ec%9a%94%ec%95%bd-1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;p&gt;&lt;img src=&#34;congestion-control-summary.png&#34; alt=&#34;congestion-control-summary.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cwnd&lt;/code&gt;가 임계값보다 낮을때, 발신자는 &lt;code&gt;Slow Start 단계&lt;/code&gt;로, 윈도우가 기하급수적으로 증가&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cwnd&lt;/code&gt;가 임계값 이상이면, 발신자는 &lt;code&gt;혼잡 회피 단계&lt;/code&gt;로, 윈도우는 선형적으로 증가&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3개의 중복 ACK&lt;/code&gt; 발생시, 임계값은 &lt;code&gt;cwnd/2&lt;/code&gt;로 설정되고, &lt;code&gt;cwnd&lt;/code&gt;는 임계값으로 설정됨&lt;/li&gt;
&lt;li&gt;&lt;code&gt;타임아웃&lt;/code&gt; 발생시, 임계값은 &lt;code&gt;cwnd/2&lt;/code&gt;로 설정되고, &lt;code&gt;cwnd&lt;/code&gt;는 &lt;code&gt;1 MSS&lt;/code&gt;로 설정됨&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;tcp-세그먼트-구조&#34; &gt;TCP 세그먼트 구조
&lt;span&gt;
    &lt;a href=&#34;#tcp-%ec%84%b8%ea%b7%b8%eb%a8%bc%ed%8a%b8-%ea%b5%ac%ec%a1%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;TCP-Segment.png&#34; alt=&#34;TCP-Segment.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP 세그먼트&lt;/code&gt;는 다음으로 이뤄져있음
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;송신 포트&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;수신 포트&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;순서 번호&lt;/code&gt; (Sequence Number, 현재 세그먼트의 가장 앞 바이트 번호)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ACK 번호&lt;/code&gt; (마지막으로 수신한 데이터 바이트 다음의 번호)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;헤더 길이&lt;/code&gt;(4 bits)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;예약된 공간&lt;/code&gt;(6 bits)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;TCP 제어 플래그&lt;/code&gt; &lt;a href=&#34;http://www.ktword.co.kr/test/view/view.php?no=2437&#34;&gt;참고 - TCP 제어 플래그&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;URG&lt;/code&gt; : &lt;code&gt;Urgent Pointer&lt;/code&gt;필드에 값이 채워져있음을 알림&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ACK&lt;/code&gt;: &lt;code&gt;ACK 번호&lt;/code&gt; 필드에 값이 세팅되어있음을 알림
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;SYN 세그먼트&lt;/code&gt; 전송 이후 모든 세그먼트에 항상 이 비트가 1로 설정됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PSH&lt;/code&gt;: &lt;code&gt;Push the Data&lt;/code&gt;, &lt;code&gt;버퍼링된 데이터&lt;/code&gt;를 가능한 &lt;code&gt;빨리&lt;/code&gt; 상위 계층 &lt;code&gt;응용프로그램에 전달할 것&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;수신 측은 버퍼가 차기를 기다리지 않고 버퍼링된 데이터들 응용프로그램에전달&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PST&lt;/code&gt;: &lt;code&gt;연결확립(ESTABLISHED)&lt;/code&gt;된 회선에 &lt;code&gt;강제 리셋 요청&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;LISTEN&lt;/code&gt;,&lt;code&gt;SYN_RCVD&lt;/code&gt; 상태라면 &lt;code&gt;LISTEN&lt;/code&gt; 상태로, 그외의 경우 연결 끊고 &lt;code&gt;CLOSED&lt;/code&gt; 상태로&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SYN&lt;/code&gt;: 연결설정을 위해 &lt;code&gt;순서 번호&lt;/code&gt;를 동기화
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;SYN=1, ACK=0&lt;/code&gt; -&amp;gt; SYN 세그먼트(&lt;code&gt;연결 요청&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SYN=1, ACK=1&lt;/code&gt; -&amp;gt; SYN+ACK 세그먼트(&lt;code&gt;연결 허락&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ACK=1&lt;/code&gt; -&amp;gt; ACK 세그먼트(&lt;code&gt;연결 설정&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;FIN&lt;/code&gt;: 연결 종료
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;FIN=1&lt;/code&gt; -&amp;gt; FIN 세그먼트 (&lt;code&gt;종결 요청&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;FIN=1, ACK=1&lt;/code&gt; -&amp;gt; FIN+ACK 세그먼트 (&lt;code&gt;종결 응답&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;윈도우&lt;/code&gt; (수신자가 수락할 의향이 있는 바이트 수)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;체크섬&lt;/code&gt; (헤더+텍스트를 16비트 word들로 분할해, 이를 16비트 1의 보수합으로 누계한 다음, 최종 결과 값의 1의 보수를 구한 것)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;긴급 포인터(Urgent Pointer)&lt;/code&gt;(긴급 포인터의 현재 값을 &lt;code&gt;순서 번호&lt;/code&gt;의 &lt;code&gt;오프셋&lt;/code&gt;으로 전달하는 값. 긴급 포인터는 긴급 데이터 &lt;code&gt;다음 바이트의 순서 번호&lt;/code&gt;를 가리킴)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;옵션&lt;/code&gt; (MSS 옵션 협상, 윈도우 크기 확장, 선택확인응답(SACK) 등의 옵션 데이터를 포함할 수 있음)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;udp&#34; &gt;UDP
&lt;span&gt;
    &lt;a href=&#34;#udp&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;요약-2&#34; &gt;요약
&lt;span&gt;
    &lt;a href=&#34;#%ec%9a%94%ec%95%bd-2&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;신뢰할 수 없음&lt;/strong&gt;(&lt;code&gt;unreliable&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;순서 지키지 않음&lt;/strong&gt;(&lt;code&gt;unordered&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;어떤것도 보장하지 않는(&lt;code&gt;best-effort&lt;/code&gt;) IP의 기본적인(&lt;code&gt;bare bones&lt;/code&gt;) 확장&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;즉, 어떠한 기능도 지원하지 않음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;지연 보장&lt;/code&gt;, &lt;code&gt;대역폭 보장&lt;/code&gt;과 같은 서비스 &lt;code&gt;지원되지 않음&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;모든 데이터들이 동급&lt;/code&gt;이라는 전제가 있어, &amp;lsquo;어떤 파일을 빨리 보내야 한다&amp;rsquo; 이런 개념이 존재하지 않음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;주요-특징-1&#34; &gt;주요 특징
&lt;span&gt;
    &lt;a href=&#34;#%ec%a3%bc%ec%9a%94-%ed%8a%b9%ec%a7%95-1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;h5 id=&#34;best-effort한-서비스-제공&#34; &gt;&amp;ldquo;best effort&amp;quot;한 서비스 제공
&lt;span&gt;
    &lt;a href=&#34;#best-effort%ed%95%9c-%ec%84%9c%eb%b9%84%ec%8a%a4-%ec%a0%9c%ea%b3%b5&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;따라서 &lt;code&gt;UDP Segment&lt;/code&gt;는&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;손실 가능&lt;/code&gt;(송신자는 전송 이후 신경쓰지 않음)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;비순차적&lt;/code&gt;으로 전달됨&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;connectionless&#34; &gt;&lt;code&gt;connectionless&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#connectionless&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;ul&gt;
&lt;li&gt;UDP 송신자-수신자 간 &lt;code&gt;핸드셰이킹&lt;/code&gt; 없음&lt;/li&gt;
&lt;li&gt;각 &lt;code&gt;UDP Segment&lt;/code&gt;는 다른 &lt;code&gt;Segmeent&lt;/code&gt;들과는 독립적으로 처리됨&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;신뢰성-없음&#34; &gt;신뢰성 없음
&lt;span&gt;
    &lt;a href=&#34;#%ec%8b%a0%eb%a2%b0%ec%84%b1-%ec%97%86%ec%9d%8c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;ul&gt;
&lt;li&gt;따라서 UDP 상에서 신뢰성 있는 전송이 필요하다면, &lt;code&gt;응용 계층&lt;/code&gt;에서 이를 &lt;code&gt;구현&lt;/code&gt;해야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;장점&#34; &gt;장점
&lt;span&gt;
    &lt;a href=&#34;#%ec%9e%a5%ec%a0%90&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;연결 조율 과정이 없음&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;따라서 이로인한 &lt;code&gt;딜레이 X&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;단순함&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;송-수신자 간 연결 상태가 존재하지 않음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;작은 헤더 사이즈&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;혼잡 제어 없음&lt;/code&gt;&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;원하는 만큼 빠르게 전송할 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;udp-세그먼트-구조&#34; &gt;UDP 세그먼트 구조
&lt;span&gt;
    &lt;a href=&#34;#udp-%ec%84%b8%ea%b7%b8%eb%a8%bc%ed%8a%b8-%ea%b5%ac%ec%a1%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;UDP-Segment.png&#34; alt=&#34;UDP-Segment.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;UDP 헤더&lt;/code&gt;는 &lt;code&gt;출발 포트&lt;/code&gt;, &lt;code&gt;도착 포트&lt;/code&gt;, &lt;code&gt;길이&lt;/code&gt;(헤더와 세그먼트를 포함한), &lt;code&gt;체크섬&lt;/code&gt;으로 이뤄짐&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;udp-체크섬&#34; &gt;UDP 체크섬
&lt;span&gt;
    &lt;a href=&#34;#udp-%ec%b2%b4%ed%81%ac%ec%84%ac&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;ul&gt;
&lt;li&gt;전송된 세그먼트에서 &lt;code&gt;에러&lt;/code&gt;(ex. &lt;code&gt;반전된 비트(flipped bits)&lt;/code&gt;)를 감지하기 위해 사용되는 데이터 블록&lt;/li&gt;
&lt;li&gt;&lt;code&gt;송신자&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;헤더 필드를 포함한&lt;/em&gt; &lt;code&gt;세그먼트 내용&lt;/code&gt;을 &lt;code&gt;16 bit 정수 시퀀스&lt;/code&gt;로 처리&lt;/li&gt;
&lt;li&gt;&lt;code&gt;체크섬&lt;/code&gt;: &lt;code&gt;세그먼트 내용&lt;/code&gt;의 &lt;code&gt;1의 보수(모든 비트를 반전시킨 값)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;송신자는 체크섬 값을 &lt;code&gt;UDP 체크섬 필드&lt;/code&gt;로 전달&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;수신자&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;수신한 세그먼트의 &lt;code&gt;체크섬을 계산&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;만약 &lt;code&gt;계산한 값&lt;/code&gt;이 &lt;code&gt;체크섬 필드의 값&lt;/code&gt;과
&lt;ul&gt;
&lt;li&gt;같다면, 에러가 검출되지 않은 것&lt;/li&gt;
&lt;li&gt;다르면, 에러가 검출된 것&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;사용처&#34; &gt;사용처
&lt;span&gt;
    &lt;a href=&#34;#%ec%82%ac%ec%9a%a9%ec%b2%98&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;code&gt;UDP&lt;/code&gt;는 위와 같은 특징 때문에 주로 다음의 용도로 사용됨&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;멀티미디어 스트리밍 애플리케이션&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;손실을 허용하고, 속도에 민감함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;DNS&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SNMP&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;checksum이란&#34; &gt;Checksum이란?
&lt;span&gt;
    &lt;a href=&#34;#checksum%ec%9d%b4%eb%9e%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;체크섬&lt;/code&gt;?
&lt;ul&gt;
&lt;li&gt;전송된 세그먼트에서 &lt;code&gt;에러&lt;/code&gt;(ex. &lt;code&gt;반전된 비트(flipped bits)&lt;/code&gt;)를 &lt;strong&gt;&lt;code&gt;감지&lt;/code&gt;&lt;/strong&gt; 하기 위해 사용되는 데이터 블록
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;헤더 필드를 포함한&lt;/em&gt; &lt;code&gt;세그먼트 내용&lt;/code&gt;을 &lt;code&gt;16 bit 정수 시퀀스&lt;/code&gt;로 분해한 뒤, 1의 보수로 합을 누적하여 구함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;tcp와-udp-중-어느-프로토콜이-checksum을-수행하는가&#34; &gt;TCP와 UDP 중 어느 프로토콜이 Checksum을 수행하는가?
&lt;span&gt;
    &lt;a href=&#34;#tcp%ec%99%80-udp-%ec%a4%91-%ec%96%b4%eb%8a%90-%ed%94%84%eb%a1%9c%ed%86%a0%ec%bd%9c%ec%9d%b4-checksum%ec%9d%84-%ec%88%98%ed%96%89%ed%95%98%eb%8a%94%ea%b0%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP&lt;/code&gt;, &lt;code&gt;UDP&lt;/code&gt; 모두 Checksum을 수행할 수 있다
&lt;ul&gt;
&lt;li&gt;다만, &lt;code&gt;UDP&lt;/code&gt;의 경우 &lt;em&gt;IPv4에서는 선택적&lt;/em&gt;이고 &lt;code&gt;IPv6&lt;/code&gt;에서는 &lt;code&gt;필수&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;checksum을-통해-오류를-정정할-수-있는가&#34; &gt;Checksum을 통해 오류를 정정할 수 있는가?
&lt;span&gt;
    &lt;a href=&#34;#checksum%ec%9d%84-%ed%86%b5%ed%95%b4-%ec%98%a4%eb%a5%98%eb%a5%bc-%ec%a0%95%ec%a0%95%ed%95%a0-%ec%88%98-%ec%9e%88%eb%8a%94%ea%b0%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;checksum을 이용한 &lt;code&gt;오류 정정&lt;/code&gt;은 &lt;strong&gt;불가능&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;단순히 &lt;code&gt;각 16비트 word들의 1의 보수 합&lt;/code&gt;이기 때문에 원래 값이 무엇이었는지 유추하기 힘듦&lt;/li&gt;
&lt;li&gt;따라서 &lt;code&gt;자동반복요청(ARQ)&lt;/code&gt; 기법을 사용하거나, &lt;code&gt;Hamming Code&lt;/code&gt;, &lt;code&gt;Reed–Solomon code&lt;/code&gt;등 &lt;code&gt;오류 정정 코드&lt;/code&gt;를 사용하는 &lt;code&gt;전진오류수정(FEC)&lt;/code&gt; 기법을 사용해 오류를 정정해야 함
&lt;ul&gt;
&lt;li&gt;이러한 기법들은 &lt;code&gt;데이터링크 계층&lt;/code&gt;에서 수행됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;tcp가-신뢰성을-보장하는-방법&#34; &gt;TCP가 신뢰성을 보장하는 방법
&lt;span&gt;
    &lt;a href=&#34;#tcp%ea%b0%80-%ec%8b%a0%eb%a2%b0%ec%84%b1%ec%9d%84-%eb%b3%b4%ec%9e%a5%ed%95%98%eb%8a%94-%eb%b0%a9%eb%b2%95&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP&lt;/code&gt;에서는 신뢰성을 보장하기 위해 다음과 같은 서비스 제공
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;파이프라인화된 세그먼트&lt;/code&gt; (연속으로 전송할 수 있음)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;누적 ACK&lt;/code&gt; (Go-Back-N과 유사)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;단일 재전송 타이머&lt;/code&gt; (데이터 보낸 시간 != timeout 시간 일 수 있어 타이머 사용)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;위 서비스를 통해 &lt;code&gt;비트 에러&lt;/code&gt;, &lt;code&gt;패킷 손실&lt;/code&gt;이 일어난 데이터를 감지하고 재전송을 요청함.&lt;/li&gt;
&lt;li&gt;이때, &lt;code&gt;재전송&lt;/code&gt;은 다음 두 경우 발생
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;timeout 이벤트&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;timeout이 발생한 경우, 이를 일으킨 세그먼트를 재전송&lt;/li&gt;
&lt;li&gt;타이머 재시작&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;중복된 ACK&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;이전에 ACK되지 않은 세그먼트를 ACK하는 경우&lt;/li&gt;
&lt;li&gt;무엇이 ACK되었다고 알려져있는지 갱신&lt;/li&gt;
&lt;li&gt;ACK되지 않은 세그먼트 아직 있으면 타이머 시작&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;tcp의-혼잡-제어-처리-방법&#34; &gt;TCP의 혼잡 제어 처리 방법
&lt;span&gt;
    &lt;a href=&#34;#tcp%ec%9d%98-%ed%98%bc%ec%9e%a1-%ec%a0%9c%ec%96%b4-%ec%b2%98%eb%a6%ac-%eb%b0%a9%eb%b2%95&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;TCP에서는 &lt;code&gt;혼잡 제어&lt;/code&gt;를 위해
&lt;code&gt;AIMD&lt;/code&gt;, &lt;code&gt;slow start&lt;/code&gt;, &lt;code&gt;conservative after timeout events&lt;/code&gt; 3가지 메커니즘 존재
&lt;ul&gt;
&lt;li&gt;발신자가 혼잡함을 인식하는 기준
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;손실 이벤트(loss event)&lt;/code&gt;: &lt;code&gt;타임아웃&lt;/code&gt; 또는 &lt;code&gt;3번&lt;/code&gt;의 &lt;code&gt;중복된 ACK&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;TCP 발신자는 &lt;code&gt;손실 이벤트&lt;/code&gt; 발생시, 혼잡에 대응하기 위해 &lt;code&gt;혼잡 윈도우(Congestion Window, CongWin)&lt;/code&gt;의 크기를 조절해 대응&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;aimd-1&#34; &gt;AIMD
&lt;span&gt;
    &lt;a href=&#34;#aimd-1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;p&gt;&lt;img src=&#34;AIMD.png&#34; alt=&#34;AIMD.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Additive Increase Multiplicative Decrease&lt;/code&gt;의 약어&lt;/li&gt;
&lt;li&gt;&lt;code&gt;혼잡 윈도우&lt;/code&gt;를 &lt;em&gt;혼잡이 감지되지 않을때&lt;/em&gt;는 &lt;code&gt;선형적으로 증가&lt;/code&gt;시키다, &lt;em&gt;혼잡이 감지되면&lt;/em&gt; &lt;code&gt;기하급수적으로 감소&lt;/code&gt;시키는 방식
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;손실이 감지될 때까지&lt;/em&gt;, 매 &lt;code&gt;RTT&lt;/code&gt;마다 &lt;code&gt;cwnd&lt;/code&gt;를 1 MSS씩 증가&lt;/li&gt;
&lt;li&gt;&lt;em&gt;손실이 발생하면&lt;/em&gt;, &lt;code&gt;cwnd&lt;/code&gt;를 절반으로 줄임&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;즉, &lt;code&gt;cwnd&lt;/code&gt;는 인식된 네트워크 혼잡 정도를 나타내는 함수라고 할 수 있음&lt;/li&gt;
&lt;li&gt;TCP 전송 속도 $rate \approx {cwnd \over RTT} bytes/sec$&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;slow-start-1&#34; &gt;Slow Start
&lt;span&gt;
    &lt;a href=&#34;#slow-start-1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;p&gt;&lt;img src=&#34;Slow-Start.png&#34; alt=&#34;Slow-Start.png&#34;&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;연결 시작 이후, &lt;code&gt;손실 이벤트&lt;/code&gt; 발생 전까지 속도를 기하급수적으로 증가시키는 방식
&lt;ul&gt;
&lt;li&gt;초기 &lt;code&gt;cwnd&lt;/code&gt; = 1 MSS&lt;/li&gt;
&lt;li&gt;매 RTT마다 &lt;code&gt;cwnd&lt;/code&gt;는 2배씩 증가
&lt;ul&gt;
&lt;li&gt;정확히는 모든 &lt;code&gt;ACK 수신&lt;/code&gt;마다 &lt;code&gt;cwnd&lt;/code&gt;를 2배로 증가시킴&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;시작 값이 1이라 &lt;code&gt;Slow Start&lt;/code&gt;라는 이름이 붙었으며, 증가 속도는 빠름&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h6 id=&#34;conservative-after-timeout-events타임아웃-발생-후-보수적으로-1&#34; &gt;Conservative after timeout events(타임아웃 발생 후 보수적으로)
&lt;span&gt;
    &lt;a href=&#34;#conservative-after-timeout-events%ed%83%80%ec%9e%84%ec%95%84%ec%9b%83-%eb%b0%9c%ec%83%9d-%ed%9b%84-%eb%b3%b4%ec%88%98%ec%a0%81%ec%9c%bc%eb%a1%9c-1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h6&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;타임아웃&lt;/code&gt;으로 손실을 인식
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cwnd&lt;/code&gt;는 1로 세팅됨&lt;/li&gt;
&lt;li&gt;이후 &lt;code&gt;cwnd&lt;/code&gt;가 기하급수적으로 &lt;code&gt;임계값(threshold)&lt;/code&gt;까지 증가한 뒤, &lt;code&gt;선형적&lt;/code&gt;으로 증가&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;3개의 중복 ACK&lt;/code&gt;로 손실을 인식 : &lt;code&gt;TCP RENO&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;중복 ACK&lt;/code&gt;는 네트워크가 아직 &lt;code&gt;세그먼트들을 전달할 수 있음&lt;/code&gt;을 나타냄&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cwnd&lt;/code&gt;를 &lt;code&gt;절반&lt;/code&gt;으로 줄인 뒤, &lt;code&gt;선형적&lt;/code&gt;으로 증가&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;타임아웃&lt;/code&gt; 또는 &lt;code&gt;3개의 중복 ACK&lt;/code&gt; 발생시 손실 인식 : &lt;code&gt;TCP Tahoe&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;인식시 &lt;code&gt;cwnd&lt;/code&gt;를 1로 설정&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;왜-http는-tcp를-사용하는가&#34; &gt;왜 HTTP는 TCP를 사용하는가?
&lt;span&gt;
    &lt;a href=&#34;#%ec%99%9c-http%eb%8a%94-tcp%eb%a5%bc-%ec%82%ac%ec%9a%a9%ed%95%98%eb%8a%94%ea%b0%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP&lt;/code&gt;가 &lt;strong&gt;&lt;code&gt;신뢰성&lt;/code&gt;&lt;/strong&gt; 을 제공하기 때문
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HTTP&lt;/code&gt;는 &lt;code&gt;신뢰할 수 있는 전송(reliable transport)&lt;/code&gt;을 전제로하는 프로토콜임&lt;/li&gt;
&lt;li&gt;따라서 이를 기본적으로 제공하는 &lt;code&gt;TCP&lt;/code&gt;를 선택
&lt;ul&gt;
&lt;li&gt;만약 &lt;code&gt;신뢰성&lt;/code&gt;이 제공되지 않아 패킷들의 순서가 뒤죽박죽이 되거나, 누락될 경우 웹사이트를 이루는 요소들이 올바르게 배치되지 않거나 텍스트, 이미지 등의 정보가 누락될 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;왜-http3-에서는-udp를-사용하는가&#34; &gt;왜 HTTP/3 에서는 UDP를 사용하는가?
&lt;span&gt;
    &lt;a href=&#34;#%ec%99%9c-http3-%ec%97%90%ec%84%9c%eb%8a%94-udp%eb%a5%bc-%ec%82%ac%ec%9a%a9%ed%95%98%eb%8a%94%ea%b0%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HTTP/3&lt;/code&gt;는 &lt;code&gt;TCP의 고질적인 문제점&lt;/code&gt;을 해결하고자 &lt;code&gt;UDP&lt;/code&gt;를 채용
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP&lt;/code&gt;로 인해 발생하는 문제
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HOL Blocking&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;TCP의 신뢰성때문에, 한 스트림에서 데이터 손실 발생시, 다른 데이터 스트림들은 손실된 데이터 재전송될 때까지 차단됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;연결 설정&lt;/code&gt;으로 인한 &lt;code&gt;지연&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;TCP가 연결 설정할 때 거치는 &lt;code&gt;3-way handshake&lt;/code&gt; 과정과 보안을 위한 &lt;code&gt;TLS Handshake&lt;/code&gt; 때문에 두 번의 지연 발생
&lt;ul&gt;
&lt;li&gt;반면 UDP(정확히는 &lt;code&gt;QUIC&lt;/code&gt;)는 최초 연결 설정시 &lt;code&gt;연결에 필요한 정보&lt;/code&gt; + &lt;code&gt;데이터&lt;/code&gt;를 함께 전송해 1-RTT로 지연을 줄임&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;패킷 &lt;code&gt;암호화 불가능&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP 프로토콜 헤더&lt;/code&gt;는 암호화 및 인증되지 않아, 중개자에 의한 변조/인젝션/도청에 취약
&lt;ul&gt;
&lt;li&gt;반면 &lt;code&gt;QUIC&lt;/code&gt;은 &lt;em&gt;일부 메시지를 제외한&lt;/em&gt; &lt;code&gt;모든 패킷 헤더&lt;/code&gt;와 &lt;code&gt;메시지 본문&lt;/code&gt;이 암호화 됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;연결 요소 변경시 연결 재설정
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;TCP&lt;/code&gt; 연결은 &lt;code&gt;출발지 IP&lt;/code&gt;, &lt;code&gt;출발지 포트&lt;/code&gt;, &lt;code&gt;도착지 IP&lt;/code&gt;, &lt;code&gt;도착지 포트&lt;/code&gt; 4가지를 기반
&lt;ul&gt;
&lt;li&gt;하나라도 변경될 경우 연결 다시 설정해야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;반면 &lt;code&gt;QUIC&lt;/code&gt;은 &lt;code&gt;연결 ID&lt;/code&gt;를 기반으로해, 이 값이 변경되지 않는 이상 연결 계속 유지&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;브라우저는-어떤-서버가-tcp를-쓰는지-udp를-쓰는지-어떻게-알-수-있는가&#34; &gt;브라우저는 어떤 서버가 TCP를 쓰는지 UDP를 쓰는지 어떻게 알 수 있는가?
&lt;span&gt;
    &lt;a href=&#34;#%eb%b8%8c%eb%9d%bc%ec%9a%b0%ec%a0%80%eb%8a%94-%ec%96%b4%eb%96%a4-%ec%84%9c%eb%b2%84%ea%b0%80-tcp%eb%a5%bc-%ec%93%b0%eb%8a%94%ec%a7%80-udp%eb%a5%bc-%ec%93%b0%eb%8a%94%ec%a7%80-%ec%96%b4%eb%96%bb%ea%b2%8c-%ec%95%8c-%ec%88%98-%ec%9e%88%eb%8a%94%ea%b0%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;연결 시도 과정&lt;/code&gt;에서 알 수 있음
&lt;ul&gt;
&lt;li&gt;먼저 브라우저는 &lt;code&gt;TCP&lt;/code&gt;로 &lt;code&gt;443&lt;/code&gt;번(&lt;code&gt;HTTPS&lt;/code&gt;), 또는 &lt;code&gt;80&lt;/code&gt;번(&lt;code&gt;HTTP&lt;/code&gt;) 포트로 연결 시도
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HTTP/1.1&lt;/code&gt; 또는 &lt;code&gt;HTTP/2&lt;/code&gt;로 연결을 설정하기 위함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;만약 서버가 &lt;code&gt;HTTP/3&lt;/code&gt;를 지원하는 경우, &lt;code&gt;h3&lt;/code&gt; ALPN 토큰을 사용해 &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Alt-Svc#example&#34;&gt;&lt;code&gt;Alt-Svc&lt;/code&gt; HTTP 응답 헤더 필드&lt;/a&gt;를 사용하거나, &lt;code&gt;HTTP/2 ALTSVC 프레임&lt;/code&gt;을 통해 동등한 &lt;code&gt;HTTP/3&lt;/code&gt; 엔드포인트를 지원함을 알림
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Alt-Svc&lt;/code&gt; : 향후 요청에 대해 &lt;code&gt;다른 네트워크 위치(대체 서비스)&lt;/code&gt;역시 현재 요청의 오리진처럼 정당한 응답을 받을 수 있음을 알림.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Alt-Svc&lt;/code&gt; 필드의 값을 활용해 &lt;code&gt;h3&lt;/code&gt; 키에 해당하는 값의 UDP 포트로 연결 시도
&lt;ul&gt;
&lt;li&gt;만약 &lt;code&gt;h3=&amp;quot;:443&amp;quot;&lt;/code&gt;인 경우, UDP 443 포트로 &lt;code&gt;QUIC&lt;/code&gt; 연결 시도&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;참고&#34; &gt;참고
&lt;span&gt;
    &lt;a href=&#34;#%ec%b0%b8%ea%b3%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;전공 강의 자료
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;Computer Networking: A Top Down Approach - 7th Edition&amp;rdquo;, Jim Kurose, Keith RossPearson. April 2016&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://ocw.snu.ac.kr/sites/default/files/NOTE/W6.Transport_Layer.pdf&#34;&gt;W6.Transport_Layer.pdf - SNU&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.ietf.org/rfc/rfc793.txt&#34;&gt;TRANSMISSION CONTROL PROTOCOL - ietf.org/rfc/rfc793.txt&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc9293#name-header-format&#34;&gt;RFC 9293 - Transmission Control Protocol (TCP)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://coursys.sfu.ca/2022fa-cmpt-471-d1/pages/Prj2/view&#34;&gt;Reliable Data Transfer over UDP - Simon Fraser University&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7838&#34;&gt;RFC 7838 - HTTP Alternative Services&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.ktword.co.kr/test/view/view.php?no=2437&#34;&gt;TCP 제어 플래그 - ktworld&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.ktword.co.kr/test/view/view.php?no=1889&#34;&gt;TCP Header- ktworld&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.ktword.co.kr/test/view/view.php?no=5536&#34;&gt;TCP 혼잡제어 - ktworld&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://os.korea.ac.kr/wp-content/uploads/2020/11/10_TCP-in-Linux.pdf&#34;&gt;Fall ’20 COSE322-00  System Programming  TCP in Linux - korea univ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.slashroot.in/how-is-tcp-and-udp-checksum-calculated&#34;&gt;How is TCP &amp;amp; UDP Checksum Calculated?&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://www.tcpipguide.com/free/t_TCPChecksumCalculationandtheTCPPseudoHeader-2.htm&#34;&gt;The TCP/IP Guide - TCP Checksum Calculation and the TCP &amp;ldquo;Pseudo Header&amp;rdquo;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>[Network] JWT 알아보기 (w. JWE, JWS)</title>
      <link>https://cloudsoswift.github.io/post/develop/network/jwt/</link>
      <pubDate>Thu, 10 Oct 2024 16:46:55 +0900</pubDate>
      
      <guid>https://cloudsoswift.github.io/post/develop/network/jwt/</guid>
      <description>&lt;h1 id=&#34;서론&#34; &gt;서론
&lt;span&gt;
    &lt;a href=&#34;#%ec%84%9c%eb%a1%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;p&gt;&lt;a href=&#34;https://github.com/orm712/CS-712&#34;&gt;CS 스터디&lt;/a&gt;에서 10월 8일 발표한 &lt;a href=&#34;https://github.com/orm712/CS-712/blob/main/05-ETC/13_JWT/Readme.md&#34;&gt;&lt;strong&gt;JWT&lt;/strong&gt;&lt;/a&gt;에 대해 정리한 문서를 블로그에 공유하고자 한다.&lt;/p&gt;
&lt;h2 id=&#34;jwt-인증-방식이-무엇인가요&#34; &gt;JWT 인증 방식이 무엇인가요?
&lt;span&gt;
    &lt;a href=&#34;#jwt-%ec%9d%b8%ec%a6%9d-%eb%b0%a9%ec%8b%9d%ec%9d%b4-%eb%ac%b4%ec%97%87%ec%9d%b8%ea%b0%80%ec%9a%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;&lt;code&gt;JWT 인증 방식&lt;/code&gt;이란, &lt;em&gt;두 당사자 간 전송할 &lt;code&gt;클레임(claim)&lt;/code&gt;&lt;/em&gt; 을 나타내는 &lt;code&gt;JWT(JSON 웹 토큰)&lt;/code&gt;을 통해 사용자를 &lt;code&gt;인증&lt;/code&gt;하는 방식을 말합니다.&lt;br&gt;
&lt;code&gt;JWT&lt;/code&gt;는 공간이 제약된 환경, 예를 들어 &lt;code&gt;HTTP Authorization 헤더&lt;/code&gt;, &lt;code&gt;URI 쿼리 매개변수&lt;/code&gt;와 같은 환경에서 &lt;code&gt;클레임들&lt;/code&gt;을 주고 받을 수 있도록 &lt;code&gt;간결화&lt;/code&gt;하는 것이 목적입니다.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;클레임&lt;/code&gt;: &lt;code&gt;키-값 쌍&lt;/code&gt;으로 이뤄진 데이터&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;jwt&#34; &gt;JWT?
&lt;span&gt;
    &lt;a href=&#34;#jwt&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;&lt;code&gt;JWT(JSON Web Token)&lt;/code&gt;는 당사자 간 정보를 &lt;code&gt;JSON 객체&lt;/code&gt;로 안전하게 전송하기 위한 간결하고 독립적인 방법을 정의하는 개방형 표준(&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7519&#34;&gt;RFC 7519&lt;/a&gt;)입니다.&lt;br&gt;
&lt;code&gt;JWT&lt;/code&gt;는 &lt;code&gt;정보(클레임 집합)&lt;/code&gt;를 &lt;code&gt;선택적 서명(JWS 구조로 인코딩)/암호화(JWE 구조로 인코딩)&lt;/code&gt;한 &lt;code&gt;JSON 객체&lt;/code&gt;라고 할 수 있으며, 이 &lt;code&gt;JSON 객체&lt;/code&gt;는 &lt;code&gt;0개 이상의 클레임&lt;/code&gt;을 가질 수 있습니다.&lt;br&gt;
&lt;img src=&#34;JWT-workflow.png&#34; alt=&#34;JWT-workflow.png&#34;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;출처: &lt;a href=&#34;https://www.freecodecamp.org/news/how-to-sign-and-validate-json-web-tokens/&#34;&gt;How to Sign and Validate JSON Web Tokens – JWT Tutorial (freecodecamp.org)&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;주로 인증 과정에서 사용자가 자격 증명을 통해 로그인에 성공하면 JWT가 반환되며, 사용자가 &lt;code&gt;보호된 경로/리소스&lt;/code&gt;에 접근할 경우 &lt;code&gt;Bearer&lt;/code&gt; 스키마를 통해 &lt;code&gt;Authorization&lt;/code&gt; 헤더에 JWT를 첨부해 요청해야 합니다.&lt;br&gt;
즉, 다음과 같은 형태를 띄어야 합니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Authorization: Bearer &amp;lt;token&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&#34;jwejson-web-encryption-rfc-7516httpsdatatrackerietforgdochtmlrfc7516&#34; &gt;JWE(JSON Web Encryption) &lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7516&#34;&gt;RFC 7516&lt;/a&gt;
&lt;span&gt;
    &lt;a href=&#34;#jwejson-web-encryption-rfc-7516httpsdatatrackerietforgdochtmlrfc7516&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;JWE.png&#34; alt=&#34;JWE.png&#34;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;출처: &lt;a href=&#34;https://dzone.com/articles/using-json-web-encryption-jwe&#34;&gt;Using JSON Web Encryption (JWE) - DZone&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;JWT 내용을 디지털 방식으로 암호화 함.
&lt;ul&gt;
&lt;li&gt;따라서 &lt;code&gt;무결성 검증&lt;/code&gt; 및 &lt;code&gt;콘텐츠 보호&lt;/code&gt;에 사용할 수 있음.&lt;/li&gt;
&lt;li&gt;또한 &lt;code&gt;인증된 암호화(AUtehmticated Encryption)&lt;/code&gt;를 통해 평문의 &lt;code&gt;기밀성&lt;/code&gt;과 &lt;code&gt;무결성&lt;/code&gt;, &lt;code&gt;JWE 보호 헤더(JWE Protected Header)&lt;/code&gt;의 &lt;code&gt;무결성&lt;/code&gt;을 보장.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;본질적으로 콘텐츠를 암호화 하므로, `HTTP 상에서 사용할 수 있음.&lt;/li&gt;
&lt;li&gt;일반적인 구조&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;lt;Base64URL 인코딩 된 UTF8 인코딩 형태의 JWE Protected Header&amp;gt;.&amp;lt;Base64URL 인코딩 된 JWE Encrypted Key&amp;gt;.&amp;lt;Base64URL 인코딩 된 JWE Initialization Vector&amp;gt;.&amp;lt;Base64URL 인코딩 된 JWE Ciphertext&amp;gt;.&amp;lt;Base64URL 인코딩 된 JWE Authentication Tag&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;과정
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;JWT Protected Header&lt;/code&gt;를 선언한다.
&lt;ul&gt;
&lt;li&gt;헤더는 다음 두 가지를 갖고있다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;alg&lt;/code&gt;: &lt;code&gt;콘텐츠 암호화 키(Content Encryption Key)&lt;/code&gt;를 어떤 알고리즘을 사용해 암호화할지 나타냄.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;enc&lt;/code&gt;: 어떤 알고리즘을 사용해 &lt;code&gt;인증된 암호화(AUtehmticated Encryption)&lt;/code&gt;를 수행할지 지 나타냄.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;인증된 암호화&lt;/code&gt;는 평문에 대해 수행되어, &lt;code&gt;암호화된 텍스트(ciphertext)&lt;/code&gt;와 &lt;code&gt;인증 태그(Authentication Tag)&lt;/code&gt;를 생성함.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;이후 이를 &lt;code&gt;UTF-8&lt;/code&gt;로 인코딩 한 뒤, &lt;code&gt;Base64URL&lt;/code&gt;로 인코딩 한다.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;랜덤한 &lt;code&gt;CEK(콘텐츠 암호화 키)&lt;/code&gt;를 생성한다.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;CEK&lt;/code&gt;를 &lt;code&gt;RSAES-OAEP&lt;/code&gt; 알고리즘을 사용해 수신자의 &lt;code&gt;공개키&lt;/code&gt;로 암호화하여, &lt;code&gt;JWE Encrypted Key&lt;/code&gt;를 생성한 뒤, &lt;code&gt;Base64URL&lt;/code&gt; 인코딩을 수행한다.&lt;/li&gt;
&lt;li&gt;랜덤한 &lt;code&gt;JWE Initialization Vector&lt;/code&gt;를 생성한 뒤, Base64URL 인코딩을 수행한다.&lt;/li&gt;
&lt;li&gt;평문에 &lt;code&gt;AES GCM&lt;/code&gt; 알고리즘을 사용해 &lt;code&gt;인증된 암호화&lt;/code&gt;를 수행한다.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;CEK&lt;/code&gt;를 &lt;code&gt;암호화 키&lt;/code&gt;로 사용하며, 추가로 &lt;code&gt;JWE Initialization Vector&lt;/code&gt;, &lt;code&gt;AAD&lt;/code&gt; 역시 사용한다.&lt;/li&gt;
&lt;li&gt;이를 통해 &lt;code&gt;Ciphertext(암호문)&lt;/code&gt;와 128비트 &lt;code&gt;JWE Authentication Tag&lt;/code&gt;를 만들어내고, 이들에 대해 Base64URL 인코딩을 수행한다.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;jwsjson-web-signature-rfc-7515httpsdatatrackerietforgdochtmlrfc7515&#34; &gt;JWS(JSON Web Signature) &lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7515&#34;&gt;RFC 7515&lt;/a&gt;
&lt;span&gt;
    &lt;a href=&#34;#jwsjson-web-signature-rfc-7515httpsdatatrackerietforgdochtmlrfc7515&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;JWT.png&#34; alt=&#34;JWT.png&#34;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;출처: &lt;a href=&#34;https://fusionauth.io/articles/tokens/jwt-components-explained&#34;&gt;Components of JWTs Explained (fusionauth.io)&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;ul&gt;
&lt;li&gt;디지털 서명을 통해 발신자-수신자 간 전송되는 JWT 내용이 &lt;code&gt;변조되지 않음&lt;/code&gt;을 &lt;code&gt;보장&lt;/code&gt;하는 &lt;code&gt;JWT&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;일반적으로 &lt;code&gt;JWT 인증&lt;/code&gt;에 사용되는 형태는 &lt;code&gt;JWS&lt;/code&gt;라고 할 수 있음&lt;/li&gt;
&lt;li&gt;특징
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;내용(클레임)&lt;/code&gt;은 타인도 읽을 수 있음.
&lt;ul&gt;
&lt;li&gt;따라서 비밀번호와 같은 &lt;code&gt;민감 데이터&lt;/code&gt;를 &lt;code&gt;전송하는데 사용해서는 안 됨&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;본질적으로 타인이 데이터를 읽는 것을 방지하지 않으므로, &lt;code&gt;HTTPS&lt;/code&gt; 또는 &lt;code&gt;SSL&lt;/code&gt;를 통해 전송됨.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;비밀(secret)&lt;/code&gt;(&lt;code&gt;HMAC&lt;/code&gt; 알고리즘) 또는 &lt;code&gt;공개-개인 키 쌍&lt;/code&gt;(&lt;code&gt;RSA&lt;/code&gt;, &lt;code&gt;ECDSA&lt;/code&gt; 알고리즘)을 사용해 &lt;code&gt;서명&lt;/code&gt;할 수 있음.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;일반적인 구조&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;lt;Base64URL 인코딩된 헤더&amp;gt;.&amp;lt;Base64URL 인코딩된 페이로드&amp;gt;.&amp;lt;Base64URL 인코딩된 시그니처&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&#34;jwt의-구조&#34; &gt;JWT의 구조
&lt;span&gt;
    &lt;a href=&#34;#jwt%ec%9d%98-%ea%b5%ac%ec%a1%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;&lt;code&gt;JWT&lt;/code&gt;는 점(&lt;code&gt;.&lt;/code&gt;)으로 구분된 &lt;code&gt;세 가지 부분&lt;/code&gt;으로 &lt;code&gt;구성&lt;/code&gt;되어 있음
즉, &lt;code&gt;&amp;lt;header&amp;gt;.&amp;lt;payload&amp;gt;.&amp;lt;signature&amp;gt;&lt;/code&gt;와 같은 형태&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;header&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;일반적으로 두 부분을 갖는 &lt;code&gt;JSON 객체&lt;/code&gt;로, Base64URL 인코딩을 거쳐 JWT의 첫 번째 부분을 맡음.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;typ&lt;/code&gt;: 토큰의 &lt;code&gt;유형&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;alg&lt;/code&gt;: 사용된 &lt;code&gt;서명 알고리즘&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Payload&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;0개 이상의 &lt;code&gt;클레임&lt;/code&gt;을 포함하는 JSON 객체로, &lt;code&gt;엔티티&lt;/code&gt;(주로 &lt;code&gt;사용자&lt;/code&gt;)와 추가적인 데이터로 이뤄짐.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;클레임&lt;/code&gt;은 &lt;code&gt;registered&lt;/code&gt;, &lt;code&gt;public&lt;/code&gt;, &lt;code&gt;private&lt;/code&gt; 세 가지 종류가 있음.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;registered&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;미리 정의된&lt;/strong&gt; &lt;code&gt;클레임 셋&lt;/code&gt;으로, 필수는 아니지만 권장되는 사항으로 유용하며 상호 운용 가능함.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;iss&lt;/code&gt;(issuer): JWT를 &lt;code&gt;발급한 주체&lt;/code&gt;를 식별&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sub&lt;/code&gt;(subject): JWT의 주제가 되는 &lt;code&gt;주체(인증가능한 엔티티)&lt;/code&gt;.
&lt;ul&gt;
&lt;li&gt;JWT의 클레임은 일반적으로 &lt;code&gt;subject&lt;/code&gt;에 대한 진술임.&lt;/li&gt;
&lt;li&gt;또한, 발행자의 컨텍스트상에서 또는 전역적으로 &lt;code&gt;subject&lt;/code&gt;는 고유해야함.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;aud&lt;/code&gt;(Audience): JWT가 &lt;code&gt;의도하는 수신자&lt;/code&gt;를 식별
&lt;ul&gt;
&lt;li&gt;즉, JWT를 처리하는 각 주체들은 &lt;code&gt;aud&lt;/code&gt; 클레임 값으로 자신을 식별해야 함.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;exp&lt;/code&gt;(expiration time): JWT 처리가 허용되어서는 안되는 &lt;code&gt;만료 시간(또는 그 이후)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;nbf&lt;/code&gt;(not before): JWT 처리가 허용되어서는 안되는 &lt;code&gt;이전 시간&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;iat&lt;/code&gt;(issued at): JWT가 &lt;code&gt;발행된 시점&lt;/code&gt;을 식별&lt;/li&gt;
&lt;li&gt;&lt;code&gt;jti&lt;/code&gt;(jwt id): JWT의 &lt;code&gt;고유 식별자&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;public&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;JWT를 &lt;code&gt;사용하는 측&lt;/code&gt;에서 &lt;code&gt;마음대로 정의&lt;/code&gt;할 수 있음&lt;/li&gt;
&lt;li&gt;다만 충돌 방지를 위해선 &lt;code&gt;IANA JSON Web Token Registry&lt;/code&gt;에 정의되어 있거나, &lt;code&gt;충돌 방지 네임스페이스가 포함된 URI&lt;/code&gt;로 정의해야 함.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;private&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;사용자 지정 클레임&lt;/code&gt;으로, 사용에 동의한 당사자 간에 정보 공유하기 위해 만듦&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;signature&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;Base64 인코딩된 &lt;code&gt;헤더&lt;/code&gt;, &lt;code&gt;페이로드&lt;/code&gt;, &lt;code&gt;비밀&lt;/code&gt;을 가져와 &lt;code&gt;헤더에 지정된 알고리즘&lt;/code&gt;으로 &lt;code&gt;서명&lt;/code&gt;한 값
&lt;ul&gt;
&lt;li&gt;예를 들어, &lt;code&gt;HMAC SHA256&lt;/code&gt; 알고리즘으로 서명하는 경우 다음과 같음
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HMACSHA256(base64UrlEncode(header) + &amp;quot;.&amp;quot; + base64UrlEncode(payload), secret)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;서명&lt;/code&gt;은 메시지가 &lt;code&gt;도중에 변경되진 않았는지 확인&lt;/code&gt;하는데 사용
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;개인 키로 서명된 토큰&lt;/code&gt;은 JWT 발신자가 &lt;code&gt;본인이 맞는지 확인&lt;/code&gt;할 수도 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;jwt의-장점&#34; &gt;JWT의 장점
&lt;span&gt;
    &lt;a href=&#34;#jwt%ec%9d%98-%ec%9e%a5%ec%a0%90&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;&lt;code&gt;SSO&lt;/code&gt;와 같은 시스템에서 주로 사용되는 또 다른 인증 포맷인 &lt;code&gt;SAML 토큰&lt;/code&gt; 대비&lt;/p&gt;
&lt;h4 id=&#34;더-간결하다&#34; &gt;더 간결하다
&lt;span&gt;
    &lt;a href=&#34;#%eb%8d%94-%ea%b0%84%ea%b2%b0%ed%95%98%eb%8b%a4&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;JSON&lt;/code&gt;은 &lt;code&gt;XML&lt;/code&gt;보다 장황하지 않아 웬만한 경우 &lt;code&gt;JWT&lt;/code&gt;가 &lt;code&gt;SAML 토큰&lt;/code&gt;보다 작음.
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;SAML(Security Assertion Markup Language)&lt;/code&gt;: &lt;code&gt;SSO&lt;/code&gt;와 같은 인증 방식에서 사용되는 포맷으로, XML을 기반으로 &lt;code&gt;인증 대상자가 누구인지&lt;/code&gt; 알려주는 표준화된 방법
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.okta.com/kr/blog/2020/09/what-is-saml/&#34;&gt;SAML | Okta Identity Korea&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.cloudflare.com/ko-kr/learning/access-management/what-is-saml/&#34;&gt;SAML이란? | SAML 인증이 작동하는 방식 | Cloudflare&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;따라서 &lt;code&gt;HTML&lt;/code&gt; 및 &lt;code&gt;HTTP&lt;/code&gt;환경에서 전달하기 용이함&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;더-안전하다&#34; &gt;더 안전하다
&lt;span&gt;
    &lt;a href=&#34;#%eb%8d%94-%ec%95%88%ec%a0%84%ed%95%98%eb%8b%a4&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;JWT는 서명을 위해 &lt;code&gt;X.509 인증서&lt;/code&gt; 형식의 &lt;code&gt;공개-개인키 쌍&lt;/code&gt;을 사용하거나, &lt;code&gt;HMAC 알고리즘&lt;/code&gt;을 사용해 &lt;code&gt;공유된 비밀&lt;/code&gt;로 대칭적 서명이 가능&lt;/li&gt;
&lt;li&gt;&lt;code&gt;SAML 토큰&lt;/code&gt;은 JWT와 같이 &lt;code&gt;공개-개인키 쌍&lt;/code&gt;을 사용할 수 있지만, 취약점없이 &lt;code&gt;XML 디지털 서명&lt;/code&gt;을 통해 XML에 서명하는것은 &lt;code&gt;JSON 서명&lt;/code&gt;의 &lt;strong&gt;&lt;code&gt;단순성&lt;/code&gt;&lt;/strong&gt; 에 비하면 매우 어려움&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;더-대중적이다&#34; &gt;더 대중적이다
&lt;span&gt;
    &lt;a href=&#34;#%eb%8d%94-%eb%8c%80%ec%a4%91%ec%a0%81%ec%9d%b4%eb%8b%a4&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;JSON parser&lt;/code&gt;는 &lt;code&gt;JSON&lt;/code&gt;이 객체에 직접 매핑되므로 대부분의 프로그래밍 언어에서 &lt;code&gt;일반적&lt;/code&gt;임&lt;/li&gt;
&lt;li&gt;반면 &lt;code&gt;XML&lt;/code&gt;은 자연스러운 &lt;code&gt;문서-to-객체&lt;/code&gt; 매핑이 없음
&lt;ul&gt;
&lt;li&gt;따라서 &lt;code&gt;SAML assertion&lt;/code&gt; 대비 작업이 더 쉬움&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;signature는-어떻게-만들어지나요&#34; &gt;Signature는 어떻게 만들어지나요?
&lt;span&gt;
    &lt;a href=&#34;#signature%eb%8a%94-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%a7%8c%eb%93%a4%ec%96%b4%ec%a7%80%eb%82%98%ec%9a%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;Base64 인코딩된 &lt;code&gt;헤더&lt;/code&gt;, &lt;code&gt;페이로드&lt;/code&gt;, &lt;code&gt;비밀&lt;/code&gt;을 가져와 &lt;code&gt;헤더에 지정된 알고리즘&lt;/code&gt;으로 &lt;code&gt;signature&lt;/code&gt;를 만듦
&lt;ul&gt;
&lt;li&gt;예를 들어, &lt;code&gt;HMAC SHA256&lt;/code&gt; 알고리즘으로 서명하는 경우 다음과 같음
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;HMACSHA256(base64UrlEncode(header) + &amp;quot;.&amp;quot; + base64UrlEncode(payload), secret)&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;만약-access-token이-탈취되면-어떻게-대응할-수-있을까요--반대로-refresh-token이-탈취되면-어떻게-대응해야-할까요&#34; &gt;만약 Access Token이 탈취되면, 어떻게 대응할 수 있을까요? / 반대로 Refresh Token이 탈취되면, 어떻게 대응해야 할까요?
&lt;span&gt;
    &lt;a href=&#34;#%eb%a7%8c%ec%95%bd-access-token%ec%9d%b4-%ed%83%88%ec%b7%a8%eb%90%98%eb%a9%b4-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%8c%80%ec%9d%91%ed%95%a0-%ec%88%98-%ec%9e%88%ec%9d%84%ea%b9%8c%ec%9a%94--%eb%b0%98%eb%8c%80%eb%a1%9c-refresh-token%ec%9d%b4-%ed%83%88%ec%b7%a8%eb%90%98%eb%a9%b4-%ec%96%b4%eb%96%bb%ea%b2%8c-%eb%8c%80%ec%9d%91%ed%95%b4%ec%95%bc-%ed%95%a0%ea%b9%8c%ec%9a%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;토큰이 탈취 당한 경우, 아래와 같은 방법들을 통해 &lt;code&gt;토큰을 무효화&lt;/code&gt;해야합니다.&lt;/p&gt;
&lt;h3 id=&#34;토큰-블랙리스트&#34; &gt;토큰 블랙리스트
&lt;span&gt;
    &lt;a href=&#34;#%ed%86%a0%ed%81%b0-%eb%b8%94%eb%9e%99%eb%a6%ac%ec%8a%a4%ed%8a%b8&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;유효하지 않은 것으로 간주되어야 할 토큰의 &lt;code&gt;jti&lt;/code&gt; 클레임, 또는 &lt;code&gt;사용자 id&lt;/code&gt;와 같은 &lt;code&gt;식별자&lt;/code&gt;를 &lt;code&gt;서버측 블랙리스트&lt;/code&gt;에서 관리하는 방법&lt;/li&gt;
&lt;li&gt;API 엔드포인트에 토큰이 제시되면, 서버는 블랙리스트에 포함되었는지 확인&lt;/li&gt;
&lt;li&gt;블랙리스트는 주로 &lt;code&gt;Redis&lt;/code&gt;와 같이 접근 속도가 빠른 &lt;code&gt;인-메모리 저장소&lt;/code&gt;에 저장하거나,  &lt;code&gt;DB&lt;/code&gt;에 저장&lt;/li&gt;
&lt;li&gt;장점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;세분화된 제어&lt;/code&gt;: 다른 토큰들에 영향 없이 특정 토큰만 무효화 할 수 있음&lt;/li&gt;
&lt;li&gt;&lt;code&gt;호환성&lt;/code&gt;: 다양한 백엔드 환경에서 사용 가능함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;단점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;확장성&lt;/code&gt;: 블랙리스트에 포함된 &lt;code&gt;토큰 수가 증가&lt;/code&gt;하면 &lt;code&gt;블랙리스트 조회 성능이 저하&lt;/code&gt;될 수 있음&lt;/li&gt;
&lt;li&gt;&lt;code&gt;서비스가 Stateful해짐&lt;/code&gt;: 블랙리스트를 계속 유지한다는 것은, &lt;code&gt;상태를 계속 유지&lt;/code&gt;한다는 것과 사실상 동일. 이는 &lt;code&gt;JWT&lt;/code&gt;의 &lt;code&gt;Stateless&lt;/code&gt;한 특성과 상충됨&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;짧은-토큰-수명&#34; &gt;짧은 토큰 수명
&lt;span&gt;
    &lt;a href=&#34;#%ec%a7%a7%ec%9d%80-%ed%86%a0%ed%81%b0-%ec%88%98%eb%aa%85&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;토큰의 수명(&lt;code&gt;exp&lt;/code&gt;)을 &lt;code&gt;매우 짧게 설정&lt;/code&gt;해, 공격자가 액세스 토큰을 탈취해도 많이 사용할 수 없음.&lt;/li&gt;
&lt;li&gt;이는 공격자가 &lt;code&gt;리프레시 토큰&lt;/code&gt;은 탈취하지 못한 경우 매우 유용&lt;/li&gt;
&lt;li&gt;장점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;노출 감소&lt;/code&gt;: 토큰이 탈취되어도 &lt;code&gt;공격에 노출되는 시간이 최소화&lt;/code&gt;됨&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Stateless 유지&lt;/code&gt;: 별도의 &lt;code&gt;서버 측 저장소가 필요하지 않음&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;단점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;사용자 경험&lt;/code&gt;: 사용자가 &lt;code&gt;더 자주 인증&lt;/code&gt;해야 함&lt;/li&gt;
&lt;li&gt;&lt;code&gt;즉각적인 해지 불가능&lt;/code&gt;: 탈취당해도 해당 토큰이 &lt;code&gt;수명에 다다르길 기다려야 함&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;비밀-로테이션&#34; &gt;비밀 로테이션
&lt;span&gt;
    &lt;a href=&#34;#%eb%b9%84%eb%b0%80-%eb%a1%9c%ed%85%8c%ec%9d%b4%ec%85%98&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;JWT&lt;/code&gt; 서명에 사용되는 &lt;code&gt;비밀(secret) 키&lt;/code&gt;를 주기적으로 교체하면, 이전 &lt;code&gt;비밀 키&lt;/code&gt;로 서명된 &lt;code&gt;모든 기존 토큰들을 무효화&lt;/code&gt; 할 수 있음
&lt;ul&gt;
&lt;li&gt;이는 보안 사고가 발생했거나, 인증 전략을 변경한 뒤 &lt;code&gt;많은 수의 토큰&lt;/code&gt;을 &lt;code&gt;동시에 해지&lt;/code&gt;해야할 때 특히 유용&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;장점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;매우 안전&lt;/code&gt;: 정기적으로 로테이션되는 &lt;code&gt;비밀&lt;/code&gt;은 보안 계층을 추가하는 셈&lt;/li&gt;
&lt;li&gt;&lt;code&gt;광범위한 영향&lt;/code&gt;: 기존의 모든 토큰들을 &lt;code&gt;한 번에 무효화 해야하는 케이스&lt;/code&gt;에 매우 효과적&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;단점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;복잡한 키 관리&lt;/code&gt;: 실수로 &lt;code&gt;합법적인 토큰&lt;/code&gt;을 무효화하지 않도록 신중한 관리가 필요&lt;/li&gt;
&lt;li&gt;&lt;code&gt;토큰 재생성&lt;/code&gt;: &lt;code&gt;비밀 로테이션&lt;/code&gt; 이후 클라이언트는 새로운 JWT를 획득해야 해 클라이언트-백엔드 간 &lt;code&gt;상호 작용 복잡&lt;/code&gt;하게 만들 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;토큰-버전-관리&#34; &gt;토큰 버전 관리
&lt;span&gt;
    &lt;a href=&#34;#%ed%86%a0%ed%81%b0-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;발행된 각 &lt;code&gt;JWT&lt;/code&gt;에 &lt;code&gt;버전 번호&lt;/code&gt;를 할당한 뒤, 사용자의 계정 정보와 함께 &lt;code&gt;DB에 저장&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;만약 토큰을 무효화해야 할 경우, &lt;code&gt;DB&lt;/code&gt;의 &lt;code&gt;버전 번호를 증가&lt;/code&gt;시켜 &lt;code&gt;이전 토큰들을 무효화&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;증가된 이후, 사용자가 인증을 시도할 경우 &lt;code&gt;업데이트된 버전이 포함된 토큰&lt;/code&gt;을 제시해야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;장점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;선택적 무효화&lt;/code&gt;: 사용자의 계정 상태나 기타 기준에 따라 &lt;code&gt;특정 대상만 무효화&lt;/code&gt; 할 수 있음&lt;/li&gt;
&lt;li&gt;&lt;code&gt;호환성&lt;/code&gt;: 다양한 신원 제공자 및 인증 시스템과 &lt;code&gt;함께 사용&lt;/code&gt;될 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;단점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;복잡성 증가&lt;/code&gt;: 토큰 버전 역시 검증해야 하므로 &lt;code&gt;추가적인 로직&lt;/code&gt;이 필요&lt;/li&gt;
&lt;li&gt;&lt;code&gt;데이터베이스 종속성&lt;/code&gt;: DB 검색을 통해 토큰 버전을 검증하므로, 검색하는데 &lt;code&gt;지연 시간&lt;/code&gt;이 발생할 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;사용자-로그아웃-및-강제-토큰-무효화&#34; &gt;사용자 로그아웃 및 강제 토큰 무효화
&lt;span&gt;
    &lt;a href=&#34;#%ec%82%ac%ec%9a%a9%ec%9e%90-%eb%a1%9c%ea%b7%b8%ec%95%84%ec%9b%83-%eb%b0%8f-%ea%b0%95%ec%a0%9c-%ed%86%a0%ed%81%b0-%eb%ac%b4%ed%9a%a8%ed%99%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;사용자가 &lt;code&gt;로그아웃&lt;/code&gt; 할 때, &lt;code&gt;서버에서 마킹&lt;/code&gt;하거나 &lt;code&gt;세션을 만료&lt;/code&gt;시켜 &lt;code&gt;JWT 토큰&lt;/code&gt;을 &lt;code&gt;무효화&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;로그아웃 이후 탈취된 토큰을 사용하는 것을 방지&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;장점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;즉시 발동&lt;/code&gt;: 토큰이 &lt;code&gt;즉시 무효화&lt;/code&gt; 됨&lt;/li&gt;
&lt;li&gt;&lt;code&gt;사용자 제어&lt;/code&gt;: 사용자는 로그아웃을 통해 &lt;code&gt;본인의 세션 보안을 제어&lt;/code&gt;할 수 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;단점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;Stateful함&lt;/code&gt;: 토큰 무효화를 위해 &lt;code&gt;서버측 상태를 유지&lt;/code&gt;해야 함&lt;/li&gt;
&lt;li&gt;&lt;code&gt;구현 복잡성&lt;/code&gt;: &lt;code&gt;분산 환경&lt;/code&gt;과 같이 여러 엔드포인트가 있는 경우 &lt;code&gt;구현하기 어려울 수&lt;/code&gt; 있음&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;토큰-무효화-목록token-revocation-list-trl&#34; &gt;토큰 무효화 목록(Token Revocation List, TRL)
&lt;span&gt;
    &lt;a href=&#34;#%ed%86%a0%ed%81%b0-%eb%ac%b4%ed%9a%a8%ed%99%94-%eb%aa%a9%eb%a1%9dtoken-revocation-list-trl&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;토큰 블랙리스트&lt;/code&gt;와 유사하지만, &lt;code&gt;토큰 취소 여부&lt;/code&gt;를 확인하기 위한 &lt;strong&gt;&lt;code&gt;쿼리&lt;/code&gt;&lt;/strong&gt; 가 가능한 &lt;code&gt;중앙 집중/분산형 서비스&lt;/code&gt;로 구현됨
&lt;ul&gt;
&lt;li&gt;이는 &lt;code&gt;여러 서비스, 엔드포인트&lt;/code&gt;에서 취소 여부를 확인해야 하는 &lt;code&gt;대규모 분산 시스템&lt;/code&gt;에 효과적&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;장점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;확장성&lt;/code&gt;:  분산 환경에서 높은 부하를 처리하도록 설계됨&lt;/li&gt;
&lt;li&gt;&lt;code&gt;중앙 집중식 관리&lt;/code&gt;: 토큰 무효화를 &lt;code&gt;중앙 집중화&lt;/code&gt;해 토큰 무효화 정책의 관리를 간소화&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;단점
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;지연 시간&lt;/code&gt;: &lt;code&gt;토큰 무효화 목록&lt;/code&gt;이 인-메모리 DB에 저장되지 않거나 최적화가 되어있지 않은 경우 지연시간 발생 가능&lt;/li&gt;
&lt;li&gt;&lt;code&gt;복잡성&lt;/code&gt;: &lt;code&gt;TRL&lt;/code&gt;의 구현 및 유지를 위한 신중한 설계 필요&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;토큰에-유저-컨텍스트-포함하기-httpscheatsheetseriesowasporgcheatsheetsjson_web_token_for_java_cheat_sheethtmltoken-sidejacking&#34; &gt;토큰에 유저 컨텍스트 포함하기 &lt;a href=&#34;https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.html#token-sidejacking&#34;&gt;#&lt;/a&gt;
&lt;span&gt;
    &lt;a href=&#34;#%ed%86%a0%ed%81%b0%ec%97%90-%ec%9c%a0%ec%a0%80-%ec%bb%a8%ed%85%8d%ec%8a%a4%ed%8a%b8-%ed%8f%ac%ed%95%a8%ed%95%98%ea%b8%b0-httpscheatsheetseriesowasporgcheatsheetsjson_web_token_for_java_cheat_sheethtmltoken-sidejacking&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;토큰에 &lt;code&gt;유저 컨텍스트&lt;/code&gt;를 추가해 사용자인지 공격자인지 식별.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;유저 컨텍스트&lt;/code&gt;는 다음과 같은 정보로 구성됨
&lt;ul&gt;
&lt;li&gt;인증 단계에서 &lt;code&gt;무작위 문자열&lt;/code&gt;을 생성해, &lt;code&gt;굳어진 쿠키(hardend cookie)&lt;/code&gt;로 클라이언트에게 전송
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;굳어진 쿠키&lt;/code&gt;는 &lt;code&gt;HttpOnly&lt;/code&gt; + &lt;code&gt;Secure&lt;/code&gt; + &lt;code&gt;SameSite&lt;/code&gt; + &lt;code&gt;Max-Age&lt;/code&gt; + &lt;code&gt;cookie prefixes&lt;/code&gt;와 같은 플래그가 설정된 쿠키&lt;/li&gt;
&lt;li&gt;이때, &lt;code&gt;쿠키의 수명(Max-Age)&lt;/code&gt;은 &lt;code&gt;JWT 만료값(exp)&lt;/code&gt;보다 작거나 같도록 설정해야 함&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;공격자가 이를 읽고 예상되는 쿠키를 설정하는 &lt;code&gt;XSS 문제&lt;/code&gt;를 방지하기 위해, &lt;code&gt;무작위 문자열&lt;/code&gt;의 &lt;code&gt;SHA256 해시&lt;/code&gt;를 원본 값 대신 토큰에 저장&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;서버는 &lt;code&gt;토큰 검증&lt;/code&gt; 중 &lt;strong&gt;올바른 컨텍스트가 포함되지 않은 경우&lt;/strong&gt;, &lt;code&gt;토큰을 거부&lt;/code&gt;해야 함.&lt;/li&gt;
&lt;/ul&gt;
&lt;h1 id=&#34;참고&#34; &gt;참고
&lt;span&gt;
    &lt;a href=&#34;#%ec%b0%b8%ea%b3%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7519&#34;&gt;RFC 7519 - JSON Web Token (JWT) (ietf.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7515&#34;&gt;RFC 7515 - JSON Web Signature (JWS) (ietf.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc7516&#34;&gt;RFC 7516 - JSON Web Encryption (JWE) (ietf.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.ibm.com/docs/en/order-management?topic=users-jwt-authentication&#34;&gt;JWT authentication - IBM Documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://auth0.com/docs/secure/tokens/access-tokens/json-web-encryption&#34;&gt;JSON Web Encryption (auth0.com)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.scottbrady91.com/jose/json-web-encryption&#34;&gt;Understanding JSON Web Encryption (JWE) (scottbrady91.com)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://jwt.io/introduction&#34;&gt;JSON Web Token Introduction - jwt.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.cloudflare.com/ko-kr/learning/access-management/what-is-saml/&#34;&gt;SAML이란? | SAML 인증이 작동하는 방식 | Cloudflare&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.okta.com/kr/blog/2020/09/what-is-saml/&#34;&gt;SAML | Okta Identity Korea&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://supertokens.com/blog/revoking-access-with-a-jwt-blacklist#&#34;&gt;7 Ways To Revoke JWT Tokens - SuperTokens&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://cheatsheetseries.owasp.org/cheatsheets/JSON_Web_Token_for_Java_Cheat_Sheet.html&#34;&gt;JSON Web Token for Java - OWASP Cheat Sheet Series&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;추후 참고할 것
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html&#34;&gt;Session Management - OWASP Cheat Sheet Series&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://openid.net/specs/draft-jones-json-web-encryption-02.html&#34;&gt;JSON Web Encryption (JWE) (openid.net)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>[웹, 네트워크] XSS 알아보기</title>
      <link>https://cloudsoswift.github.io/post/develop/network/xss/</link>
      <pubDate>Tue, 19 Mar 2024 19:51:00 +0900</pubDate>
      
      <guid>https://cloudsoswift.github.io/post/develop/network/xss/</guid>
      <description>&lt;h1 id=&#34;서론&#34; &gt;서론
&lt;span&gt;
    &lt;a href=&#34;#%ec%84%9c%eb%a1%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;p&gt;&lt;a href=&#34;https://github.com/orm712/CS-712&#34;&gt;CS 스터디&lt;/a&gt;에서 3월 12일 발표한 &lt;a href=&#34;https://github.com/orm712/CS-712/blob/main/03-NETWORK/21_XSS/Readme.md&#34;&gt;&lt;strong&gt;XSS&lt;/strong&gt;&lt;/a&gt;에 대해 정리한 문서를 블로그에 공유하고자 한다.&lt;/p&gt;
&lt;h2 id=&#34;xss란&#34; &gt;XSS란?
&lt;span&gt;
    &lt;a href=&#34;#xss%eb%9e%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;신뢰할 수 있는 웹 사이트에 &lt;strong&gt;악성코드를 삽입하는 공격&lt;/strong&gt;을 말합니다.&lt;br&gt;
공격자가 표적 웹사이트의 콘텐츠에 악성 스크립트를 삽입하고, 피해자의 브라우저에 전달되는 동적 콘텐츠에 이를 포함시키므로써 피해를 입게 됩니다.&lt;br&gt;
이때, 피해자의 브라우저는 해당 스크립트가 &lt;strong&gt;&amp;lsquo;신뢰할 수 없는 스크립트&amp;rsquo;라는 점&lt;/strong&gt;을 &lt;em&gt;알 수 없어&lt;/em&gt; &lt;strong&gt;해당 스크립트를 실행&lt;/strong&gt;하게 됩니다.&lt;br&gt;
악성 스크립트는 &lt;em&gt;피해자의 브라우저가 보유한&lt;/em&gt; 해당 사이트에서 사용되는 &lt;strong&gt;모든 쿠키, 저장소에 저장된 민감 정보에 액세스&lt;/strong&gt;할 수 있습니다.&lt;br&gt;
뿐만 아니라 &lt;strong&gt;멀웨어&lt;/strong&gt;를 퍼뜨리거나, 웹사이트의 콘&lt;strong&gt;텐츠를 변조&lt;/strong&gt;하거나,&lt;strong&gt;피싱 사이트로 이동&lt;/strong&gt;시키거나 하는 등의 공격도 가능합니다.&lt;br&gt;
다른 웹 공격들과 달리, &lt;em&gt;애플리케이션 자체가 아닌&lt;/em&gt; &lt;strong&gt;웹 애플리케이션 사용자를 표적&lt;/strong&gt;으로 삼는다는 특징이 있습니다.&lt;/p&gt;
&lt;h3 id=&#34;xss-공격의-종류&#34; &gt;XSS 공격의 종류
&lt;span&gt;
    &lt;a href=&#34;#xss-%ea%b3%b5%ea%b2%a9%ec%9d%98-%ec%a2%85%eb%a5%98&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;저장형-크로스사이트-스크립팅stored-cross-site-scripting&#34; &gt;&lt;code&gt;저장형 크로스사이트 스크립팅(Stored Cross-site Scripting)&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#%ec%a0%80%ec%9e%a5%ed%98%95-%ed%81%ac%eb%a1%9c%ec%8a%a4%ec%82%ac%ec%9d%b4%ed%8a%b8-%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8c%85stored-cross-site-scripting&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;stored-xss.png&#34; alt=&#34;stored-xss.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;지속적(Persistent) XSS&lt;/code&gt;라고도 하는 공격 방식입니다.&lt;br&gt;
사용자가 입력한 값이 저장(주로 게시판)된 후 이를 웹 페이지에서 출력할때 피해가 발생하는 공격입니다.&lt;br&gt;
공격자의 악성스크립트가 서버에 저장되어 불특정 다수를 대상으로 공격에 이용될 수 있어 Reflected XSS보다 공격 대상의 범위가 훨씬 크다는 특징이 있습니다.&lt;/p&gt;
&lt;h5 id=&#34;공격-방식&#34; &gt;공격 방식
&lt;span&gt;
    &lt;a href=&#34;#%ea%b3%b5%ea%b2%a9-%eb%b0%a9%ec%8b%9d&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;공격자가 스크립트가 포함된 &lt;strong&gt;콘텐츠&lt;/strong&gt;(&lt;strong&gt;게시글, 댓글, 사용자 이름 등&lt;/strong&gt;)를 작성한 뒤, 이를 피해자가 요청하게 되면 해당 스크립트가 &lt;strong&gt;피해자 측에서 동작&lt;/strong&gt;하게 됩니다.&lt;/p&gt;
&lt;h4 id=&#34;반사-크로스사이트-스크립팅reflected-cross-site-scripting&#34; &gt;&lt;code&gt;반사 크로스사이트 스크립팅(Reflected cross-site scripting)&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#%eb%b0%98%ec%82%ac-%ed%81%ac%eb%a1%9c%ec%8a%a4%ec%82%ac%ec%9d%b4%ed%8a%b8-%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8c%85reflected-cross-site-scripting&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;reflected-xss.png&#34; alt=&#34;reflected-xss.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;비지속적(Non-Persistent) XSS&lt;/code&gt;라고도 하는 공격 방식입니다.&lt;br&gt;
이름에 포함된 &amp;lsquo;반사&amp;rsquo; 라는 단어처럼, &lt;strong&gt;사용자가 요청&lt;/strong&gt;한 스크립트가 사용자 측에서 반사되어 동작합니다. 즉, 공격자의 스크립트가 별도의 저장소에 저장되지 않고 &lt;strong&gt;사용자 측에서 즉시 동작&lt;/strong&gt;합니다.&lt;br&gt;
&lt;em&gt;지속적 XSS와 달리&lt;/em&gt;, &lt;strong&gt;공격자가&lt;/strong&gt; 각 피해자들에게 페이로드(악성스크립트)를 &lt;strong&gt;전달&lt;/strong&gt;해주어야 합니다. 따라서 악성 링크, 피싱 이메일, SNS 등을 이용해 해당 페이로드가 포함된 URL을 &lt;strong&gt;클릭하도록 유도&lt;/strong&gt;해야 합니다.&lt;/p&gt;
&lt;h5 id=&#34;공격-방식-1&#34; &gt;공격 방식
&lt;span&gt;
    &lt;a href=&#34;#%ea%b3%b5%ea%b2%a9-%eb%b0%a9%ec%8b%9d-1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;공격자가 &lt;strong&gt;악성스크립트가 웹서버로 전송되는 요청(URL)의 일부&lt;/strong&gt;가 되도록 합니다. 요청과 함께 포함되어있던 악성 스크립트가 &lt;strong&gt;사용자의 브라우저에서 동작&lt;/strong&gt;하게 됩니다.&lt;/p&gt;
&lt;h4 id=&#34;dom-기반-크로스사이트-스크립팅dom-based-cross-site-scripting&#34; &gt;&lt;code&gt;DOM 기반 크로스사이트 스크립팅(DOM-based cross-site scripting)&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#dom-%ea%b8%b0%eb%b0%98-%ed%81%ac%eb%a1%9c%ec%8a%a4%ec%82%ac%ec%9d%b4%ed%8a%b8-%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8c%85dom-based-cross-site-scripting&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;dom-based-xss.png&#34; alt=&#34;dom-based-xss.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;공격자의 스크립트가 HTML 내부가 아닌, &lt;strong&gt;&lt;code&gt;DOM&lt;/code&gt;에 나타나는 공격 방식&lt;/strong&gt;입니다.&lt;br&gt;
반사/저장형 XSS에서는 응답 페이지에서 스크립트를 확인할 수 있는것과 다르게 HTML 소스 코드와 응답 페이지의 코드가 동일하기 때문에 페이로드를 찾을 수 없습니다.&lt;br&gt;
따라서 &lt;strong&gt;런타임일때&lt;/strong&gt;, 또는 &lt;strong&gt;페이지의 DOM을 조사&lt;/strong&gt;해야만 스크립트를 찾을 수 있습니다.&lt;br&gt;
DOM 기반 XSS는 주로 &lt;strong&gt;Client-side 공격&lt;/strong&gt;으로, 악성 스크립트는 서버로 전송되지 않습니다. 따라서 &lt;strong&gt;서버 로그를 분석해도 공격을 확인할 수 없습니다.&lt;/strong&gt;&lt;/p&gt;
&lt;h5 id=&#34;공격-방식-2&#34; &gt;공격 방식
&lt;span&gt;
    &lt;a href=&#34;#%ea%b3%b5%ea%b2%a9-%eb%b0%a9%ec%8b%9d-2&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;공격자가 악성스크립트가 포함된 URL을 요청하면, 해당 &lt;strong&gt;스크립트를 실행해 DOM 영역을 변경&lt;/strong&gt;합니다. 브라우저 자체에서 스크립트가 실행되어 DOM 영역을 변화시키므로 서로 패킷을 보내지 않고 공격이 수행됩니다.&lt;br&gt;
주로 &lt;code&gt;document&lt;/code&gt;, &lt;code&gt;location&lt;/code&gt;와 같은 &lt;strong&gt;DOM 객체를 조작&lt;/strong&gt;해 공격을 수행합니다.&lt;/p&gt;
&lt;h2 id=&#34;csrf랑-xss의-차이점&#34; &gt;CSRF랑 XSS의 차이점?
&lt;span&gt;
    &lt;a href=&#34;#csrf%eb%9e%91-xss%ec%9d%98-%ec%b0%a8%ec%9d%b4%ec%a0%90&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;&lt;code&gt;크로스-사이트 요청 위조(Cross-site Request Forgery)&lt;/code&gt;와 &lt;code&gt;크로스-사이트 스크립팅(Cross-site Scripting)&lt;/code&gt; 모두 &lt;strong&gt;웹 애플리케이션&lt;/strong&gt;에서 발견되는 보안 취약점입니다.&lt;br&gt;
두 공격 방식의 가장 큰 차이는 &lt;strong&gt;&lt;code&gt;인증된 세션(쿠키 등)&lt;/code&gt;을 활용하느냐&lt;/strong&gt; 여부 입니다.&lt;br&gt;
&lt;code&gt;CSRF 공격&lt;/code&gt;은 사용자의 &lt;strong&gt;인증된 세션을 악용&lt;/strong&gt;하는 공격 방식이고, &lt;code&gt;XSS 공격&lt;/code&gt;은 사용자가 &lt;strong&gt;특정 사이트를 신뢰한다는 사실을 이용&lt;/strong&gt;해 인증된 세션 없이도 공격할 수 있는 공격 방식입니다.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;CSRF&lt;/th&gt;
&lt;th&gt;XSS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;사용자가 공격 사실을 모르는채 대상 웹사이트에 &lt;strong&gt;악성 요청&lt;/strong&gt;을 보내도록 합니다.&lt;/td&gt;
&lt;td&gt;웹 사이트에 클라이언트 측 &lt;strong&gt;스크립트를 삽입&lt;/strong&gt;해 공격합니다.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;공격을 수행하기 위해 Javascript가 필요하지 않습니다.&lt;/td&gt;
&lt;td&gt;공격을 수행하기 위해 &lt;strong&gt;Javascript가 필요&lt;/strong&gt;합니다.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;악성 스크립트가 &lt;strong&gt;다른 사이트에 저장&lt;/strong&gt;되어 있습니다.&lt;/td&gt;
&lt;td&gt;웹 사이트가 &lt;strong&gt;악성 스크립트를 허용&lt;/strong&gt;합니다.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;취약한 &lt;strong&gt;URL에서 수행하는 작업만 수행&lt;/strong&gt;할 수 있습니다.&lt;/td&gt;
&lt;td&gt;공격자가 취약점을 이용해 &lt;strong&gt;원하는 모든 행동&lt;/strong&gt;을 할 수 있습니다.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&#34;xss는-프론트엔드에서만-방어할-수-있을까&#34; &gt;XSS는 프론트엔드에서만 방어할 수 있을까?
&lt;span&gt;
    &lt;a href=&#34;#xss%eb%8a%94-%ed%94%84%eb%a1%a0%ed%8a%b8%ec%97%94%eb%93%9c%ec%97%90%ec%84%9c%eb%a7%8c-%eb%b0%a9%ec%96%b4%ed%95%a0-%ec%88%98-%ec%9e%88%ec%9d%84%ea%b9%8c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;XSS 공격은 &lt;em&gt;프론트엔드 뿐만 아니라&lt;/em&gt;, &lt;strong&gt;백엔드단에서도 방어&lt;/strong&gt;할 수 있습니다.&lt;br&gt;
프로그래밍 언어와 웹 프레임워크 별로 방어 할 수 있는 방법들이 다양하지만, 해당 방법들의 &lt;strong&gt;주요 전략&lt;/strong&gt;은 &lt;code&gt;&#39;사용자 입력 값을 전처리한다&#39;&lt;/code&gt;입니다.&lt;br&gt;
스크립트에서 자주 사용되는&lt;code&gt; &amp;lt;, &amp;gt;, (, )&lt;/code&gt; 와 같은괄호를 HTML로 바꾼다거나, &lt;a href=&#34;https://github.com/naver/lucy-xss-filter&#34;&gt;Lucy-XSS-Filter&lt;/a&gt;, &lt;a href=&#34;https://github.com/ESAPI/esapi-java-legacy&#34;&gt;OWASP ESAPI&lt;/a&gt;와 같은 라이브러리를 사용해 방어할 수 있습니다.&lt;br&gt;
또한, Spring에서는 &lt;code&gt;Spring Security&lt;/code&gt;에서 제공하는 &lt;code&gt;X-XSS-Protection&lt;/code&gt; 헤더를 사용할 수도 있습니다.&lt;/p&gt;
&lt;h3 id=&#34;x-xss-protection&#34; &gt;&lt;code&gt;X-XSS-Protection&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#x-xss-protection&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;브라우저에게 &lt;strong&gt;XSS 공격처럼 생긴 스크립트를 차단&lt;/strong&gt;하도록 지시합니다.&lt;br&gt;
해당 기능을 사용하면 브라우저는 XSS 공격을 감지했을때 이를 렌더링하지 않지만, 일부 웹 브라우저는 이에 필요한 &lt;code&gt;XSS 감사기(Auditor)&lt;/code&gt;를 구현하지 않아 해당 헤더를 사용할 수 없습니다. 이를 보완하기 위해 &lt;code&gt;콘텐츠 보안 정책(CSP)&lt;/code&gt; 기능을 사용할 수도 있습니다.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;다만, 구글에서는 &lt;a href=&#34;https://www.chromium.org/developers/design-documents/xss-auditor/&#34;&gt;2019년 8월 XSS 감사기를 삭제&lt;/a&gt;했습니다.
&lt;ul&gt;
&lt;li&gt;지난 수 년 동안 XSS 감사기에 대한 &lt;strong&gt;수많은 우회 방법&lt;/strong&gt;들이 제시되었고, 합&lt;strong&gt;법적인 사이트에 대한 액세스를 차단&lt;/strong&gt;하는 경우도 존재했기 때문에 구글에서는 이를 삭제했습니다.&lt;/li&gt;
&lt;li&gt;이후 DOM 기반 XSS 공격에 대한 방어책인 &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API&#34;&gt;Trusted Types API&lt;/a&gt; 를 도입했습니다.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;콘텐츠-보안-정책csp&#34; &gt;&lt;code&gt;콘텐츠 보안 정책(CSP)&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#%ec%bd%98%ed%85%90%ec%b8%a0-%eb%b3%b4%ec%95%88-%ec%a0%95%ec%b1%85csp&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;CSP는 XSS와 데이터 인젝션 공격을 완화하는데 도움을 주는 &lt;strong&gt;추가 보안 계층&lt;/strong&gt;입니다. 이를 사용하려면 Content-Security-Policy 헤더를 반환하도록 애플리케이션을 구성해야 합니다.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-java&#34; data-lang=&#34;java&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;@Configuration&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;SecurityConf&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#a6e22e&#34;&gt;@Bean&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#66d9ef&#34;&gt;public&lt;/span&gt; SecurityFilterChain &lt;span style=&#34;color:#a6e22e&#34;&gt;filterChain&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;HttpSecurity http&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;throws&lt;/span&gt; Exception &lt;span style=&#34;color:#f92672&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        http&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;headers&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;headers &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                headers&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;xssProtection&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        xss &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; xss&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;headerValue&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;XXssProtectionHeaderWriter&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;HeaderValue&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;ENABLED_MODE_BLOCK&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#f92672&#34;&gt;).&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;contentSecurityPolicy&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                        cps &lt;span style=&#34;color:#f92672&#34;&gt;-&amp;gt;&lt;/span&gt; cps&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;policyDirectives&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;(&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;script-src &amp;#39;self&amp;#39;&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;                &lt;span style=&#34;color:#f92672&#34;&gt;));&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;        &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; http&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;build&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;();&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;참고-문서&#34; &gt;참고 문서
&lt;span&gt;
    &lt;a href=&#34;#%ec%b0%b8%ea%b3%a0-%eb%ac%b8%ec%84%9c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://usa.kaspersky.com/resource-center/definitions/what-is-a-cross-site-scripting-attack&#34;&gt;What is a Cross-Site Scripting attack? Definition &amp;amp; Examples (kaspersky.com)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.fis.kr/ko/major_biz/cyber_safety_oper/attack_info/security_news?articleSeq=3408&#34;&gt;보안뉴스 - 웹 취약점과 해킹 매커니즘#7 XSS(Cross-Site Scripting) 상세화면 | 한국재정정보원 &amp;gt; 주요사업 &amp;gt; 사이버안전센터 운영 &amp;gt; 사이버위협 정보 및 통계 &amp;gt; 보안뉴스 (fis.kr)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://portswigger.net/web-security/cross-site-scripting/dom-based&#34;&gt;What is DOM-based XSS (cross-site scripting)? Tutorial &amp;amp; Examples | Web Security Academy (portswigger.net)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.geeksforgeeks.org/difference-between-xss-and-csrf/&#34;&gt;Difference between XSS and CSRF - GeeksforGeeks&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection&#34;&gt;X-XSS-Protection - HTTP | MDN (mozilla.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.baeldung.com/spring-prevent-xss&#34;&gt;Prevent Cross-Site Scripting (XSS) in a Spring Application | Baeldung&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.dailysecu.com/news/articleView.html?idxno=55207&#34;&gt;구글, 크롬의 XSS 오디터 삭제할 계획 - 데일리시큐 (dailysecu.com)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Trusted_Types_API&#34;&gt;Trusted Types API - Web APIs | MDN (mozilla.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.spring.io/spring-security/site/docs/5.0.x/reference/html/headers.html#headers-xss-protection&#34;&gt;21. Security HTTP Response Headers (spring.io)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>[웹, 네트워크] SOP 알아보기</title>
      <link>https://cloudsoswift.github.io/post/develop/network/sop/</link>
      <pubDate>Tue, 19 Mar 2024 19:50:47 +0900</pubDate>
      
      <guid>https://cloudsoswift.github.io/post/develop/network/sop/</guid>
      <description>&lt;h1 id=&#34;서론&#34; &gt;서론
&lt;span&gt;
    &lt;a href=&#34;#%ec%84%9c%eb%a1%a0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;p&gt;&lt;a href=&#34;https://github.com/orm712/CS-712&#34;&gt;CS 스터디&lt;/a&gt;에서 3월 20일 발표예정인 &lt;a href=&#34;https://github.com/orm712/CS-712/blob/main/03-NETWORK/15_SOP/Readme.md&#34;&gt;&lt;strong&gt;SOP&lt;/strong&gt;&lt;/a&gt;에 대해 정리한 문서를 블로그에 공유하고자 한다.&lt;/p&gt;
&lt;h2 id=&#34;sop-정책이란&#34; &gt;SOP 정책이란?.
&lt;span&gt;
    &lt;a href=&#34;#sop-%ec%a0%95%ec%b1%85%ec%9d%b4%eb%9e%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;&lt;code&gt;동일 출처 정책(SOP, Same Origin Policy)&lt;/code&gt;&lt;/strong&gt; 은 &lt;em&gt;한 출처에서 불러온 문서 또는 스크립트&lt;/em&gt;가 &lt;strong&gt;다른 출처의 자원&lt;/strong&gt;과 &lt;strong&gt;상호 작용하는 방식&lt;/strong&gt;을 &lt;u&gt;제한&lt;/u&gt;하는 보안 메커니즘입니다.&lt;br&gt;
다른 출처의 자원과의 상호 작용을 제한하므로써, &lt;b&gt;잠재적으로 악의적인 문서들로 부터 &lt;u&gt;격리&lt;/u&gt;&lt;/b&gt;시켜 가능한 공격 경로를 줄일 수 있습니다. 이러한 격리를 통해 악성 웹사이트가 사용자가 로그인한 타 서비스의 데이터를 읽고 공격자에게 전달하는 것을 막을 수 있습니다.&lt;/p&gt;
&lt;h3 id=&#34;출처origin&#34; &gt;&lt;code&gt;출처(Origin)&lt;/code&gt;?
&lt;span&gt;
    &lt;a href=&#34;#%ec%b6%9c%ec%b2%98origin&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;p&gt;웹에서 같은 &lt;code&gt;출처&lt;/code&gt;인지 판단하는 기준은 &lt;strong&gt;URL의 &lt;code&gt;프로토콜&lt;/code&gt;, &lt;code&gt;포트&lt;/code&gt;(지정된 경우), &lt;code&gt;호스트 이름(hostname)&lt;/code&gt;이 모두 동일한 지&lt;/strong&gt; 입니다. 이를 &lt;code&gt;튜플&lt;/code&gt;이라고 부르기도 합니다.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;호스트 이름(hostname)&lt;/code&gt; : 네트워크에 연결된 컴퓨터 또는 기타 &lt;strong&gt;장치에 할당되는 이름&lt;/strong&gt;으로, &lt;code&gt;로컬 호스트 이름(local hostname)&lt;/code&gt;과 &lt;code&gt;도메인 이름(domain name)&lt;/code&gt;의 조합으로 구성됩니다.
&lt;ul&gt;
&lt;li&gt;예시) &lt;code&gt;en.wikipedia.org&lt;/code&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;en&lt;/code&gt;(로컬 호스트 이름)과 &lt;code&gt;wikipedia.org&lt;/code&gt;(도메인 이름)으로 구성되어 있습니다.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;예시&#34; &gt;예시
&lt;span&gt;
    &lt;a href=&#34;#%ec%98%88%ec%8b%9c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;code&gt;http://store.company.com/dir/page.html&lt;/code&gt; 라는 URL을 기준으로 예시를 들어보겠습니다.&lt;/p&gt;
&lt;h5 id=&#34;동일한-출처&#34; &gt;동일한 출처
&lt;span&gt;
    &lt;a href=&#34;#%eb%8f%99%ec%9d%bc%ed%95%9c-%ec%b6%9c%ec%b2%98&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;아래 링크들은 &lt;strong&gt;경로&lt;/strong&gt;만 다른 케이스 입니다.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http://store.company.com/dir2/other.html&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;http://store.company.com/dir/inner/another.html&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h5 id=&#34;다른-출처&#34; &gt;다른 출처
&lt;span&gt;
    &lt;a href=&#34;#%eb%8b%a4%eb%a5%b8-%ec%b6%9c%ec%b2%98&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;프로토콜이 다른 경우&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;https://store.company.com/page.html&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;포트가 다른 경우&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http://store.company.com:81/dir/page.html&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;호스트 이름이 다른 경우&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;http://news.company.com/dir/page.html&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;출처-변경-공격&#34; &gt;출처 변경 공격
&lt;span&gt;
    &lt;a href=&#34;#%ec%b6%9c%ec%b2%98-%eb%b3%80%ea%b2%bd-%ea%b3%b5%ea%b2%a9&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;이전에는 DOM 객체인 document의 &lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/API/Document/domain&#34;&gt;&lt;code&gt;document.domain&lt;/code&gt;&lt;/a&gt;을 조작해 도메인을 현재 도메인 또는 상위 도메인으로 변경할 수 있었으나, 보안 문제 때문에&lt;code&gt;document.domain&lt;/code&gt; 설정자가 사장되어(deprecated) 해당 방식 공격은 불가능하게 되었습니다.&lt;/p&gt;
&lt;h3 id=&#34;교차출처-접근의-종류&#34; &gt;교차출처 접근의 종류
&lt;span&gt;
    &lt;a href=&#34;#%ea%b5%90%ec%b0%a8%ec%b6%9c%ec%b2%98-%ec%a0%91%ea%b7%bc%ec%9d%98-%ec%a2%85%eb%a5%98&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;교차출처-쓰기&#34; &gt;교차출처 쓰기
&lt;span&gt;
    &lt;a href=&#34;#%ea%b5%90%ec%b0%a8%ec%b6%9c%ec%b2%98-%ec%93%b0%ea%b8%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;code&gt;링크&lt;/code&gt;, &lt;code&gt;리다이렉션&lt;/code&gt;, &lt;code&gt;form 제출&lt;/code&gt; 등의 작업으로, &lt;strong&gt;일반적으로 허용&lt;/strong&gt;되는 작업입니다. 일부 HTTP 요청은 &lt;code&gt;preflight&lt;/code&gt;가 필요합니다.&lt;/p&gt;
&lt;h4 id=&#34;교차출처-임베딩&#34; &gt;교차출처 임베딩
&lt;span&gt;
    &lt;a href=&#34;#%ea%b5%90%ec%b0%a8%ec%b6%9c%ec%b2%98-%ec%9e%84%eb%b2%a0%eb%94%a9&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;strong&gt;일반적으로 허용&lt;/strong&gt;됩니다.&lt;br&gt;
&lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt;(javascript),  &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;(css), &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;video&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;audio&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;object&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;embed&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;, &lt;code&gt;@font-face&lt;/code&gt;(일부 브라우저 한정) 등이 있습니다.&lt;/p&gt;
&lt;h4 id=&#34;교차출처-읽기&#34; &gt;교차출처 읽기
&lt;span&gt;
    &lt;a href=&#34;#%ea%b5%90%ec%b0%a8%ec%b6%9c%ec%b2%98-%ec%9d%bd%ea%b8%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;u&gt;일반적으로 허용되지 않으나&lt;/u&gt;, &lt;em&gt;&lt;code&gt;임베딩&lt;/code&gt;을 통해&lt;/em&gt; &lt;strong&gt;읽기 접근이 유출&lt;/strong&gt;되는 경우가 있습니다.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ex) 임베딩된 이미지의 크기, 임베딩된 스크립트의 동작&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;cors-정책이란&#34; &gt;CORS 정책이란?
&lt;span&gt;
    &lt;a href=&#34;#cors-%ec%a0%95%ec%b1%85%ec%9d%b4%eb%9e%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;&lt;code&gt;교차 출처 리소스 공유(CORS, Cross-Origin Resource Sharing)&lt;/code&gt;는 &lt;strong&gt;다른 출처의 자원을 접근&lt;/strong&gt;할 수 있도록 &lt;u&gt;허용&lt;/u&gt;하는 정책을 말합니다.&lt;br&gt;
이는 서버에서 웹 브라우저가 해당 자원을 읽을 수 있는 출처를 설명할 수 있는 &lt;strong&gt;새로운 &lt;code&gt;HTTP 헤더&lt;/code&gt;&lt;/strong&gt; (&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;)를 추가하는 방식으로 동작합니다.&lt;br&gt;
클라이언트에서는 교차출처 자원을 호스팅하는 서버에  &amp;lsquo;&lt;em&gt;서버가 실제 요청을 허용할 것인지&lt;/em&gt;&amp;lsquo;를 확인하기 위해 브라우저가 &lt;code&gt;preflight&lt;/code&gt; 요청을 전송하는 메커니즘을 사용합니다.&lt;/p&gt;
&lt;h3 id=&#34;cors를-사용하는-요청&#34; &gt;CORS를 사용하는 요청
&lt;span&gt;
    &lt;a href=&#34;#cors%eb%a5%bc-%ec%82%ac%ec%9a%a9%ed%95%98%eb%8a%94-%ec%9a%94%ec%b2%ad&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fetch()&lt;/code&gt;, &lt;code&gt;XMLHttpRequest&lt;/code&gt; 호출&lt;/li&gt;
&lt;li&gt;웹 폰트(&lt;code&gt;@font-face&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;WebGL 텍스처&lt;/li&gt;
&lt;li&gt;이미지/비디오 프레임
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;canvas&amp;gt;&lt;/code&gt;상에서 &lt;code&gt;drawImage()&lt;/code&gt;를 이용해 그려진&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;이미지상의 CSS 도형&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;cors-관련-헤더&#34; &gt;CORS 관련 헤더
&lt;span&gt;
    &lt;a href=&#34;#cors-%ea%b4%80%eb%a0%a8-%ed%97%a4%eb%8d%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;access-control-allow-origin&#34; &gt;&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#access-control-allow-origin&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;응답 헤더 중 하나로, 서버의 자원 소유자가 특정 도메인에서의 요청만 허용해 자원에 대한 접근을 제어하는데 쓸 수 있는 헤더입니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;// https://foo.example에서의 접근만 허용하는 경우
Access-Control-Allow-Origin: https://foo.example
// 모든 도메인으로부터 접근을 허용하는 경우 (자격증명이 필요 없는 요청인 경우)
Access-Control-Allow-Origin: *
&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;자격 증명&lt;/strong&gt;: &lt;em&gt;쿠키, TLS 클라이언트 인증서, 인증 헤더&lt;/em&gt;와 같은 &lt;strong&gt;인증 정보를 담은 것&lt;/strong&gt;을 말하며, &lt;code&gt;Access-Control-Allow-Credentials&lt;/code&gt;(응답 헤더)가 &lt;code&gt;true&lt;/code&gt;인 경우 사용자는 교차 출처 요청에 자격 증명을 포함할 수 있습니다.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;완화-방법&#34; &gt;완화 방법
&lt;span&gt;
    &lt;a href=&#34;#%ec%99%84%ed%99%94-%eb%b0%a9%eb%b2%95&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;access-control-allow-origin응답-헤더-설정&#34; &gt;&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt; 응답 헤더 설정
&lt;span&gt;
    &lt;a href=&#34;#access-control-allow-origin%ec%9d%91%eb%8b%b5-%ed%97%a4%eb%8d%94-%ec%84%a4%ec%a0%95&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;서버 측에서 요청을 &lt;u&gt;허용할 출처&lt;/u&gt;를 &lt;strong&gt;명시적으로 설정&lt;/strong&gt;해줍니다.&lt;br&gt;
만약 자격증명이 필요한 경우, &lt;code&gt;*&lt;/code&gt;는 사용할 수 없습니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;Access-Control-Allow-Origin: &amp;lt;origin&amp;gt; | *
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&#34;프록시-서버-사용하기&#34; &gt;프록시 서버 사용하기
&lt;span&gt;
    &lt;a href=&#34;#%ed%94%84%eb%a1%9d%ec%8b%9c-%ec%84%9c%eb%b2%84-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;p&gt;&lt;img src=&#34;proxy-server.png&#34; alt=&#34;proxy-server.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;웹 애플리케이션에서 직접 자원에 접근하지 않고, 프록시 서버를 사용해 요청을 전달하는 방식입니다. 이는 SOP 정책이 브라우저-서버 간 통신에서만 구현된다는 점을 이용합니다.&lt;br&gt;
웹 애플리케이션과 프록시 서버간에는 &lt;code&gt;Access-Control-Allow-Origin: *&lt;/code&gt; 응답 헤더를 추가해 자유롭게 요청을 주고 받습니다.&lt;br&gt;
그리고 서버-서버 간 통신에서는 SOP 정책을 만족할 필요가 없으므로 프록시 서버에서는 자유롭게 교차출처 자원에 접근할 수 있습니다.&lt;/p&gt;
&lt;h2 id=&#34;preflight란&#34; &gt;Preflight란?
&lt;span&gt;
    &lt;a href=&#34;#preflight%eb%9e%80&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h2&gt;&lt;p&gt;&lt;img src=&#34;preflight-timeline.png&#34; alt=&#34;preflight-timeline.png&#34;&gt;&lt;/p&gt;
&lt;p&gt;다른 출처의 자원에 대해 &lt;code&gt;OPTIONS&lt;/code&gt; 메서드 요청을 먼저 전송해, 실제 요청을 전송해도 안전한지 확인하는 방식을 말합니다.&lt;br&gt;
브라우저에서는 CORS를 사용하는 요청에 대해 &lt;code&gt;OPTIONS&lt;/code&gt; 메서드를 자동으로 보내는데, 이때 원본 요청의 메서드, 헤더와 같은 값을 &lt;code&gt;Access-Control-Request-...&lt;/code&gt; 과 같은 헤더에 담아서 해당 메서드, 헤더로 요청을 전송할 수 있는지 확인합니다.&lt;br&gt;
그리고 서버는 이에 대한 응답에 &lt;code&gt;Access-Control-Allow-...&lt;/code&gt; 와 같은 헤더를 담아 허용되는 메서드, 헤더 등에 대한 정보를 알려줍니다.&lt;/p&gt;
&lt;h3 id=&#34;preflight-관련-헤더&#34; &gt;Preflight 관련 헤더
&lt;span&gt;
    &lt;a href=&#34;#preflight-%ea%b4%80%eb%a0%a8-%ed%97%a4%eb%8d%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h3&gt;&lt;h4 id=&#34;요청-헤더&#34; &gt;요청 헤더
&lt;span&gt;
    &lt;a href=&#34;#%ec%9a%94%ec%b2%ad-%ed%97%a4%eb%8d%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;h5 id=&#34;origin&#34; &gt;&lt;code&gt;Origin&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#origin&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;요청을 발생시킨 출처(스키마, 호스트 이름, 포트)를 나타냅니다.&lt;br&gt;
&lt;code&gt;user agent&lt;/code&gt;가 &lt;em&gt;페이지에 포함되거나&lt;/em&gt;, &lt;em&gt;페이지 내 스크립트가 접근하는 자원에 대해&lt;/em&gt; 요청해야 하는 경우 페이지의 출처가 요청에 포함될 수 있습니다.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;일반적으로 &lt;code&gt;user agent&lt;/code&gt;는 모든 교차출처 요청, 또는 동일 출처에 대해 &lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;HEAD&lt;/code&gt;를 제외한 요청에 대해 &lt;code&gt;Origin&lt;/code&gt; 헤더를 추가합니다.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;// 특정 케이스의 경우 Origin은 null일 수 있습니다.
Origin: null
// 스키마(사용되는 프로토콜)와 호스트 이름(+ 포트)의 조합으로 Origin이 표시됩니다.
Origin: &amp;lt;scheme&amp;gt;://&amp;lt;hostname&amp;gt;
Origin: &amp;lt;scheme&amp;gt;://&amp;lt;hostname&amp;gt;:&amp;lt;port&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id=&#34;access-control-request-method&#34; &gt;&lt;code&gt;Access-Control-Request-Method&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#access-control-request-method&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;원본 요청의 메서드가 어떤 것인지를 나타냅니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;// ex) post 요청인 경우
Access-Control-Request-Method: POST
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id=&#34;access-control-request-headers&#34; &gt;&lt;code&gt;Access-Control-Request-Headers&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#access-control-request-headers&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;원본 요청의 헤더로 어떤 것이 있는지를 나타냅니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;// ex) 헤더에 X-PINGOTHER, Content-Type를 담은 경우
Access-Control-Request-Headers: X-PINGOTHER, Content-Type
&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&#34;응답-헤더&#34; &gt;응답 헤더
&lt;span&gt;
    &lt;a href=&#34;#%ec%9d%91%eb%8b%b5-%ed%97%a4%eb%8d%94&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h4&gt;&lt;h5 id=&#34;access-control-allow-origin-1&#34; &gt;&lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#access-control-allow-origin-1&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;h5 id=&#34;access-control-allow-methods&#34; &gt;&lt;code&gt;Access-Control-Allow-Methods&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#access-control-allow-methods&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;요청한 자원에 대해 쿼리할 수 있는 유효한 메서드들을 알려줍니다. (쉼표로 구분)
모든 메서드를 허용하기 위해 &lt;code&gt;*(와일드카드)&lt;/code&gt;를 쓸 수 있지만, 자격 증명이 없는 요청(&lt;em&gt;HTTP 쿠키 또는 authentication이 없는&lt;/em&gt;)에 한해서만 사용할 수 있습니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;// ex) POST, GET, OPTIONS 메서드만 허용되는 경우
Access-Control-Allow-Methods: POST, GET, OPTIONS
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id=&#34;access-control-allow-headers&#34; &gt;&lt;code&gt;Access-Control-Allow-Headers&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#access-control-allow-headers&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;원본 요청의 헤더 중 허용되는 헤더를 알려줍니다. (쉼표로 구분)
모든 헤더를 허용하기 위해 &lt;code&gt;*&lt;/code&gt;를 쓸 수 있지만, 자격 증명이 없는 요청(&lt;em&gt;HTTP 쿠키 또는 authentication이 없는&lt;/em&gt;)에 한해서만 사용할 수 있습니다.
또한, &lt;code&gt;*&lt;/code&gt;를 사용해도, &lt;code&gt;Authorization&lt;/code&gt; 헤더의 경우 명시적으로 나열해야 합니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;// ex) X-PINGOTHER, Content-Type 헤더가 허용되는 경우
Access-Control-Allow-Headers: X-PINGOTHER, Content-Type
// ex) &amp;#39;X-Custom-Header&amp;#39; 라는 사용자 지정 헤더가 허용되는 경우
Access-Control-Allow-Headers: X-Custom-Header
&lt;/code&gt;&lt;/pre&gt;&lt;h5 id=&#34;access-control-max-age&#34; &gt;&lt;code&gt;Access-Control-Max-Age&lt;/code&gt;
&lt;span&gt;
    &lt;a href=&#34;#access-control-max-age&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h5&gt;&lt;p&gt;preflight의 결과(즉 &lt;code&gt;Access-Control-Allow-Methods&lt;/code&gt;, &lt;code&gt;Access-Control-Allow-Headers&lt;/code&gt;에 포함된 정보)가 캐시될 수 있는 기간을 알려줍니다.
결과를 캐시할 수 있는 최대 시간(초)를 나타내며, 브라우저마다 최대치(&lt;code&gt;파이어폭스&lt;/code&gt;:24시간, &lt;code&gt;크로미움(v76이전)&lt;/code&gt;: 10분, &lt;code&gt;크로미움(v76이후)&lt;/code&gt;: 2시간)가 다릅니다.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;// ex) preflight의 결과가 캐시로 10분동안 저장됩니다.
Access-Control-Max-Age: 600
&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&#34;참고-문서&#34; &gt;참고 문서
&lt;span&gt;
    &lt;a href=&#34;#%ec%b0%b8%ea%b3%a0-%eb%ac%b8%ec%84%9c&#34;&gt;
        &lt;svg viewBox=&#34;0 0 28 23&#34; height=&#34;100%&#34; width=&#34;19&#34; xmlns=&#34;http://www.w3.org/2000/svg&#34;&gt;&lt;path d=&#34;M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;path d=&#34;M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71&#34; fill=&#34;none&#34; stroke-linecap=&#34;round&#34; stroke-miterlimit=&#34;10&#34; stroke-width=&#34;2&#34;/&gt;&lt;/svg&gt;
    &lt;/a&gt;
&lt;/span&gt;
&lt;/h1&gt;&lt;hr&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#preflighted_requests&#34;&gt;Cross-Origin Resource Sharing (CORS) - HTTP | MDN (mozilla.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#cross-origin_script_api_access&#34;&gt;Same-origin policy - Security on the web | MDN (mozilla.org)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://velog.io/@minjae-mj/%ED%98%B8%EC%8A%A4%ED%8A%B8-%EB%84%A4%EC%9E%84%EA%B3%BC-%EB%8F%84%EB%A9%94%EC%9D%B8-%EB%84%A4%EC%9E%84&#34;&gt;hostname(호스트명), domain name(도메인), same origin VS same site (velog.io)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9&#34;&gt;3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works | by David Katz | Medium&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://docs.tosspayments.com/resources/glossary/cors#cors-%EC%97%90%EB%9F%AC-%EB%8C%80%EC%9D%91%ED%95%98%EA%B8%B0&#34;&gt;CORS(교차 출처 리소스 공유) | 토스페이먼츠 개발자센터 (tosspayments.com)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
  </channel>
</rss>
