Skip to content

Security: data-integrity nits in consolidation and git-backup locking #69

Closed

Description

@fdaviddpt

Internal security audit, two low-impact integrity issues grouped.

4.1 STAGING path unescaping is asymmetric — Medium

scripts/run-consolidation.sh:89: staging paths from Python are extracted with

sed "s/^STAGING=//;s/^'//;s/'$//"

This undoes _shell_escape()'s outer single-quote wrapping but doesn't decode the '\'' idiom used for embedded single quotes. A staging filename containing a single quote produces a corrupt path — mv then points at the wrong file (or fails), leaving the memory file un-renamed to .done.md and re-processed indefinitely.

Not directly exploitable for code execution, but a data-loss path on filesystems where single quotes in filenames are valid.

Fix: write staging paths to a temp file (one per line, NUL-separated), and read with while IFS= read -r -d '' path; do .... Or move to JSON IPC alongside the broader safe_eval refactor.

4.2 Stale lock TOCTOU in git-backup — Low

hooks.d/after_save/50-git-backup.sh:61-62:

rm -f "$LOCK_FILE"
( set -o noclobber; echo $$ > "$LOCK_FILE" ) 2>/dev/null || exit 0

Between rm and the noclobber re-acquire, another concurrent session can win the lock. Both then proceed.

Benign in practice — worst case is two concurrent commits to disjoint slug subtrees (which git serializes via its own index lock). Worth a code comment acknowledging the race + why it's acceptable.

Fix: add a comment, or use flock(1) on a separate lock file (no TOCTOU — flock is atomic). The latter is the structurally correct fix and removes the race.


Both are low-impact today. 4.1 is the one to actually fix; 4.2 is acknowledge-or-flock.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions