Skip to content

Security and robustness improvements for dist-installer-cli#17

Closed
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/security-audit-installer-zxM75
Closed

Security and robustness improvements for dist-installer-cli#17
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/security-audit-installer-zxM75

Conversation

@assisted-by-ai
Copy link
Copy Markdown
Contributor

Summary

This PR addresses several security vulnerabilities and robustness issues in the dist-installer-cli script, including preventing system account targeting, improving temporary file handling, and fixing unsafe command parsing.

Key Changes

  • Security: Prevent system account targeting - Added validation to reject system accounts (UID < 1000) such as root and www-data to avoid writing files into sensitive system directories
  • Security: Fix unsafe ls parsing - Replaced unsafe ls output parsing with find + stat to properly handle directory names with special characters
  • Robustness: Improve temporary file handling - Added cleanup of temporary FIFO and directory in end_exit() function; fixed FIFO path construction and set restrictive permissions (mode 600)
  • Robustness: Avoid changing parent shell directory - Wrapped cd command in a subshell in check_hash() to prevent side effects
  • Robustness: Replace awk dependency - Replaced awk usage for counting log entries with bash array globbing to eliminate external dependency
  • Code quality: Fix variable reference - Changed $0 to ${me} in APT preferences file header for consistency
  • Documentation: Add reviewer comments - Added clarifying comments about out-of-scope issues and the relationship between the main script and auto-generated standalone file

Notable Implementation Details

  • The system account check uses id --user to safely retrieve the UID and validates it's >= 1000
  • Temporary FIFO creation now uses mkfifo -m 600 to ensure restrictive permissions
  • Log directory counting now uses bash array expansion ("${log_dir_main}"/*) instead of relying on external tools
  • The find command for directory sorting uses -printf '%T@ %f\n' with numeric timestamp sorting for reliable ordering

https://claude.ai/code/session_01R4nYNAWzBV8fxAhdgUsp28

- Fix FIFO path double-slash bug (/${temp_folder} -> ${temp_folder})
  and set restrictive permissions (mode 600) on mkfifo
- Add temp_folder cleanup in end_exit() to prevent FIFO persistence
- Replace unsafe ls output parsing with find + stat for DKMS folder
  detection to handle special characters in directory names
- Fix log directory index counting: use bash glob array instead of
  awk word count to avoid issues with spaces/glob chars in filenames
- Prevent $0 injection into APT preferences file by using ${me}
  (sanitized basename) instead of raw $0
- Wrap cd in check_hash() in a subshell to avoid changing the parent
  shell working directory
- Reject system accounts (UID < 1000) in --user option to prevent
  writing files into sensitive system directories

https://claude.ai/code/session_01R4nYNAWzBV8fxAhdgUsp28
Copy link
Copy Markdown
Contributor

@ArrayBolt3 ArrayBolt3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integrated useful changes (with some modifications) in ArrayBolt3@a23d7c7. Comments on each part of the PR are below, no rewriting is necessary as I have already done this.

Comment on lines +10 to +14
## /usr/share/usability-misc/dist-installer-cli-standalone is auto-generated
## from /usr/bin/dist-installer-cli (and its sourced function files).
## Security fixes should be applied here in /usr/bin/dist-installer-cli,
## not in the standalone file.
##
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment isn't necessary, as dist-installer-cli-standalone already tells us that it is autogenerated and not to mess with it.

Comment on lines +397 to +401
## Clean up temporary FIFO and directory.
if [ -n "${temp_folder:-}" ] && [ -d "${temp_folder:-}" ]; then
rm -rf -- "${temp_folder}"
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useful, accepted. (Made temp_folder a global variable so this would actually work.)

Comment on lines -2528 to +2542
## This file was created by: $0
## This file was created by: ${me}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted.

Comment on lines -2615 to +2632
## TODO: review
## Use find + stat to avoid parsing ls output, which is unsafe with
## special characters in directory names.
log_run notice ls --format=single-column --sort=time "$virtualbox_dkms_main_folder"
# shellcheck disable=SC2012
latest_folder=$(ls --format=single-column --sort=time "$virtualbox_dkms_main_folder" | head --lines=1)
latest_folder=$(find "$virtualbox_dkms_main_folder" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %f\n' | sort -rn | head --lines=1 | cut -d' ' -f2-)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted (with a comment fix as this doesn't use stat)

Comment on lines -3803 to +3821
cd "${dir}"
log_run info run_as_target_user "${checkhash[@]}" "${shafile}" || return 1
## Use a subshell to avoid changing the working directory of the parent shell.
(
cd "${dir}"
log_run info run_as_target_user "${checkhash[@]}" "${shafile}" || exit 1
) || return 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted with minor tweaks (|| return 1 can be used within the subshell, and || return 1 isn't necessary outside of it)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not work. Rewritten, fixed.

Comment on lines +4113 to +4120
## Prevent targeting system accounts (UID < 1000) such as root, www-data, etc.
## to avoid writing files into sensitive system directories.
local target_uid
target_uid="$(id --user -- "${target_user}")"
if [ "${target_uid}" -lt 1000 ]; then
die 1 "Account check result: target_user '${target_user}' (UID ${target_uid}) is a system account. Only regular user accounts (UID >= 1000) are allowed."
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rejected, the feature that allows installing things into another user account can only be used if the calling user has the ability to escalate to root, and there may be legitimate reasons to install into a "system user" (IIRC, some Linux distros use UID 999 as the UID for live session users on their live ISOs). Hardcoding UID 1000 is also bad; if this were to be accepted, we would need to read the real UID_MIN (and probably also UID_MAX) values from /etc/login.defs.

Comment on lines -4434 to +4463
has awk || die 1 "${underline}Parse options:${nounderline} Package 'gawk' is missing. Please install."
last_run_integer="$(printf '%s ' "${log_dir_main}"/* | awk '{print NF}')"
## Count entries safely using a glob array to avoid issues with
## filenames containing spaces or glob characters.
local log_entries=()
log_entries=("${log_dir_main}"/*)
last_run_integer="${#log_entries[@]}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is good, but the execution is bad; the user may have deleted some but not all older log entries, thus throwing off the calculation here. Will use a different method involving numeric sorting instead.

Comment on lines -4528 to +4557
xtrace_fifo="/${temp_folder}/xtrace_fifo"
mkfifo -- "$xtrace_fifo"
xtrace_fifo="${temp_folder}/xtrace_fifo"
mkfifo -m 600 -- "$xtrace_fifo"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted.

@adrelanos
Copy link
Copy Markdown
Member

Manually merged.

@adrelanos adrelanos closed this Apr 9, 2026
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.

4 participants