core: better user_file permission control

This commit is contained in:
undefined committed 2022-01-26 23:22:08 +08:00
1 parent 17cab51f5f
commit 2efb0e6281
3 files changed
+8 -4

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "3.3.18", "version": "3.3.19",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+5 -1
View File
@@ -28,6 +28,7 @@ class SwitchLanguageHandler extends Handler {
export class FilesHandler extends Handler { export class FilesHandler extends Handler {
@param('pjax', Types.Boolean) @param('pjax', Types.Boolean)
async get(domainId: string, pjax = false) { async get(domainId: string, pjax = false) {
if (!this.user._files?.length) this.checkPriv(PRIV.PRIV_CREATE_FILE);
const files = sortFiles(this.user._files); const files = sortFiles(this.user._files);
if (pjax) { if (pjax) {
this.response.body = { this.response.body = {
@@ -44,6 +45,7 @@ export class FilesHandler extends Handler {
@post('filename', Types.Name, true) @post('filename', Types.Name, true)
async postUploadFile(domainId: string, filename: string) { async postUploadFile(domainId: string, filename: string) {
this.checkPriv(PRIV.PRIV_CREATE_FILE);
if ((this.user._files?.length || 0) >= system.get('limit.user_files')) { if ((this.user._files?.length || 0) >= system.get('limit.user_files')) {
throw new ForbiddenError('File limit exceeded.'); throw new ForbiddenError('File limit exceeded.');
} }
@@ -87,6 +89,8 @@ export class FSDownloadHandler extends Handler {
@param('filename', Types.Name) @param('filename', Types.Name)
@param('noDisposition', Types.Boolean) @param('noDisposition', Types.Boolean)
async get(domainId: string, uid: number, filename: string, noDisposition = false) { async get(domainId: string, uid: number, filename: string, noDisposition = false) {
const targetUser = await user.getById('system', uid);
if (!targetUser.hasPriv(PRIV.PRIV_CREATE_FILE)) throw new ForbiddenError('Access denied');
this.response.addHeader('Cache-Control', 'public'); this.response.addHeader('Cache-Control', 'public');
const target = `user/${uid}/${filename}`; const target = `user/${uid}/${filename}`;
const file = await storage.getMeta(target); const file = await storage.getMeta(target);
@@ -110,7 +114,7 @@ export class SwitchAccountHandler extends Handler {
export async function apply() { export async function apply() {
Route('switch_language', '/language/:lang', SwitchLanguageHandler); Route('switch_language', '/language/:lang', SwitchLanguageHandler);
Route('home_files', '/file', FilesHandler, PRIV.PRIV_CREATE_FILE); Route('home_files', '/file', FilesHandler);
Route('fs_download', '/file/:uid/:filename', FSDownloadHandler); Route('fs_download', '/file/:uid/:filename', FSDownloadHandler);
Route('switch_account', '/account', SwitchAccountHandler, PRIV.PRIV_EDIT_SYSTEM); Route('switch_account', '/account', SwitchAccountHandler, PRIV.PRIV_EDIT_SYSTEM);
} }
+2 -2
View File
@@ -11,8 +11,8 @@ import {
ValidationError, ValidationError,
} from '../error'; } from '../error';
import { import {
ProblemConfig, ProblemDoc, ProblemStatusDoc, ProblemDoc, ProblemStatusDoc, Tdoc,
Tdoc, User, User,
} from '../interface'; } from '../interface';
import paginate from '../lib/paginate'; import paginate from '../lib/paginate';
import { isPid, parsePid as convertPid } from '../lib/validator'; import { isPid, parsePid as convertPid } from '../lib/validator';