Skip to content

Download the sury keyring into a private directory - #161

Merged
peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:fix/sury-keyring-private-tempdir
Nov 12, 2026
Merged

peterjaap merged 1 commit into
qoliber:mainfrom
Aquive:fix/sury-keyring-private-tempdir

Conversation

@Aquive

@Aquive Aquive commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Found by: the security-guidance Claude Code plugin (automated security review), which flagged this after syncing upstream main.

Problem

On Ubuntu releases that use packages.sury.org (e.g. 26.04), configureSuryRepository downloaded the keyring package to a fixed, predictable path and then installed it as root:

keyringDeb := "/tmp/magebox-sury-keyring.deb"
u.RunCommand(fmt.Sprintf("curl -fsSL -o %s https://...", keyringDeb))
u.RunSudo("dpkg", "-i", keyringDeb)

On a machine with more than one local user, another user can pre-create that file (or a symlink), or replace it between the download and dpkg -i. Then dpkg installs their package as root, maintainer scripts included.

Fix

  • New helper downloadToPrivateFile fetches the file with net/http into a fresh os.MkdirTemp directory (mode 0700). It creates the file with O_EXCL and returns a cleanup that removes the directory.
  • configureSuryRepository uses it, so the download no longer goes through sh -c + curl.
  • Table of tests: directory is 0700, two downloads never share a path, cleanup removes everything, and an HTTP error fails without leaving a temp directory.

I did not pin a SHA-256 of the .deb. sury republishes the keyring package when keys rotate, so a pinned hash would break bootstrap on the next rotation. HTTPS plus the private directory closes the local attack this is about.

Testing

  • make lint: 0 issues
  • make test: passes

Bootstrap downloaded the sury keyring package to the fixed path
/tmp/magebox-sury-keyring.deb and then ran `sudo dpkg -i` on it. Any
other local user could create that file first, or swap it between the
download and the install, and have their own package installed as root.

The package is now fetched with net/http into a fresh 0700 directory
from os.MkdirTemp, created with O_EXCL, and the directory is removed
afterwards. The download also no longer goes through a shell.
@peterjaap
peterjaap merged commit e9839d1 into qoliber:main Nov 12, 2026
10 checks 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