Skip to content

Validate container system stop --prefix to prevent accidental logout#1717

Open
mvanhorn wants to merge 1 commit into
apple:mainfrom
mvanhorn:fix/1672-system-stop-prefix-validation
Open

Validate container system stop --prefix to prevent accidental logout#1717
mvanhorn wants to merge 1 commit into
apple:mainfrom
mvanhorn:fix/1672-system-stop-prefix-validation

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

container system stop accepts a --prefix / -p option (default com.apple.container.). A user reported in #1672 that container system stop -p /usr/local/container logs them out of macOS.

The value is interpolated unvalidated into launchd label and domain-target strings that are handed to launchctl bootout (SystemStop.swift builds "\(launchdDomainString)/\(prefix)apiserver" and re-maps enumerated labels, then ServiceManager.deregister runs launchctl bootout <label>). A path value produces a malformed bootout target, and launchctl bootout of a malformed or bare domain target tears down the entire GUI session (gui/<uid>), which ends the user's login.

This adds a validate() guard that rejects any --prefix that is empty or contains characters outside [A-Za-z0-9._-] (including /), with a clear error naming the bad value and the expected form. All valid usage, including the default and any real reverse-DNS prefix, is unchanged. Scope is limited to system stop; system status declares the same option but only uses it for read-only launchctl list / isRegistered calls, so it cannot log the user out.

Fixes #1672

Testing

  • Tested locally
  • Added/updated tests

Added Tests/ContainerCommandsTests/SystemStopValidationTests.swift (swift-testing): rejects /usr/local/container and foo bar, accepts the default com.apple.container. and a custom com.example.svc..

swift test --filter SystemStopValidationTests
✔ Test run with 4 tests in 1 suite passed

swift format lint --strict --configuration .swift-format-nolint on the changed files reports no findings.

AI was used for assistance.

The --prefix option was interpolated unvalidated into launchd label and
domain-target strings passed to launchctl bootout. A path value such as
/usr/local/container produced a malformed bootout target, which can tear
down the entire GUI login session and log the user out.

Add a validate() guard that rejects any prefix that is empty or contains
characters outside [A-Za-z0-9._-] (including '/'), with a clear error.
All valid usage, including the default com.apple.container., is unchanged.

Fixes apple#1672
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: container system stop -p /usr/local/container logouts Mac

2 participants