๐งท ์ถ์ฒ
์ด๋ฏธ์ง ์ถ์ฒ: https://www.devyummi.com/page?id=66934f448a005e7d8f32213a
๐ฅ ๋ฌธ์ ์ํฉ
๋ก๊ทธ์ธ ์ฑ ์์ ๋ฐฑ์๋๊ฐ ๋งก๊ณ ์๋ ์นด์นด์ค, ๊ตฌ๊ธ ์์ ๋ก๊ทธ์ธ์ ๊ตฌํ์ค์ด์๋ค.
์์ ๋ก๊ทธ์ธ ์ฑ๊ณต ์, ๋ฐฑ์๋์์ ์์ฑํ jwt ํ ํฐ ์ฟ ํค๊ฐ ๋ธ๋ผ์ฐ์ (localhost)์ ์ ์ฅ๋์ด์ผ ํ๋๋ฐ ์ ์ฅ์ด ๋๊ณ ์์ง ์์๋ค.
๐โ๏ธ ์ฒซ ๋ฒ์งธ ์๋
- ๊ฐ๋ฐ ํ๊ฒฝ
- ํ๋ก ํธ์๋
- http://localhost:5173
- window.location.href = 'http://1.11.111.11:8080/oauth2/authorization/kakao';
- ์์ ๋ก๊ทธ์ธ ๋ฒํผ ํด๋ฆญ ์, ํ์ด์ง ์ด๋
- httpํ๋กํ ์ฝ
- ์๋ฒ ์ฃผ์(์์ดํผ): 1.11.111.11:8080 (ํด๋น ์ฃผ์๋ ์ค์ ์๋ฒ ์์ดํผ๊ฐ ์๋)
- ๋ฐฑ์๋
- ์ฟ ํค ์ค์
- SameSite = lax
- secure = false
- ์ฟ ํค ์ค์
- ํ๋ก ํธ์๋
์ ํ๊ฒฝ์์ ํ ์คํธ ์, ํด๋ผ์ด์ธํธ localhost์ jwt ํ ํฐ ์ฟ ํค๊ฐ ์ ์ฅ๋์ง ์๊ณ http://1.11.111.11:8080 ์๋ฒ์ชฝ์ ์ฟ ํค๊ฐ ์ ์ฅ๋์๋ค.
๐โ๏ธ ๋ ๋ฒ์งธ ์๋
์๋ฒ์ localhost ๋๋ฉ์ธ์ด ๋ฌ๋ผ ์ฟ ํค๊ฐ ์ ์ฅ๋์ง ์๋๋ค๊ณ ์๊ฐํ๋ค. ๋ฐฑ์๋์ ์ฟ ํค ์ค์ ์ ์์ ํด๋ณด์๋ค.
- ์ฟ ํค ์ค์
- SameSite = none
- secure = true
์ฒซ ๋ฒ์งธ ์๋์ ๋ง์ฐฌ๊ฐ์ง๋ก ์๋ฒ์ชฝ์ ์ฟ ํค๊ฐ ์ ์ฅ๋์๋ค. ๋ค์ ์ค์ ๋ค๋ ํด๋ผ์ด์ธํธ์ชฝ์ผ๋ก ์ฟ ํค๊ฐ ์ ์ก๋์ง ์์๋ค.
- ํด๋ผ์ด์ธํธ localhost https ์ ์ฉ
- ๋ฐฑ์๋ ์ฟ ํค ์ค์ domain:localhost ์ง์
๐ ๊ฐ๋จํ ์ฟ ํค ์์ฑ์ ๋ํด ์์๋ณด์
- domain
- ์ฟ ํค๊ฐ ์ ์ก๋ ์ ์๋ ๋๋ฉ์ธ์ ์ง์ ํ๋ ์์ฑ
- domain=test.com์ผ๋ก ์ค์ ํ๋ฉด, test.com๊ณผ sub.test.com์์๋ ์ฟ ํค๊ฐ ์ ์ก๋๋ค.
- secure
- ์ฟ ํค๊ฐ https ์ฐ๊ฒฐ์์๋ง ์ ์ก๋๋๋ก ํ๋ค.
- HttpOnly
- ์๋ฐ์คํฌ๋ฆฝํธ๋ก ์ฟ ํค๋ฅผ ์ฝ๊ฑฐ๋ ์์ ํ ์ ์๋๋ก ํ๋ค.
- SameSite
- Strict: ์ค์ง ๊ฐ์ ์ฌ์ดํธ์์์ ์์ฒญ์๋ง ์ ์ก๋๋ค.
- lax: ๊ฐ์ ์ฌ์ดํธ์์์ ์์ฒญ ๋ฐ Get ์์ฒญ, ๋งํฌ ์ด๋ ๋ฑ์๋ ์ฟ ํค๊ฐ ์ ์ก๋๋ค. ๋จ, POST, PUT, DELETE ์์ฒญ์ ์ฟ ํค๊ฐ ์ ์ก๋์ง ์๋๋ค.
- none: ๋ชจ๋ ์ฌ์ดํธ ๊ฐ ์์ฒญ์์ ์ ์ก๋๋ค. ๋จ secure=true ์์ฑ์ด ์ค์ ๋์ผ ํ๋ค.
๐โ๏ธ ์ธ ๋ฒ์งธ ์๋(์ฑ๊ณต)
์๋ฒ ์ฃผ์๋ฅผ ์์ดํผ๊ฐ ์๋ ๋๋ฉ์ธ์ผ๋ก ์ค์ ํ๋ค. ๊ทธ ๊ฒฐ๊ณผ ๋ธ๋ผ์ฐ์ localhost์ jwt ํ ํฐ ์ฟ ํค๊ฐ ์ ์์ ์ผ๋ก ์ ์ฅ๋์๋ค.
- ๊ฐ๋ฐ ํ๊ฒฝ
- ํ๋ก ํธ์๋
- http://localhost:5173
- window.location.href = 'https://custom-domain.com/oauth2/authorization/kakao';
- ์์ดํผ ์ฃผ์๊ฐ ์๋ ๋๋ฉ์ธ์ผ๋ก ๋ณ๊ฒฝ
- ๋ฐฑ์๋
- ์ฟ ํค ์ค์
- SameSite = lax
- secure = true
- ์ฟ ํค ์ค์
- ํ๋ก ํธ์๋
๐ค ์ฒซ ๋ฒ์งธ ์๋์์๋ ์ ์ฟ ํค๋ฅผ ์ ๋ฌ๋ฐ์ง ๋ชปํ์๊น?
๋จผ์ localhost๋ ํน์ํ ๋๋ฉ์ธ์ผ๋ก ๊ฐ์ฃผ๋๋ค. SameSite๊ฐ lax ๋๋ strict๋ก ์ค์ ๋ ๊ฒฝ์ฐ, ์ผ๋ถ ๋ธ๋ผ์ฐ์ localhost๋ ์๋ฒ์์ ๋ณด๋ด์ค ์ฟ ํค๋ฅผ ์ ์ฅํ ์ ์๋ค. ๋ํ, secure=true๋ก ์ค์ ๋์์ด๋ https๊ฐ ์๋ http ํ๊ฒฝ์์ secure ์ฟ ํค๊ฐ ๋์ํ ์ ์๋ค. (firefox์ ๊ฒฝ์ฐ strict๋ก ์ค์ ๋ ๊ฒฝ์ฐ ์ฟ ํค๊ฐ ์ ์ฅ๋์ง ์์๋ค.)
localhost๊ฐ ๋ณด์ ์ ์ฑ ์์ ์กฐ๊ธ ๋์จํ๋ค๋ฉด, ์ฒซ ๋ฒ์งธ ์๋์์ ์ฟ ํค๋ localhost์ ์ ์ฅ๋์ด์ผ ํ๋ค. ํ์ง๋ง ์ ์ฅ๋์ง ์์๋๋ฐ ์ด ์ด์ ๋ฅผ gpt๋ ๋ค์๊ณผ ๊ฐ์ด ๋ตํ๋ค.(100% ์ ๋ขฐํ์ง ๋ง์ธ์!)
- ๋ธ๋ผ์ฐ์ ๋ IP ์ฃผ์์ ๋๋ฉ์ธ ์ด๋ฆ์ ๋ค๋ฅด๊ฒ ์ฒ๋ฆฌํ ์ ์์ต๋๋ค.
- IP ์ฃผ์๋ก ์ ์ํ์ ๋์ ์ ์์ ์ธ ๋๋ฉ์ธ ์ด๋ฆ์ผ๋ก ์ ์ํ์ ๋ ๋ธ๋ผ์ฐ์ ๋ ์ฟ ํค์ SameSite, Secure ์์ฑ์ ๋ค๋ฅด๊ฒ ์ ์ฉํ ์ ์์ต๋๋ค.
- ํนํ, ๋๋ฉ์ธ ์ด๋ฆ์ด ์๋ IP ์ฃผ์๋ก ์ ๊ทผํ๋ฉด ์ฟ ํค๊ฐ SameSite=Strict๋ SameSite=Lax ์ค์ ์์ ์ฟ ํค ์ ์ก์ด ์ฐจ๋จ๋ ๊ฐ๋ฅ์ฑ์ด ๋ ๋์ต๋๋ค.
- IP ์ฃผ์๋ ๋ธ๋ผ์ฐ์ ์ ๋ณด์ ๋ชจ๋ธ์์ ๋๋ฉ์ธ์ฒ๋ผ ์ ๋ขฐ๋์ง ์์ ์ ์์ผ๋ฉฐ, ํนํ ๋ณด์ ์ฟ ํค ์ ์ฑ ์ด ๋ ์๊ฒฉํ๊ฒ ์ ์ฉ๋ ์ ์์ต๋๋ค.
๋ธ๋ผ์ฐ์ ์ ์ฑ ์ IP ์ฃผ์(http://1.11.111.11:8080/oauth2/authorization/kakao)๋ก ์ ๊ทผํ์ฌ ์ฟ ํค ์ ์ก์ด ์ฐจ๋จ๋ ๊ฑธ๋ก ๋ณด์ธ๋ค.
๐ค ๋ ๋ฒ์งธ ์๋์์๋ ์ ์ฟ ํค๋ฅผ ์ ๋ฌ๋ฐ์ง ๋ชปํ์๊น?
SameSite = None์ผ๋ก ์ค์ ํ์ฌ ๋ชจ๋ ์ฌ์ดํธ๊ฐ ์ฟ ํค๊ฐ ์ ์ก๋์ง๋ง, http ํ๋กํ ์ฝ์ ์ฌ์ฉํ๋ ๋ฐฑ์๋(http://1.11.111.11:8080)๊ฐ secure = true ์ฟ ํค ์ค์ ์ด ๋์ด ์์ด ์ ์ก๋์ง ์์๋ค.
๐งฉ ์ผ์ด์ค ์ ๋ฆฌ
- window.location.href = http://1.11.111.11:8080~~~
- SameSite = lax, secure = false: 1.11.111.11 ์๋ฒ์ jwt ํ ํฐ ์ฟ ํค ์ ์ฅ (localhost๋ก ์ ์ก X)
- SameSite = none, secure = true: 1.11.111.11 ์๋ฒ์ jwt ํ ํฐ ์ฟ ํค ์ ์ฅ (localhost๋ก ์ ์ก X)
- window.location.href = 'https://custom-domain~~~
- SameSite = lax, secure = false: localhost์ jwt ํ ํฐ ์ฟ ํค ์ ์ฅ
- SameSite = lax, secure = true: localhost์ jwt ํ ํฐ ์ฟ ํค ์ ์ฅ
- SameSite = none, secure = true: localhost์ jwt ํ ํฐ ์ฟ ํค ์ ์ฅ