diff options
| author | fox <fox@fakecake.org> | 2026-10-11 08:46:48 +0300 |
|---|---|---|
| committer | GitLab <noreply@fakecake.org> | 2026-10-11 08:46:48 +0300 |
| commit | 680836cd0983d13eebd4209416e4747c5ba17b58 (patch) | |
| tree | 03436a3901bf5b2d9d3ea88f6c3713463039c2b1 | |
| parent | 6f771f8b9468f012ba74f2e7d139efe7afbaf321 (diff) | |
| parent | 9b7d8300575ef5bf3c2daeecf97ec4055f944334 (diff) | |
| download | the-epube-680836cd0983d13eebd4209416e4747c5ba17b58.tar.gz the-epube-680836cd0983d13eebd4209416e4747c5ba17b58.tar.xz | |
Merge branch 'dev' into 'master'
set missing cookie parameters (samesite & httponly) and fix possible XSS in... See merge request git/the-epube!75
| -rw-r--r-- | .docker/app/Dockerfile | 6 | ||||
| -rw-r--r-- | .docker/app/startup.sh | 27 | ||||
| -rw-r--r-- | .env-dist | 8 | ||||
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | include/sessions.php | 14 | ||||
| -rw-r--r-- | src/app.ts | 4 |
6 files changed, 49 insertions, 12 deletions
diff --git a/.docker/app/Dockerfile b/.docker/app/Dockerfile index 9ec3691..d2e7b5b 100644 --- a/.docker/app/Dockerfile +++ b/.docker/app/Dockerfile @@ -63,8 +63,12 @@ RUN chmod 0755 ${SCRIPT_ROOT}/startup.sh ENV PHP_WORKER_MAX_CHILDREN=5 ENV PHP_WORKER_MEMORY_LIMIT=256M +# Admin bootstrap account. Only the *name* is baked in — never a password. +# If the user does not exist at first boot, startup.sh creates it with a +# randomly generated password, printed once to the container log. +# Override the name with -e EPUBE_ADMIN_USER=..., or supply your own password +# via -e EPUBE_ADMIN_PASS=... if you must. ENV EPUBE_ADMIN_USER="admin" -ENV EPUBE_ADMIN_PASS="password" # EPUBE_XDEBUG_HOST defaults to host IP if unset ENV EPUBE_XDEBUG_ENABLED="" diff --git a/.docker/app/startup.sh b/.docker/app/startup.sh index 64ad86f..d49dd05 100644 --- a/.docker/app/startup.sh +++ b/.docker/app/startup.sh @@ -36,8 +36,31 @@ rm -f /tmp/error.log && mkfifo /tmp/error.log (tail -q -f /tmp/error.log >> /proc/1/fd/2) & -if ! php${PHP_SUFFIX} $DST_DIR/update.php --user-list | grep -q "$EPUBE_ADMIN_USER"; then - php${PHP_SUFFIX} $DST_DIR/update.php --user-add "$EPUBE_ADMIN_USER:$EPUBE_ADMIN_PASS" +# --- Bootstrap admin account ------------------------------------------------- +# If the configured admin user does not exist yet, create it. When no password +# is supplied via EPUBE_ADMIN_PASS, generate a random one and print it to the +# container log exactly once. No static credentials ship in the image. +generate_password() { + local pass="" + while [ ${#pass} -lt 24 ]; do + pass="${pass}$(head -c 128 /dev/urandom | tr -dc 'A-Za-z0-9')" + done + printf '%s' "${pass:0:24}" +} + +php${PHP_SUFFIX} "$DST_DIR/update.php" --user-list > /tmp/epube_users.txt + +if ! grep -q "^.*\. *${EPUBE_ADMIN_USER}\$" /tmp/epube_users.txt; then + if [ -n "$EPUBE_ADMIN_PASS" ]; then + printf 'Creating admin user "%s" with password from environment.\n' "$EPUBE_ADMIN_USER" + else + EPUBE_ADMIN_PASS="$(generate_password)" + printf 'Creating admin user "%s" with generated password: %s\n' "$EPUBE_ADMIN_USER" "$EPUBE_ADMIN_PASS" + printf 'Store it now — it will not be shown again.\n' + fi + php${PHP_SUFFIX} "$DST_DIR/update.php" --user-add="${EPUBE_ADMIN_USER}:${EPUBE_ADMIN_PASS}" fi +rm -f /tmp/epube_users.txt + exec /usr/sbin/php-fpm${PHP_SUFFIX} --nodaemonize --force-stderr -R diff --git a/.env-dist b/.env-dist index c2dcd96..3f4781e 100644 --- a/.env-dist +++ b/.env-dist @@ -66,11 +66,13 @@ BOOKS_DIR=/home/user/calibre/Books # EPUBE_DICT_SERVER=dict # --------------------------------------------------------------------------- -# Authentication — Default Admin Account +# Authentication — Admin Bootstrap Account # --------------------------------------------------------------------------- -# Created on first startup if the user does not already exist. +# The admin user is created on first startup if it does not already exist. +# If EPUBE_ADMIN_PASS is left unset, a random password is generated and +# printed ONCE to the container log (docker logs <app-container>). EPUBE_ADMIN_USER=admin -EPUBE_ADMIN_PASS=password +# EPUBE_ADMIN_PASS= # optional — set explicitly only if you insist on your own # --------------------------------------------------------------------------- # Authentication — OpenID Connect (OIDC) diff --git a/.gitignore b/.gitignore index 94e2b87..674c5f1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,4 @@ /.phpstan-tmp /.phpunit.result.cache /TESTS.md - +/*PLAN.md diff --git a/include/sessions.php b/include/sessions.php index 1fa1e2f..b433fb9 100644 --- a/include/sessions.php +++ b/include/sessions.php @@ -6,15 +6,21 @@ $session_name = Config::get(Config::SESSION_NAME); $session_expire = Config::get(Config::SESSION_LIFETIME); - if (Config::is_server_https()) - ini_set("session.cookie_secure", "true"); - ini_set("session.name", "epube_sid"); ini_set("session.use_only_cookies", "true"); ini_set("session.gc_maxlifetime", $session_expire); ini_set("session.cookie_lifetime", "0"); - session_set_cookie_params($session_expire); + // Array signature sets all attributes at once; the legacy scalar form + // silently reset secure/httponly to their defaults. + session_set_cookie_params([ + 'lifetime' => $session_expire, + 'path' => '/', + 'domain' => '', + 'secure' => Config::is_server_https(), + 'httponly' => true, + 'samesite' => 'Lax', + ]); session_save_path(dirname(__DIR__) . "/sessions"); diff --git a/src/app.ts b/src/app.ts index 481f669..9da16c0 100644 --- a/src/app.ts +++ b/src/app.ts @@ -184,7 +184,9 @@ class AppClass extends AppCommon { console.log('cache version, current:', this.cacheVersion, 'worker:', await this.getActiveCacheVersion()); // Read URL params for mode/query/offset - this.index_mode = this.urlParam("mode") || ""; + // Whitelist known modes: never let an arbitrary URL value flow into + // generated hrefs or backend requests (DOM XSS hardening). + this.index_mode = this.urlParam("mode") === "favorites" ? "favorites" : ""; this.index_query = this.urlParam("query") || ""; const offsetParam = parseInt(this.urlParam("offset")); this.index_offset = isNaN(offsetParam) ? 0 : offsetParam; |
