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
Goal
Prevent the shipped standalone example from following a predictable, attacker-controlled temporary-file path.
Background
examples/std-usage.sh:14-17builds${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:
23797a73b2onmain.In an isolated temporary directory, precreate
base-bash-libs-example.<shell-pid>as a symlink to a file containingoriginal, then source the example in that shell withTMPDIRpointing to the directory. The target becomes:The repository already ships
base_std_make_temp_fileand registered cleanup helpers that avoid this class of race.Scope
Acceptance criteria
./tests/validate.shpasses.Validation
bash examples/std-usage.sh./tests/validate.shProject fields
Ownership