mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 01:47:47 +08:00
feat(security): harden gateway boundaries and usage policies
Consolidate subscription usage policy enforcement, privacy-safe persistence, and gateway security hardening into one reviewable change. Includes bounded HTTP and execution envelopes, header and protocol guards, DNS and relay validation, authentication and secret projection hardening, secure backup/install paths, and regression coverage.
This commit is contained in:
@@ -267,6 +267,7 @@ import { getApiUrl } from '@/utils/url'
|
||||
import { getOAuthIcon } from '@/utils/oauth-icons'
|
||||
import { navigateAfterLogin } from '@/features/auth/utils/loginRedirect'
|
||||
import { useI18n } from '@/i18n'
|
||||
import { safeInternalNavigationPath } from '@/utils/navigationSecurity'
|
||||
|
||||
const props = defineProps<{
|
||||
modelValue: boolean
|
||||
@@ -401,10 +402,8 @@ function consumeStoredRedirectPath(): string | null {
|
||||
if (redirectPath) {
|
||||
sessionStorage.removeItem('redirectPath')
|
||||
}
|
||||
if (!redirectPath || redirectPath === '/' || !redirectPath.startsWith('/') || redirectPath.startsWith('//')) {
|
||||
return null
|
||||
}
|
||||
return redirectPath
|
||||
const safePath = safeInternalNavigationPath(redirectPath)
|
||||
return safePath === '/' ? null : safePath
|
||||
}
|
||||
|
||||
function handleOAuthLogin(providerType: string) {
|
||||
|
||||
@@ -503,6 +503,7 @@ const isLoading = ref(false)
|
||||
const loadingText = ref(t('auth.register.submit'))
|
||||
const isSendingCode = ref(false)
|
||||
const emailVerified = ref(false)
|
||||
const emailVerificationToken = ref('')
|
||||
const verificationError = ref(false)
|
||||
const codeSentAt = ref<number | null>(null)
|
||||
const cooldownSeconds = ref(0)
|
||||
@@ -643,10 +644,10 @@ const canSubmit = computed(() => {
|
||||
|
||||
// 查询并恢复验证状态
|
||||
const checkAndRestoreVerificationStatus = async (email: string) => {
|
||||
if (!email || !props.requireEmailVerification) return
|
||||
if (!email || !props.requireEmailVerification || !emailVerificationToken.value) return
|
||||
|
||||
try {
|
||||
const status = await authApi.getVerificationStatus(email)
|
||||
const status = await authApi.getVerificationStatus(email, emailVerificationToken.value)
|
||||
|
||||
// 注意:不恢复 is_verified 状态
|
||||
// 刷新页面后需要重新发送验证码并验证,防止验证码被他人使用
|
||||
@@ -675,6 +676,7 @@ watch(
|
||||
// 邮箱变化时重置验证状态
|
||||
if (newEmail !== oldEmail) {
|
||||
emailVerified.value = false
|
||||
emailVerificationToken.value = ''
|
||||
verificationError.value = false
|
||||
codeSentAt.value = null
|
||||
cooldownSeconds.value = 0
|
||||
@@ -751,6 +753,7 @@ const resetForm = () => {
|
||||
verificationCode: ''
|
||||
}
|
||||
emailVerified.value = false
|
||||
emailVerificationToken.value = ''
|
||||
verificationError.value = false
|
||||
isSendingCode.value = false
|
||||
codeSentAt.value = null
|
||||
@@ -795,6 +798,7 @@ const handleSendCode = async () => {
|
||||
)
|
||||
|
||||
if (response.success) {
|
||||
emailVerificationToken.value = response.verification_token
|
||||
resetTurnstile()
|
||||
codeSentAt.value = Date.now()
|
||||
if (response.expire_minutes) {
|
||||
@@ -834,7 +838,16 @@ const handleCodeComplete = async (code: string) => {
|
||||
verificationError.value = false
|
||||
|
||||
try {
|
||||
const response = await authApi.verifyEmail(formData.value.email, code)
|
||||
if (!emailVerificationToken.value) {
|
||||
verificationError.value = true
|
||||
showError(t('auth.register.codeRetry'), t('auth.register.verifyFailed'))
|
||||
return
|
||||
}
|
||||
const response = await authApi.verifyEmail(
|
||||
formData.value.email,
|
||||
code,
|
||||
emailVerificationToken.value
|
||||
)
|
||||
|
||||
if (response.success) {
|
||||
emailVerified.value = true
|
||||
@@ -899,6 +912,9 @@ const handleSubmit = async () => {
|
||||
if (formData.value.email && formData.value.email.trim()) {
|
||||
registerData.email = formData.value.email
|
||||
}
|
||||
if (props.requireEmailVerification && emailVerificationToken.value) {
|
||||
registerData.email_verification_token = emailVerificationToken.value
|
||||
}
|
||||
if (turnstileRequired.value && currentTurnstileAction.value === 'register') {
|
||||
registerData.turnstile_token = turnstileToken.value
|
||||
}
|
||||
|
||||
@@ -161,6 +161,7 @@ beforeEach(() => {
|
||||
success: true,
|
||||
message: 'ok',
|
||||
expire_minutes: 5,
|
||||
verification_token: 'verification-session-token',
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -147,6 +147,7 @@ describe('RegisterDialog Turnstile flow', () => {
|
||||
success: true,
|
||||
message: 'ok',
|
||||
expire_minutes: 5,
|
||||
verification_token: 'verification-session-token',
|
||||
})
|
||||
toastErrorMock.mockReset()
|
||||
toastSuccessMock.mockReset()
|
||||
|
||||
Reference in New Issue
Block a user