fix: read /proc/self/environ so PSST_PASSWORD survives ptrace-based sandbox injection#36
Open
LucasRoesler wants to merge 1 commit intoMichaelliv:mainfrom
Open
Conversation
Bun snapshots process.env from envp[] very early in its startup sequence. Sandbox supervisors that inject credentials via ptrace (e.g. nono) write into the kernel's live environ after execve(), making those vars visible in /proc/self/environ but invisible to process.env. Add native-env.ts which reads /proc/self/environ at call-time (Linux only, no-op on other platforms) and export getenvNative() as a fallback for any env var lookup that must survive ptrace-style injection. Apply the fallback in SqliteBackend.unlock(): check process.env first, then /proc/self/environ, then keychain. This order ensures that injected passwords are found before a sandbox-restricted keychain attempt fails. Also add PSST_DEBUG=1 gated logging (itself read via both paths) to make the unlock flow diagnosable without rebuilding.
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.
Problem
psst unlockfails with "Failed to unlock vault" whenPSST_PASSWORDis injected by a ptrace-based sandbox supervisor (e.g. nono in supervised mode), even though the variable is present in the process environment.The root cause is a timing gap between Bun and ptrace injection. Bun snapshots
process.envfromenvp[]very early in its startup sequence — before a ptrace supervisor has had a chance to write into the process environment. The injected variable is present in the kernel's live view (/proc/self/environ) but absent fromprocess.env.This affects any runtime that snapshots
envp[]at startup (Bun, Go, JVM). It does not affect Node.js or bash, which call through glibc'sgetenv()and see the liveenvironpointer.Reproduction
Before fix:
After fix (with
PSST_DEBUG=1):Changes
src/vault/native-env.ts: reads/proc/self/environat call-time and exposesgetenvNative(name). Linux-only; returnsnullon other platforms. Result is cached after first read.SqliteBackend.unlock(): fall back togetenvNative()whenprocess.env.PSST_PASSWORDis unset, so injected credentials are found even if Bun missed them at startup.PSST_DEBUG=1logging to the unlock path (itself read via both sources) to make this class of failure diagnosable without rebuilding.