-
Notifications
You must be signed in to change notification settings - Fork 6.7k
feat: csrf, two tokens verify #5692
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
base: test/html
Are you sure you want to change the base?
Conversation
Preview sandbox Image:
|
Preview fastgpt Image:
|
e7d6534
to
151237e
Compare
Preview mcp_server Image:
|
@@ -0,0 +1,32 @@ | |||
import type { NextApiRequest, NextApiResponse } from 'next'; | |||
import { verifyCsrfToken } from '../../support/permission/auth/common'; | |||
import { generateCsrfToken } from '../../../../projects/app/src/web/support/user/api'; |
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.
verifyCsrfToken 和 generateCsrfToken 应该放在一个模块里面
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.
前端检测到cookie即将过期, 要主动请求generateCsrfToken, 所以generateCsrfToken放在了api模块, 便于请求; verifyCsrfToken则放在中间件模块用于验证CsrfToken
|
||
try { | ||
const csrfToken = await getCsrfTokenFromRequest(req); | ||
verifyCsrfToken(csrfToken || ''); |
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.
参数能接受 undefined 不就行了
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.
done
}; | ||
|
||
const isTokenValid = (expiresAt: number): boolean => { | ||
const currentTime = Math.floor(Date.now() / 1000); |
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.
怎么还 /1000,直接比较 timestamp 不就行了吗
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.
jwt标准是用秒级时间戳来生成签名, 这里 /1000 是为与jwt的秒级别统一
No description provided.