core: handle CsrfTokenError and DomainNotFoundError

pull/462/head
undefined 2 years ago
parent 00f83d805a
commit 3371f39ef4

@ -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) {

Loading…
Cancel
Save