core: fix csrf

This commit is contained in:
undefined committed 2021-05-07 08:21:16 +08:00
1 parent 92b2535b89
commit fc98c61f7b
2 files changed
+5 -5

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "2.24.18",
"version": "2.24.19",
"bin": "bin/hydrooj.js",
"main": "dist/loader.js",
"typings": "dist/loader.d.ts",
+4 -4
View File
@@ -482,10 +482,6 @@ export class Handler extends HandlerCommon {
}
async init({ domainId }) {
if (this.request.headers.referer) {
const hostname = new URL(this.request.headers.referer).hostname;
if (hostname !== this.request.hostname) throw new CsrfTokenError();
}
if (!argv.benchmark) await this.limitRate('global', 10, 88);
const [absoluteDomain, inferDomain, bdoc] = await Promise.all([
domain.get(domainId),
@@ -524,6 +520,10 @@ export class Handler extends HandlerCommon {
text: global.Hydro.lib[key].text,
}));
if (!this.noCheckPermView) this.checkPerm(PERM.PERM_VIEW);
if (this.request.method === 'POST' && this.request.headers.referer) {
const hostname = new URL(this.request.headers.referer).hostname;
if (hostname !== this.request.hostname) throw new CsrfTokenError(hostname);
}
}
async finish() {