core: add server.url check

This commit is contained in:
undefined committed 2021-08-01 17:48:55 +08:00
1 parent e8d0881082
commit 998248e212
4 files changed
+11 -12

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.30.9", "version": "2.30.10",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",
+4 -6
View File
@@ -22,11 +22,7 @@ const checks: Dictionary<CheckItem> = {
error(`Mongo Error: Database read-write failed.\n${e.message}`); error(`Mongo Error: Database read-write failed.\n${e.message}`);
} }
}, },
async checkPerm(ctx, log, warn) { // TODO check storage
const { username } = os.userInfo();
if (username === 'root') warn('Hydro should not be run as root.');
// TODO check cwd read-write
},
async checkSystem(ctx, log, warn) { async checkSystem(ctx, log, warn) {
const platform = os.platform(); const platform = os.platform();
if (platform !== 'linux') { if (platform !== 'linux') {
@@ -37,7 +33,9 @@ const checks: Dictionary<CheckItem> = {
const from = system.get('smtp.from'); const from = system.get('smtp.from');
if (!from) warn('SMTP account was not provided, email verification disabled.'); if (!from) warn('SMTP account was not provided, email verification disabled.');
}, },
async checkIpHeader(ctx, log, warn) { async checkSetting(ctx, log, warn) {
const url = system.get('server.url');
if (url === '/') warn("server.url wasn't set.");
const header = system.get('server.xff'); const header = system.get('server.xff');
if (header && !ctx.request.ip) warn('IP header seems incorrect.\nCheck dashboard>settings>server.'); if (header && !ctx.request.ip) warn('IP header seems incorrect.\nCheck dashboard>settings>server.');
}, },
+2 -2
View File
@@ -386,7 +386,7 @@ export class Handler extends HandlerCommon {
args: any; args: any;
ctx: Koa.Context; ctx: Koa.Context;
request: { declare request: {
method: string, method: string,
host: string, host: string,
hostname: string, hostname: string,
@@ -747,7 +747,7 @@ export function Route(name: string, path: string, RouteHandler: any, ...permPriv
export class ConnectionHandler extends HandlerCommon { export class ConnectionHandler extends HandlerCommon {
conn: sockjs.Connection; conn: sockjs.Connection;
args: Record<string, any>; args: Record<string, any>;
request: { declare request: {
params: Record<string, any>; params: Record<string, any>;
headers: Record<string, string>; headers: Record<string, string>;
ip: string; ip: string;
+4 -3
View File
@@ -193,13 +193,14 @@ class StorageService {
async signDownloadLink(target: string, filename?: string, noExpire = false, useAlternativeEndpointFor?: 'user' | 'judge'): Promise<string> { async signDownloadLink(target: string, filename?: string, noExpire = false, useAlternativeEndpointFor?: 'user' | 'judge'): Promise<string> {
if (target.includes('..') || target.includes('//')) throw new Error('Invalid path'); if (target.includes('..') || target.includes('//')) throw new Error('Invalid path');
try { try {
const headers = {};
if (filename) headers['response-content-disposition'] = `attachment; filename="${encodeRFC5987ValueChars(filename)}"`;
if (/\.(jpe?g|png|gif)$/i.test(target)) headers['cache-control'] = 'max-age=604800';
const url = await this.client.presignedGetObject( const url = await this.client.presignedGetObject(
this.opts.bucket, this.opts.bucket,
target, target,
noExpire ? 24 * 60 * 60 * 7 : 30 * 60, noExpire ? 24 * 60 * 60 * 7 : 30 * 60,
filename headers,
? { 'response-content-disposition': `attachment; filename="${encodeRFC5987ValueChars(filename)}"` }
: {},
); );
if (useAlternativeEndpointFor) return this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor](url); if (useAlternativeEndpointFor) return this.replaceWithAlternativeUrlFor[useAlternativeEndpointFor](url);
return url; return url;