Skip to content

security: replace the predictable temp path in std-usage.sh #331

Description

@codeforester

Goal

Prevent the shipped standalone example from following a predictable, attacker-controlled temporary-file path.

Background

examples/std-usage.sh:14-17 builds ${TMPDIR:-/tmp}/base-bash-libs-example.$$ and immediately redirects into it. In a shared writable temp directory, another local process can predict the PID path and precreate a symlink. The example then overwrites the symlink target. This is the same insecure temporary-path class fixed for production scripts by #282, but the shipped and validated example was not covered.

Reproduction and evidence

Framework reference: 23797a73b2 on main.

In an isolated temporary directory, precreate base-bash-libs-example.<shell-pid> as a symlink to a file containing original, then source the example in that shell with TMPDIR pointing to the directory. The target becomes:

example
# BEGIN base-bash-libs
managed=true
# END base-bash-libs

The repository already ships base_std_make_temp_file and registered cleanup helpers that avoid this class of race.

Scope

  • Replace the PID-derived path with the stdlib temporary-file contract.
  • Preserve cleanup and the example's observable success behavior.
  • Add a regression test that precreated names/symlinks cannot redirect the write.
  • Audit executable examples so they consistently demonstrate the safe API.

Acceptance criteria

  • The example obtains an exclusively created temporary file or directory.
  • A precreated symlink cannot cause another file to be modified.
  • Cleanup removes only the owned temporary artifact.
  • ./tests/validate.sh passes.

Validation

  • Run the adversarial symlink reproduction.
  • bash examples/std-usage.sh
  • ./tests/validate.sh

Project fields

  • Status: Backlog
  • Priority: P1
  • Area: Security
  • Initiative: Adoption Polish
  • Size: S

Ownership

Metadata

Metadata

Assignees

Labels

securitySecurity hardening or vulnerability work

Type

No type

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions