mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fix problems found by deepscan.io
This commit is contained in:
1 parent
e8dcd97561
commit
dd4ecdb029
13 files changed
+33
-29
No files matched your search
@@ -323,8 +323,8 @@ export class ProblemPretestConnectionHandler extends ConnectionHandler {
|
||||
@param('pid', Types.String)
|
||||
async prepare(domainId: string, pid: string) {
|
||||
const pdoc = await problem.get(domainId, pid);
|
||||
if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
if (!pdoc) throw new ProblemNotFoundError(domainId, pid);
|
||||
if (pdoc.hidden) this.checkPerm(PERM.PERM_VIEW_PROBLEM_HIDDEN);
|
||||
this.pid = pdoc.docId.toString();
|
||||
this.domainId = domainId;
|
||||
this.dispose = bus.on('record/change', this.onRecordChange.bind(this));
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
import { Readable, Writable } from 'stream';
|
||||
import { ObjectID } from 'mongodb';
|
||||
import fs from 'fs';
|
||||
import { Dictionary, NumericDictionary } from 'lodash';
|
||||
import type { Readable, Writable } from 'stream';
|
||||
import type { ObjectID } from 'mongodb';
|
||||
import type fs from 'fs';
|
||||
import type { Dictionary, NumericDictionary } from 'lodash';
|
||||
import type { Pdoc } from './model/problem';
|
||||
|
||||
type document = typeof import('./model/document');
|
||||
|
||||
@@ -55,8 +55,8 @@ export async function getWithSecret(_id: ObjectID, secret: string, reject?: Func
|
||||
const file = await coll.findOne({ _id });
|
||||
if (!file) throw new NotFoundError(_id);
|
||||
const timestamp = _timestamp();
|
||||
if (!(hash(file.secret, timestamp.toString()) === secret)) {
|
||||
if (!(hash(file.secret, (timestamp - 1).toString()) === secret)) {
|
||||
if (hash(file.secret, timestamp.toString()) !== secret) {
|
||||
if (hash(file.secret, (timestamp - 1).toString()) !== secret) {
|
||||
throw new ForbiddenError();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ export async function judge(domainId: string, rid: ObjectID) {
|
||||
if (rdoc.pid) {
|
||||
const pdoc = await problem.get(domainId, rdoc.pid);
|
||||
if (!config) config = pdoc?.config || {};
|
||||
data = pdoc.data;
|
||||
data = pdoc?.data;
|
||||
}
|
||||
delete rdoc._id;
|
||||
await task.add({
|
||||
|
||||
@@ -129,7 +129,7 @@ export class User implements _User {
|
||||
checkPassword(password: string) {
|
||||
const h = global.Hydro.lib[`hash.${this.hashType}`];
|
||||
if (!h) throw new Error('Unknown hash method');
|
||||
if (!(h(password, this.salt(), this) === this.hash())) {
|
||||
if (h(password, this.salt(), this) !== this.hash()) {
|
||||
throw new LoginError(this.uname);
|
||||
} else if (this.hashType !== 'hydro') {
|
||||
setPassword(this._id, password);
|
||||
|
||||
@@ -440,8 +440,7 @@ export class Handler {
|
||||
args.domainId = args.domainId || this.domainId;
|
||||
}
|
||||
const { anchor } = args;
|
||||
if (query) res = router.url(name, args, { query });
|
||||
else res = router.url(name, args);
|
||||
res = router.url(name, args, { query });
|
||||
if (anchor) return `${res}#${anchor}`;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
@@ -563,10 +562,8 @@ export class Handler {
|
||||
this.ctx.response.status = 302;
|
||||
this.ctx.redirect(this.response.redirect);
|
||||
} else {
|
||||
if (this.response.body != null) {
|
||||
this.ctx.response.body = this.response.body;
|
||||
this.ctx.response.status = this.response.status || 200;
|
||||
}
|
||||
this.ctx.response.body = this.response.body;
|
||||
this.ctx.response.status = this.response.status || 200;
|
||||
this.ctx.response.type = this.request.json
|
||||
? 'application/json'
|
||||
: this.response.type
|
||||
@@ -683,7 +680,7 @@ const Checker = (permPrivChecker) => {
|
||||
if (typeof item === 'object') {
|
||||
if (typeof item.call !== 'undefined') {
|
||||
checker = item;
|
||||
} if (typeof item[0] === 'number') {
|
||||
} else if (typeof item[0] === 'number') {
|
||||
priv = item;
|
||||
} else if (typeof item[0] === 'bigint') {
|
||||
perm = item;
|
||||
@@ -772,18 +769,22 @@ export class ConnectionHandler {
|
||||
url(name: string, kwargs: any = {}) {
|
||||
let res = '#';
|
||||
const args: any = {};
|
||||
const query: any = {};
|
||||
for (const key in kwargs) {
|
||||
if (kwargs[key] instanceof ObjectID) args[key] = kwargs[key].toHexString();
|
||||
else args[key] = kwargs[key].toString();
|
||||
}
|
||||
for (const key in kwargs.query || {}) {
|
||||
if (query[key] instanceof ObjectID) query[key] = kwargs.query[key].toHexString();
|
||||
else query[key] = kwargs.query[key].toString();
|
||||
}
|
||||
try {
|
||||
if (this.args.domainId !== 'system' || args.domainId) {
|
||||
name += '_with_domainId';
|
||||
args.domainId = args.domainId || this.args.domainId;
|
||||
}
|
||||
const { anchor, query } = args;
|
||||
if (query) res = router.url(name, args, { query });
|
||||
else res = router.url(name, args);
|
||||
const { anchor } = args;
|
||||
res = router.url(name, args, { query });
|
||||
if (anchor) return `${res}#${anchor}`;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
|
||||
Reference in new issue
Block a user