Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ MAX_PORT=
# File uploads
UPLOADS_DIR=
BIN_UPLOADS_DIR=
PUBLIC_MAX_UPLOAD_SIZE_MB=50

FLAG_ENCRYPTION_KEY=

Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ RUN bun install --frozen-lockfile && \
bun run build

FROM nginx:latest
RUN apt-get update && apt-get install -y supervisor net-tools && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y supervisor net-tools gettext-base && rm -rf /var/lib/apt/lists/*
COPY --from=build /usr/local/bin/bun /usr/local/bin/bun

# prepare necessary directories
RUN mkdir -p /app

# replace nginx config file
COPY khi.conf /etc/nginx/conf.d/default.conf
COPY khi.conf.template /etc/nginx/khi.conf.template

WORKDIR /app
COPY --from=build /app/build ./build
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ services:
UPLOADS_DIR: /app/uploads
BIN_UPLOADS_DIR: /app/ctf
JAIL_CONF_DIR: /app/nsjail_confs


PUBLIC_MAX_UPLOAD_SIZE_MB: ${PUBLIC_MAX_UPLOAD_SIZE_MB:-50}
BODY_SIZE_LIMIT: ${PUBLIC_MAX_UPLOAD_SIZE_MB:-50}M

CHALLENGE_HOST: ${CHALLENGE_HOST:-ctf.hacksu.com}
FLAG_ENCRYPTION_KEY: ${FLAG_ENCRYPTION_KEY}
TESTING_READ: "C++ is the Best Language, the very best."
Expand Down
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ chown -R www-data:www-data "/app/build"
mkdir -p "${UPLOADS_DIR}" && chown -R www-data:www-data "${UPLOADS_DIR}"
mkdir -p "${BIN_UPLOADS_DIR}" && chown -R www-data:www-data "${BIN_UPLOADS_DIR}"

: "${PUBLIC_MAX_UPLOAD_SIZE_MB:=50}"
echo "[*] Rendering nginx config (client_max_body_size = ${PUBLIC_MAX_UPLOAD_SIZE_MB}m)..."
envsubst '${PUBLIC_MAX_UPLOAD_SIZE_MB}' < /etc/nginx/khi.conf.template > /etc/nginx/conf.d/default.conf

# Start supervisord in the background
echo "[*] Starting supervisord..."
/usr/bin/supervisord -n -c /etc/supervisor/conf.d/supervisord.conf &
Expand Down
2 changes: 2 additions & 0 deletions khi.conf → khi.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ server {
listen 80;
server_name ctf.hacksu.com dev.ctf.hacksu.com;

client_max_body_size ${PUBLIC_MAX_UPLOAD_SIZE_MB}m;

# block access to all hidden files
location ~ /\. {
return 404;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/components/file_upload.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ChevronDown from "@lucide/svelte/icons/chevron-down";
import LoaderCircle from "@lucide/svelte/icons/loader-circle";
import Trash2 from "@lucide/svelte/icons/trash-2";
import { MAX_UPLOAD_FILE_SIZE, MAX_UPLOAD_SIZE_MB } from "$lib/upload-limits";

let {
summaryText,
Expand Down Expand Up @@ -46,8 +47,6 @@
}

function handleFileInput(e: Event) {
const MAX_FILE_SIZE = 12 * 1024 * 1024; // 12 MB

const input = e.target as HTMLInputElement;
const picked = Array.from(input.files ?? []);

Expand All @@ -69,9 +68,9 @@
}
}

const tooBig = picked.filter(f => f.size > MAX_FILE_SIZE);
const tooBig = picked.filter(f => f.size > MAX_UPLOAD_FILE_SIZE);
if (tooBig.length > 0) {
error = `Files exceed 12 MB limit: ${tooBig.map(f => f.name).join(", ")}`;
error = `Files exceed ${MAX_UPLOAD_SIZE_MB} MB limit: ${tooBig.map(f => f.name).join(", ")}`;
if (fileInput) fileInput.value = "";
selectedFiles = [];
return;
Expand Down
4 changes: 4 additions & 0 deletions src/lib/upload-limits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { env } from "$env/dynamic/public";

export const MAX_UPLOAD_SIZE_MB = Number(env.PUBLIC_MAX_UPLOAD_SIZE_MB) || 50;
export const MAX_UPLOAD_FILE_SIZE = MAX_UPLOAD_SIZE_MB * 1024 * 1024;
19 changes: 7 additions & 12 deletions src/routes/admin/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { join, basename } from "path";
import type { ChallengeForm } from "$lib/database/db";
import { SHA256 } from '$lib/utilities';
import { encryptFlag } from '$lib/server/flag-crypto';
import { MAX_UPLOAD_FILE_SIZE } from '$lib/upload-limits';

const uploadDir = process.env.UPLOADS_DIR ?? join(process.cwd(), "uploads");
const binUploadDir = process.env.BIN_UPLOADS_DIR ?? join(process.cwd(), "ctf");
Expand Down Expand Up @@ -239,10 +240,8 @@ export const actions = {
});

// check for file sizes and remove large files
const MAX_FILE_SIZE = 12 * 1024 * 1024; // 12 MB

const largeFiles = files.filter(f => f.size > MAX_FILE_SIZE);
files = files.filter(f => f.size <= MAX_FILE_SIZE);
const largeFiles = files.filter(f => f.size > MAX_UPLOAD_FILE_SIZE);
files = files.filter(f => f.size <= MAX_UPLOAD_FILE_SIZE);

if (files.length === 0 || files.every(f => f.size === 0)) {
return {
Expand Down Expand Up @@ -311,10 +310,8 @@ export const actions = {
});

// check for file sizes and remove large files
const MAX_FILE_SIZE = 12 * 1024 * 1024; // 12 MB

const largeFiles = files.filter(f => f.size > MAX_FILE_SIZE);
files = files.filter(f => f.size <= MAX_FILE_SIZE);
const largeFiles = files.filter(f => f.size > MAX_UPLOAD_FILE_SIZE);
files = files.filter(f => f.size <= MAX_UPLOAD_FILE_SIZE);

if (files.length === 0 || files.every(f => f.size === 0)) {
return {
Expand Down Expand Up @@ -361,10 +358,8 @@ export const actions = {
});

// check for file sizes and remove large files
const MAX_FILE_SIZE = 12 * 1024 * 1024; // 12 MB

const largeFiles = files.filter(f => f.size > MAX_FILE_SIZE);
files = files.filter(f => f.size <= MAX_FILE_SIZE);
const largeFiles = files.filter(f => f.size > MAX_UPLOAD_FILE_SIZE);
files = files.filter(f => f.size <= MAX_UPLOAD_FILE_SIZE);

if (files.length === 0 || files.every(f => f.size === 0)) {
return {
Expand Down