Skip to content

Installer: refuse a malformed ADDY_VERSION, rewrite .env portably and atomically - #3

Merged
ZeeshanSultan merged 1 commit into
mainfrom
fix/installer-version-portable
Dec 5, 2026
Merged

ZeeshanSultan merged 1 commit into
mainfrom
fix/installer-version-portable

Conversation

@ZeeshanSultan

Copy link
Copy Markdown
Member

The pinned-upgrade path ran sed -i "s/^ADDY_VERSION=.*/ADDY_VERSION=$ADDY_VERSION/" .env. That had three problems:

  • Portability: BSD sed reads the word after -i as a backup suffix, so an upgrade on macOS died with "invalid command code".
  • Atomicity: .env holds the relay's secrets, and an interrupted in-place rewrite can truncate it.
  • Input: ADDY_VERSION reached the sed expression unchecked. A / broke the edit, and GNU sed's e flag 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_VERSION must be latest or a version (a leading v is still stripped). It's checked before anything else runs.
  • set_env_version writes a 0600 temporary file beside .env with awk, then renames it over the original.
  • The test harness no longer passes inherited ADDY_* variables through. scripts/build.sh exports ADDY_VERSION while running the tests, which made a release build fail the upgrade test on macOS.

New tests

  • A pinned upgrade rewrites the version, keeps every other line, and leaves .env at 0600 with no temporary file behind.
  • Malformed versions, including injection attempts, are refused with the reason.
  • latest, 0.1.7, v0.1.7 and 1.0.0-rc.1 are accepted.

go test ./...: all 18 test packages pass on macOS.

Note: install.sh is a release asset and is also served from get.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

… 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>
@ZeeshanSultan
ZeeshanSultan merged commit 1a0851b into main Dec 5, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants