mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +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();
|
||||
};
|
||||
@@ -185,6 +185,7 @@ export class Handler extends HandlerCommon {
|
||||
icon: global.Hydro.module.oauth[key].icon,
|
||||
text: global.Hydro.module.oauth[key].text,
|
||||
}));
|
||||
if (this.context.pendingError) throw this.context.pendingError;
|
||||
}
|
||||
|
||||
async onerror(error: HydroError) {
|
||||
|
||||
Reference in new issue
Block a user