Files
w3cjandClaude Opus 5.5 4d409589bb refactor(redact): every secret's value is a redact.Secret, revealed only where it's used
redact.Secret holds a value that lets whoever has it act as the user or
a VM, behind a pointer, so fmt's raw printing of an unexported field
shows only an address. String, GoString and Format print <redacted> for
every verb; MarshalJSON, UnmarshalJSON and MarshalText return
redact.ErrEncode, so a secret is never silently written as a stand-in
(which would lose a login); there's no LogValue. NewSecret ("" is the
zero Secret), Reveal, Empty and TrimSpace are the rest. internal/redact
joins the proxy's standard-library-only depguard group.

Reveal is refused by forbidigo outside tests; each of the 23 call sites
carries a //nolint:forbidigo saying why, and testdata/lint/forbidigo.go
keeps a call the rule must report. The structure test (checkSecrets)
refuses a struct that embeds redact.Secret outside internal/redact and
an interface that declares Reveal() string.

Typed now: proxy.Config.Password (configFile is the wire type, in
Config's order, held to it by TestConfigFile), the server's password,
proxy.Lookup and the cached values, upstream.auth, upstreamPassword,
Upstream.WithPassword's password; backend.NewProxyPassword, ProxyURL,
Confinement.ProxyPassword, BuildProxy.Password; netpolicy.Key and
NetMade.ProxyKey (netMade wire type); settings.CompanyProxy.Password;
secrets.Store.Value, saved, ProxyPassword, Token, Save, save, Get,
SaveKey, Yours.Save, Claude.Env, saveToken, oauthToken; agentlogin
File.Get, SetKey, ClaudeToken, every format's get, setKey and chatGPT,
refresh's refresh token, capture's access, refresh and id tokens, and
the JWT helpers (a login's map stays the wire, through token and
setToken; piKey is piBound); vm.Net.SecretSave, AgentLoginOptions.Key;
ui.UI.Secret. Strings by design: platform.KeychainGet/Set and the
desktop's VNC password.

Tests: TestSecret (unexported and nested fields too), TestConfigFile,
TestV010ProxyConfigs (0.1.0's proxy.json round-trips byte for byte),
TestFixtureStoreGet saves the Linux secret file back byte for byte,
checkV010Logins (login files read, copied and bound without a change),
secretCases, and e2e netNoLeaks, twice in the network section: every
VM's proxy password and the section's values, also as Basic
credentials, in no run log or proxy log, and the passwords in no
ha.stderr.log or serial log. Docs: Contributing's Secrets in the code,
the owners table, the secrets How it works page, design.md's Where
secret values live.

Fixed, found by netNoLeaks: Lima's boot script 07-etc-environment.sh
runs under set -x, so the console logs (serial*.log) kept the VM's
proxy password; redactLog now stars passwords in them as it does in
ha.stderr.log (CHANGELOG, overview, processes and attack-vectors pages).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:31 -07:00

56 lines
2.0 KiB
Go

package backend
import (
"crypto/rand"
"encoding/hex"
"net"
"net/url"
"strconv"
"strings"
"github.com/devvmhq/devvm/internal/proxy"
"github.com/devvmhq/devvm/internal/redact"
)
// ProxyUser is the user in the address of every proxy of devvm's, a VM's
// or a build's, which the proxy checks (proxy.ProxyUser); the password is
// the VM's or the build's own.
const ProxyUser = proxy.ProxyUser
// ProxyURL is a proxy of devvm's at host and port as the guest reaches it,
// with ProxyUser and password. The URL holds the password: it goes only
// into the guest's proxy settings, which the guest needs it in.
func ProxyURL(host string, port int, password redact.Secret) string {
u := url.URL{Scheme: "http", Host: net.JoinHostPort(host, strconv.Itoa(port)), User: url.UserPassword(ProxyUser, password.Reveal())} //nolint:forbidigo // the guest's proxy URL, which the guest sends the password in
return u.String()
}
// NewProxyPassword is a new password for a proxy of devvm's: 32 random
// bytes, as 64 hex digits, which go into ProxyURL as they are.
func NewProxyPassword() (redact.Secret, error) {
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
return redact.Secret{}, err
}
return redact.NewSecret(hex.EncodeToString(b)), nil
}
// GuestProxyVars are the variables that name devvm's proxy in a guest
// (ProxyURL), in capitals and lowercase: tools read one or the other.
func GuestProxyVars() []string {
return []string{"HTTP_PROXY", "HTTPS_PROXY", "http_proxy", "https_proxy"}
}
// ClientProxyVars are every proxy variable a backend's own client
// (limactl) reads from its environment and passes on to a VM, in capitals
// and lowercase: devvm runs the client without them or sets them empty, so
// the host's proxy, password and all, stays out of VMs devvm doesn't mean
// to give it.
func ClientProxyVars() []string {
var out []string
for _, k := range []string{"HTTP_PROXY", "HTTPS_PROXY", "FTP_PROXY", "NO_PROXY", "ALL_PROXY"} {
out = append(out, k, strings.ToLower(k))
}
return out
}