fix(security): use isolated temp directory in spm.sh scripts [DEVA11Y-483]#23
Open
sunny-se wants to merge 1 commit into
Open
fix(security): use isolated temp directory in spm.sh scripts [DEVA11Y-483]#23sunny-se wants to merge 1 commit into
sunny-se wants to merge 1 commit into
Conversation
F-014 / DEVA11Y-483 — Concurrent spm.sh instances shared CWD (CWE-362), causing cleanup trap to delete sibling's Package.swift. Use mktemp -d for an isolated working directory per invocation. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
spm.shinstances shared CWD, causing the EXIT-trapcleanup()to delete a sibling instance'sPackage.swift/Package.resolved(CWE-362 race condition).mktemp -dper invocation so each run gets an isolated working directory.scripts/bash/spm.shscripts/zsh/spm.shscripts/fish/spm.shWhat changed
PACKAGE_EXISTSexit-code flag ($?)HAS_EXISTING_PACKAGEboolean (0/1)Package.swiftwritten to shared$PWD$WORK_DIRviamktemp -dcleanup()deletes$PWD/Package.swiftcleanup()doesrm -rf $WORK_DIR(temp dir only)swift package pluginruns in$PWD$WORK_DIRaftercdWhen a pre-existing
Package.swiftis detected,WORK_DIRpoints to the original directory and cleanup is skipped — preserving backward compatibility.Test plan
spm.shinvocation — verify scan completes, temp dir cleaned upspm.shinstances in same CWD — verify neither deletes the other'sPackage.swiftPackage.swift— verify existing file untouchedJira: DEVA11Y-483
🤖 Generated with Claude Code