From 38ca97f3baee4161e2d28f972dc54c27e2da6ee0 Mon Sep 17 00:00:00 2001 From: luorijun Date: Tue, 22 Apr 2025 11:31:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=20cookie=20=E7=9A=84=20secur?= =?UTF-8?q?e=20=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 1 - src/actions/auth/auth.ts | 9 --------- src/actions/auth/verify.ts | 4 ---- src/actions/base.ts | 2 -- src/app/(auth)/captcha/route.ts | 2 -- 5 files changed, 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index c909355..3cfe410 100644 --- a/Dockerfile +++ b/Dockerfile @@ -31,7 +31,6 @@ RUN pnpm run build FROM base AS runner WORKDIR /app -ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 RUN addgroup --system --gid 1001 nodejs diff --git a/src/actions/auth/auth.ts b/src/actions/auth/auth.ts index a0d81f4..fc5eb28 100644 --- a/src/actions/auth/auth.ts +++ b/src/actions/auth/auth.ts @@ -40,25 +40,21 @@ export async function login(props: LoginParams): Promise { cookieStore.set('auth_token', data.access_token, { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: Math.max(future, 0), }) cookieStore.set('auth_refresh', data.refresh_token, { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: 7 * 24 * 3600, }) cookieStore.set('auth_info', JSON.stringify(data.auth), { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: 7 * 24 * 3600, }) cookieStore.set('auth_profile', JSON.stringify(data.profile), { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: 7 * 24 * 3600, }) @@ -85,25 +81,21 @@ export async function logout() { cookieStore.set('auth_token', '', { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: -1, }) cookieStore.set('auth_refresh', '', { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: -1, }) cookieStore.set('auth_info', '', { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: -1, }) cookieStore.set('auth_profile', '', { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: -1, }) @@ -140,7 +132,6 @@ export async function getProfile(refresh: boolean = false) { cookie.set('auth_profile', JSON.stringify(result.data), { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: 7 * 24 * 3600, }) diff --git a/src/actions/auth/verify.ts b/src/actions/auth/verify.ts index ab98fd7..bbe456e 100644 --- a/src/actions/auth/verify.ts +++ b/src/actions/auth/verify.ts @@ -1,5 +1,4 @@ 'use server' -// 验证验证码函数 import {cookies} from 'next/headers' import crypto from 'crypto' import {ApiResponse} from '@/lib/api' @@ -43,8 +42,6 @@ export default async function verify(props: VerifyParams): Promise } async function verifyCaptcha(userInput: string): Promise { - console.log("验证验证码:", userInput) - const cookieStore = await cookies() const hash = cookieStore.get('captcha_hash')?.value const salt = cookieStore.get('captcha_salt')?.value @@ -63,7 +60,6 @@ async function verifyCaptcha(userInput: string): Promise { // 比较哈希值 const isValid = hash === userInputHash - console.log('验证码验证结果:', isValid, hash, userInputHash) // 验证后删除验证码cookie,防止重复使用 if (isValid) { diff --git a/src/actions/base.ts b/src/actions/base.ts index cdd4f7b..81aec09 100644 --- a/src/actions/base.ts +++ b/src/actions/base.ts @@ -156,13 +156,11 @@ async function getUserToken(refresh = false): Promise { cookie.set('auth_token', nextAccessToken, { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: Math.max(expiresIn, 0), }) cookie.set('auth_refresh', nextRefreshToken, { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: 7 * 24 * 3600, // 7天 }) diff --git a/src/app/(auth)/captcha/route.ts b/src/app/(auth)/captcha/route.ts index 55ac513..44601ee 100644 --- a/src/app/(auth)/captcha/route.ts +++ b/src/app/(auth)/captcha/route.ts @@ -73,13 +73,11 @@ export async function GET(request: Request) { .set('captcha_hash', hash, { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: 60, }) .set('captcha_salt', salt, { httpOnly: true, sameSite: 'strict', - secure: process.env.NODE_ENV === 'production', maxAge: 60, })