Initial upload
This commit is contained in:
1 parent
b0bf3b7167
commit
a022f29e34
65 files changed
+46484
-4339
No files matched your search
@@ -1,5 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const POLLUTION_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
||||
|
||||
function cleanString(value) {
|
||||
return String(value ?? "").trim();
|
||||
}
|
||||
@@ -17,6 +19,41 @@ function toFiniteNumber(value) {
|
||||
return Number.isFinite(numeric) ? numeric : null;
|
||||
}
|
||||
|
||||
function normalizePortProtocol(value) {
|
||||
const protocol = cleanString(value).toLowerCase();
|
||||
return protocol === "tcp" || protocol === "udp" || protocol === "sctp" ? protocol : "";
|
||||
}
|
||||
|
||||
function sanitizePortProtocolPayload(portProtocols, ports = []) {
|
||||
if (!portProtocols || typeof portProtocols !== "object" || Array.isArray(portProtocols)) return null;
|
||||
|
||||
const allowedPorts = new Set(
|
||||
(Array.isArray(ports) ? ports : [])
|
||||
.map((entry) => toFiniteNumber(entry))
|
||||
.filter((entry) => Number.isInteger(entry) && entry > 0)
|
||||
.map((entry) => String(entry))
|
||||
);
|
||||
const out = {};
|
||||
for (const [rawPort, rawProtocols] of Object.entries(portProtocols)) {
|
||||
const port = toFiniteNumber(rawPort);
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) continue;
|
||||
const portKey = String(port);
|
||||
if (allowedPorts.size && !allowedPorts.has(portKey)) continue;
|
||||
|
||||
const source = Array.isArray(rawProtocols) ? rawProtocols : [rawProtocols];
|
||||
const protocols = [];
|
||||
const seen = new Set();
|
||||
for (const entry of source) {
|
||||
const protocol = normalizePortProtocol(entry);
|
||||
if (!protocol || seen.has(protocol)) continue;
|
||||
seen.add(protocol);
|
||||
protocols.push(protocol);
|
||||
}
|
||||
if (protocols.length) out[portKey] = protocols;
|
||||
}
|
||||
return Object.keys(out).length ? out : null;
|
||||
}
|
||||
|
||||
function cleanAbsoluteContainerPath(value, fallback = "") {
|
||||
let raw = cleanString(value).replace(/\0/g, "").replace(/\\/g, "/");
|
||||
if (!raw) return fallback;
|
||||
@@ -31,6 +68,7 @@ function sanitizeEnvPayload(env) {
|
||||
const out = {};
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
const envKey = cleanString(key);
|
||||
if (POLLUTION_KEYS.has(envKey)) continue;
|
||||
if (!envKey) continue;
|
||||
out[envKey] = String(value ?? "");
|
||||
}
|
||||
@@ -44,7 +82,6 @@ function sanitizeDockerInstallPayload(install) {
|
||||
if (!script) return null;
|
||||
|
||||
const image = cleanString(install.image || install.container) || "ghcr.io/pterodactyl/installers:debian";
|
||||
const entrypoint = cleanString(install.entrypoint) || "bash";
|
||||
const mountPath = cleanAbsoluteContainerPath(
|
||||
install.mountPath || install.containerPath || install.container_path || install.serverPath,
|
||||
"/mnt/server"
|
||||
@@ -54,24 +91,26 @@ function sanitizeDockerInstallPayload(install) {
|
||||
"/home/container"
|
||||
);
|
||||
|
||||
const timeoutRaw = toFiniteNumber(install.timeoutSeconds || install.timeout_seconds || install.timeout);
|
||||
const timeoutSeconds = timeoutRaw && timeoutRaw > 0
|
||||
? Math.max(60, Math.min(Math.trunc(timeoutRaw), 7200))
|
||||
: 1800;
|
||||
const minimumStorageRaw = toFiniteNumber(install.minimumStorageMb || install.minimum_storage_mb);
|
||||
const minimumStorageMb = minimumStorageRaw && minimumStorageRaw > 0
|
||||
? Math.max(1, Math.min(Math.trunc(minimumStorageRaw), 1024 * 1024))
|
||||
: 0;
|
||||
const timeoutRaw = toFiniteNumber(install.timeoutSeconds || install.timeout_seconds);
|
||||
const timeoutSeconds = timeoutRaw && timeoutRaw > 0
|
||||
? Math.max(60, Math.min(Math.trunc(timeoutRaw), 7200))
|
||||
: 1800;
|
||||
|
||||
const payload = {
|
||||
image,
|
||||
script,
|
||||
entrypoint,
|
||||
mountPath,
|
||||
runtimePath,
|
||||
timeoutSeconds,
|
||||
};
|
||||
if (minimumStorageMb > 0) payload.minimumStorageMb = minimumStorageMb;
|
||||
if (install.allowEmpty === true || install.allowEmptyResult === true) {
|
||||
payload.allowEmpty = true;
|
||||
}
|
||||
|
||||
const env = sanitizeEnvPayload(install.env);
|
||||
if (env) payload.env = env;
|
||||
@@ -104,6 +143,10 @@ function sanitizeDockerTemplatePayload(docker) {
|
||||
const restartPolicy = cleanString(docker.restartPolicy);
|
||||
if (restartPolicy) payload.restartPolicy = restartPolicy;
|
||||
|
||||
if (docker.runAsRoot === true || docker.run_as_root === true) {
|
||||
payload.runAsRoot = true;
|
||||
}
|
||||
|
||||
const ports = Array.isArray(docker.ports)
|
||||
? docker.ports
|
||||
.map((entry) => {
|
||||
@@ -114,6 +157,12 @@ function sanitizeDockerTemplatePayload(docker) {
|
||||
: [];
|
||||
if (ports.length) payload.ports = ports;
|
||||
|
||||
const portProtocols = sanitizePortProtocolPayload(
|
||||
docker.portProtocols || docker.port_protocols || docker.protocols,
|
||||
ports
|
||||
);
|
||||
if (portProtocols) payload.portProtocols = portProtocols;
|
||||
|
||||
const volumes = Array.isArray(docker.volumes)
|
||||
? docker.volumes.map((entry) => cleanString(entry)).filter(Boolean)
|
||||
: [];
|
||||
@@ -132,6 +181,17 @@ function sanitizeDockerTemplatePayload(docker) {
|
||||
);
|
||||
if (adpanelStartup) payload.adpanelStartup = adpanelStartup;
|
||||
|
||||
const startupDisplay = cleanScript(
|
||||
docker.startupDisplay ||
|
||||
docker.startup_display ||
|
||||
docker.startupPreview ||
|
||||
docker.startup_preview ||
|
||||
docker.imageDefaultStartup ||
|
||||
docker.image_default_startup,
|
||||
32768
|
||||
);
|
||||
if (startupDisplay) payload.startupDisplay = startupDisplay;
|
||||
|
||||
const install = sanitizeDockerInstallPayload(docker.install || docker.installation);
|
||||
if (install) payload.install = install;
|
||||
|
||||
@@ -146,4 +206,5 @@ module.exports = {
|
||||
sanitizeDockerTemplatePayload,
|
||||
sanitizeDockerInstallPayload,
|
||||
sanitizeEnvPayload,
|
||||
sanitizePortProtocolPayload,
|
||||
};
|
||||
Reference in new issue
Block a user