Skip to content

fix(docker): validate HERMES_UID/GID to prevent privilege escalation in stage2-hook#34119

Closed
sprmn24 wants to merge 1 commit into
NousResearch:mainfrom
sprmn24:fix/docker-stage2-uid-gid-validation
Closed

fix(docker): validate HERMES_UID/GID to prevent privilege escalation in stage2-hook#34119
sprmn24 wants to merge 1 commit into
NousResearch:mainfrom
sprmn24:fix/docker-stage2-uid-gid-validation

Conversation

@sprmn24

@sprmn24 sprmn24 commented May 28, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds numeric validation for HERMES_UID and HERMES_GID environment variables before passing them to usermod/groupmod in docker/stage2-hook.sh.

Type of Change

  • Bug fix

Changes Made

  • Added validate_uid_gid() helper function: rejects non-numeric values and enforces range 1000–65534
  • Wrapped both HERMES_UID and HERMES_GID conditions with the validator
  • Prevents HERMES_UID=0 or HERMES_GID=0 from silently granting root-level privileges to the hermes user

How to Test

  • Set HERMES_UID=0 → usermod should NOT fire
  • Set HERMES_UID=999 → usermod should NOT fire
  • Set HERMES_UID=1001 → usermod fires normally
  • Set HERMES_GID=0 → groupmod should NOT fire

Checklist

  • Single focused commit
  • No secrets or API keys
  • Existing UID remap behavior preserved for valid values (1000–65534)

@alt-glitch alt-glitch added type/security Security vulnerability or hardening P2 Medium — degraded but workaround exists area/docker Docker image, Compose, packaging labels May 29, 2026
@benbarclay

Copy link
Copy Markdown
Collaborator

Superseded by #35340, which landed in 758454d.

Thanks for raising the privilege-escalation gap @sprmn24 — the same validate_uid_gid() guard ships in #35340, applied to the already-merged PUID/PGID alias path so NAS users (Synology/unRAID/UGOS) are covered in the same conditional. Your fix branch was conflicting against main; #35340 had a clean rebase, hence the merge from there.

@benbarclay benbarclay closed this Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/docker Docker image, Compose, packaging P2 Medium — degraded but workaround exists type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants