Repository navigation
Installer: refuse a malformed ADDY_VERSION, rewrite .env portably and atomically - #3
Merged
Merged
Conversation
… atomically The pinned-upgrade path ran `sed -i "s/^ADDY_VERSION=.*/ADDY_VERSION=$ADDY_VERSION/"`. That had three problems: - Portability. BSD sed reads the word after -i as a backup suffix, so on macOS the upgrade died with "invalid command code". - Atomicity. .env holds the relay's secrets. An in-place rewrite that is interrupted can leave a truncated file. - Input. ADDY_VERSION went into the sed expression unchecked: a `/` broke the edit, and GNU sed's `e` flag would run whatever followed. The operator sets the value, so this is not a privilege boundary, but a typo should fail early and in words. ADDY_VERSION must now be `latest` or a version (a leading v is still stripped), checked before anything else runs. set_env_version writes a 0600 temporary file beside .env with awk and renames it over the original. The test harness also stops passing inherited ADDY_* variables through. scripts/build.sh exports ADDY_VERSION while it runs the tests, which is how a release build pushed its own version into the upgrade test and failed it on macOS. New tests: a pinned upgrade rewrites the version, keeps every other line, leaves .env at 0600 with no temporary file behind; malformed versions (including injection attempts) are refused with the reason, and valid ones (latest, 0.1.7, v0.1.7, 1.0.0-rc.1) are accepted. Co-Authored-By: Claude Opus 5.5 <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.
The pinned-upgrade path ran
sed -i "s/^ADDY_VERSION=.*/ADDY_VERSION=$ADDY_VERSION/" .env. That had three problems:-ias a backup suffix, so an upgrade on macOS died with "invalid command code"..envholds the relay's secrets, and an interrupted in-place rewrite can truncate it.ADDY_VERSIONreached the sed expression unchecked. A/broke the edit, and GNU sed'seflag would run whatever followed. The operator sets it, so this isn't a privilege boundary, but a typo should fail early and say why.Fix
ADDY_VERSIONmust belatestor a version (a leadingvis still stripped). It's checked before anything else runs.set_env_versionwrites a0600temporary file beside.envwithawk, then renames it over the original.ADDY_*variables through.scripts/build.shexportsADDY_VERSIONwhile running the tests, which made a release build fail the upgrade test on macOS.New tests
.envat0600with no temporary file behind.latest,0.1.7,v0.1.7and1.0.0-rc.1are accepted.go test ./...: all 18 test packages pass on macOS.Note:
install.shis a release asset and is also served fromget.opsmaxx.dev, so this reaches users with the next addy release, plus a copy to/var/www/get.opsmaxx.dev/addy/on Chain305.🤖 Generated with Claude Code