Repository credentials still logged in cleartext after the fix for GHSA-v6mg-7f7p-qmqp
Description
Impact
apko accepts HTTP basic-auth credentials in repository URLs (https://user:pass@host/...). The fix for GHSA-v6mg-7f7p-qmqp (CVE-2024-36127, commit 2c0533e4) redacted those URLs only when the image configuration is marshalled to YAML. Log statements and error messages that format repository URLs directly still write the username and password in cleartext.
Logs from apko, and from tools that embed it such as melange, often end up in CI output. On public repositories that output is world-readable.
Affected data paths
At main 0408833b:
(*APK).InitRuntimeOnlyKeyslogs the runtime-only repository URL at warn. Key discovery rejects any URL that contains user info (canonicalHTTPOrigin), so for a credentialed runtime-only repository this line fires on every build, with no network failure needed.(*ImageConfiguration).Summarizelogs build, runtime-only and main repositories at info. melange callsSummarizeon every build.- Package fetch errors include the raw URL:
package_getter.go,httpStatusError.Errorandtransport.go. They reach the warn-level retry log and the final error on any 5xx or 429 response. - debug level:
(*APK).SetRepositories,(*APK).fetchChainguardKeysand the key-discovery lines inapko lock. - The
redact()helper itself did not redact a URL that fails to parse, for example one whose password contains an unescaped/,?or#, as base64 tokens often do. Such URLs kept their credentials in every redacted log line and error, including path 1. - The on-disk package and index cache. Each repository's cache directory was named after its URL, password included. Cache paths appear in debug logs and errors, and the password stays on disk in the directory name. CI jobs that save or upload the apk cache directory publish it.
- Trace spans. On a package cache miss, the span name contained the full package URL, so anyone exporting apko traces received the password.
Attack prerequisites
- A build configures at least one repository URL with embedded credentials.
- The attacker can read the build's log output, for example the CI logs of a public repository.
Paths 1 to 3 need only the default log level.
Affected versions
apko releases through 1.5.5, and melange releases through 0.66.0, which log repositories through apko's Summarize.
Reproduction
Against main at 0408833b, with the repository https://apkuser:SUPERSECRET@127.0.0.1:1/os:
- Call
InitRuntimeOnlyKeyswith a logger at info level. The warn line containsSUPERSECRET. - Call
Summarizeon anImageConfigurationthat lists the repository, at info level. The output containsSUPERSECRET, whileyaml.Marshalof the same configuration does not. - Call
SetRepositoriesandfetchChainguardKeysat debug level. Both lines containSUPERSECRET.
Patches
Fixed in apko 1.5.6. Every repository and key URL is now redacted before it is logged or put in an error, and URLs that fail to parse are fully redacted. melange users should upgrade to melange 0.66.1 or later.
After upgrading, delete any apk cache directory filled from repository URLs with credentials in them; their names contain the password. Online builds refill the cache automatically. Offline builds that use a cache filled by an earlier release fail until it is refilled with the fixed release.
Workarounds
- Supply repository credentials through
HTTP_AUTHrather than in the repository URL. - Do not publish apko or melange build logs from builds that use credentialed repository URLs.