mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: handle CsrfTokenError and DomainNotFoundError
This commit is contained in:
1 parent
00f83d805a
commit
3371f39ef4
2 files changed
+6
-2
No files matched your search
@@ -17,10 +17,13 @@ export default async (ctx: KoaContext, next) => {
|
||||
if (user._id === 0) delete user.viewLang;
|
||||
user.avatarUrl = avatar(user.avatar, 128);
|
||||
ctx.HydroContext.user = user;
|
||||
if (!domain) throw new NotFoundError(args.domainId);
|
||||
if (!domain) {
|
||||
ctx.pendingError = new NotFoundError(args.domainId);
|
||||
args.domainId = 'system';
|
||||
}
|
||||
if (request.method === 'post' && request.headers.referer) {
|
||||
const host = new URL(request.headers.referer).host;
|
||||
if (host !== request.host) throw new CsrfTokenError(host);
|
||||
if (host !== request.host) ctx.pendingError = new CsrfTokenError(host);
|
||||
}
|
||||
await next();
|
||||
};
|
||||
Reference in new issue
Block a user