core: allowCors option for Handler

This commit is contained in:
undefined committed 2023-02-15 15:06:32 +08:00
1 parent c347d36e99
commit cafe9246c2
2 files changed
+10 -9

No files matched your search

+2 -6
View File
@@ -1,4 +1,4 @@
import { CsrfTokenError, NotFoundError } from '../../error';
import { NotFoundError } from '../../error';
import avatar from '../../lib/avatar';
import { PERM } from '../../model/builtin';
import UserModel from '../../model/user';
@@ -6,7 +6,7 @@ import type { KoaContext } from '../server';
export default async (ctx: KoaContext, next) => {
// User Layer
const { request, args, domain } = ctx.HydroContext;
const { args, domain } = ctx.HydroContext;
const domainId = domain ? args.domainId : 'system';
let user = await UserModel.getById(domainId, ctx.session.uid, ctx.session.scope);
if (!user) {
@@ -21,9 +21,5 @@ export default async (ctx: KoaContext, next) => {
ctx.pendingError = new NotFoundError(args.domainId);
args.domainId = 'system';
}
if (request.method === 'post' && request.headers.referer && !ctx.cors) {
const host = new URL(request.headers.referer).host;
if (host !== request.host) ctx.pendingError = new CsrfTokenError(host);
}
await next();
};