-
Notifications
You must be signed in to change notification settings - Fork 0
[app] 실수로 디벨롭 제외하고 메인에 머지함 #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1656e04
Merge pull request #29 from Early-Employment/develop
Dino0204 482ecc9
fix(app): DataGSM 로그인 리다이렉트 경로 수정
tlrdmsEjrqhRdl f521fe1
chore(global): 폰트 및 미들웨어 경고 정리
tlrdmsEjrqhRdl 3da6aef
Merge pull request #30 from Early-Employment/fix/redirect
tlrdmsEjrqhRdl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import { createHash, randomBytes } from "node:crypto"; | ||
| import { NextResponse } from "next/server"; | ||
|
|
||
| const DATAGSM_AUTHORIZE_URL = "https://oauth.authorization.datagsm.kr/v1/oauth/authorize"; | ||
| const OAUTH_CALLBACK_PATH = "/oauth/callback"; | ||
| const OAUTH_COOKIE_MAX_AGE_SECONDS = 60 * 5; | ||
|
|
||
| function createPkceCodeVerifier() { | ||
| return randomBytes(64).toString("base64url"); | ||
| } | ||
|
|
||
| function createPkceCodeChallenge(codeVerifier: string) { | ||
| return createHash("sha256").update(codeVerifier).digest("base64url"); | ||
| } | ||
|
|
||
| function createState() { | ||
| return randomBytes(32).toString("base64url"); | ||
| } | ||
|
|
||
| export async function GET(request: Request) { | ||
| const clientId = process.env.NEXT_PUBLIC_DATAGSM_CLIENT_ID; | ||
|
|
||
| if (!clientId) { | ||
| return NextResponse.json( | ||
| { message: "NEXT_PUBLIC_DATAGSM_CLIENT_ID is not configured." }, | ||
| { status: 500 }, | ||
| ); | ||
| } | ||
|
|
||
| const requestUrl = new URL(request.url); | ||
| const redirectUri = new URL(OAUTH_CALLBACK_PATH, requestUrl.origin).toString(); | ||
| const state = createState(); | ||
| const codeVerifier = createPkceCodeVerifier(); | ||
| const codeChallenge = createPkceCodeChallenge(codeVerifier); | ||
|
|
||
| const authorizeUrl = new URL(DATAGSM_AUTHORIZE_URL); | ||
| authorizeUrl.searchParams.set("client_id", clientId); | ||
| authorizeUrl.searchParams.set("redirect_uri", redirectUri); | ||
| authorizeUrl.searchParams.set("response_type", "code"); | ||
| authorizeUrl.searchParams.set("state", state); | ||
| authorizeUrl.searchParams.set("code_challenge", codeChallenge); | ||
| authorizeUrl.searchParams.set("code_challenge_method", "S256"); | ||
|
|
||
| const response = NextResponse.redirect(authorizeUrl); | ||
|
|
||
| response.cookies.set("dg_oauth_state", state, { | ||
| httpOnly: true, | ||
| maxAge: OAUTH_COOKIE_MAX_AGE_SECONDS, | ||
| path: "/auth/dg", | ||
| sameSite: "lax", | ||
| }); | ||
| response.cookies.set("dg_oauth_code_verifier", codeVerifier, { | ||
| httpOnly: true, | ||
| maxAge: OAUTH_COOKIE_MAX_AGE_SECONDS, | ||
| path: "/auth/dg", | ||
| sameSite: "lax", | ||
| }); | ||
| response.cookies.set("dg_oauth_redirect_uri", redirectUri, { | ||
| httpOnly: true, | ||
| maxAge: OAUTH_COOKIE_MAX_AGE_SECONDS, | ||
| path: "/auth/dg", | ||
| sameSite: "lax", | ||
| }); | ||
|
Comment on lines
+46
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 OAuth 보안 쿠키에
|
||
|
|
||
| return response; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 프록시 환경에서 잘못된 Redirect URI 생성 위험
현재
request.url에서 직접origin을 추출하여redirectUri를 생성하고 있습니다.Next.js 애플리케이션이 Vercel, Docker, Nginx 등의 리버스 프록시 뒤에서 실행되는 경우,
request.url은 실제 클라이언트가 접속한 도메인이 아닌 내부 주소(예:http://localhost:3000또는 내부 IP)를 가질 수 있습니다. 이로 인해 OAuth 인증 서버로 잘못된redirect_uri가 전달되어 로그인 흐름이 완전히 깨질 수 있습니다.이를 방지하기 위해
x-forwarded-host및x-forwarded-proto헤더를 참조하여 동적으로 올바른 외부 Origin을 구성하는 것이 안전합니다.