Repository navigation
XRAY-171572 - Refuse yarn jf c fallback with proxy or TLS settings - #953
Phavya-jfrog wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
960b172 to
d924feb
Compare
| if yarnrcValueIsSet(raw["httpsProxy"]) { | ||
| add("httpsProxy") | ||
| } | ||
| if yarnrcValueIsFalse(raw["enableStrictSsl"]) { |
There was a problem hiding this comment.
GetYarnrcNetworkSettings doesn't report a project-supplied CA bundle (caFilePath on Yarn 2/3, httpsCaFilePath on Yarn 4). A project can ship ./ca.pem; Yarn then trusts only that CA, so an on-path attacker holding a certificate that CA signed could receive the lent token, the same exposure as enableStrictSsl: false. I checked both keys with yarn config get on 2.4.1, 3.2.1 and 4.5.0: each key is valid only on its own major and rejected by the others, so listing both is safe. Client-cert keys (httpsCertFilePath, httpsKeyFilePath) don't change which server Yarn trusts, so they can stay allowed. Consider also adding both keys to the doc comment above.
Suggested addition before the enableStrictSsl check:
// caFilePath is the Yarn 2/3 name and httpsCaFilePath the Yarn 4 one; a project-supplied CA bundle replaces Yarn's trust store.
for _, caSetting := range []string{"httpsCaFilePath", "caFilePath"} {
if yarnrcValueIsSet(raw[caSetting]) {
add(caSetting)
}
}Test that fails today and passes with the change (sca/bom/buildinfo/technologies/yarn):
func TestGetYarnrcNetworkSettingsFlagsCustomCaFile(t *testing.T) {
for _, key := range []string{"httpsCaFilePath", "caFilePath"} {
t.Run(key, func(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("YARN_RC_FILENAME", "")
wd := t.TempDir()
require.NoError(t, os.WriteFile(filepath.Join(wd, ".yarnrc.yml"), []byte(key+": ./attacker-ca.pem\n"), 0o600))
found, err := GetYarnrcNetworkSettings(wd)
require.NoError(t, err)
require.Len(t, found, 1, "a custom CA file must be reported like enableStrictSsl: false")
assert.Equal(t, key, found[0].Setting)
})
}
}Review generated by xray-pr-review
| func loadYarnrcFiles(workingDir string) ([]loadedYarnrc, error) { | ||
| var files []loadedYarnrc | ||
| for _, path := range yarnrcCandidatePaths(workingDir) { | ||
| data, err := os.ReadFile(path) |
There was a problem hiding this comment.
The PR description says "An unreadable rc is refused too (fail closed)", but loadYarnrcFiles skips every os.ReadFile error, so only an unparsable rc is refused. There's no leak path: Yarn 2.4.1, 3.2.1 and 4.5.0 all fail on a directory or mode-000 rc. Consider changing the description to "unparsable". If you'd rather make the code match, a plain "skip only ErrNotExist" would regress Yarn 2/3 users with an untraversable $HOME (those versions skip it), so stat first and fail only on a file that exists but can't be read:
if _, statErr := os.Stat(path); statErr != nil {
continue
}
data, err := os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("could not read %s: %w", path, err)
}Review generated by xray-pr-review
|
Question on the design: Review generated by xray-pr-review |
devbranch.Problem
We already check that the registry is on the
jf chost, but not how Yarn reaches it. A project can keep the registry on the right host and still addhttpProxy/httpsProxy(or turn TLS verification off), so Yarn sends the token through an attacker's machine. A proxy URL could also read the token's env var by its fixed name.Design
jf cachecks every.yarnrc.ymlYarn reads: the project, the parent dirs of the temp copy Yarn runs in, and~/.yarnrc.yml. If any setshttpProxy,httpsProxy,networkSettings,enableStrictSsl: false(also0, or an env default like"${X:-false}") orunsafeHttpWhitelist, it refuses and names the setting and file, never the value. An unreadable rc is refused too (fail closed).jf ccredential would actually be lent. A freshyarn.lock(no install), an anonymousjf cserver, or a token of the project's own are not refused.YARN_RC_FILENAME.Impact
jf caon Yarn 2, 3 and 4.~/.yarnrc.yml) no longer gets thejf cfallback and must put their own token in.yarnrc.yml. The error says so.jf cserver, setYARN_UNSAFE_HTTP_WHITELISTin the environment, notunsafeHttpWhitelistin the rc. The Yarn integration tests now do this.unsafeHttpWhitelistshould stay refused.Tests
Unit tests for each setting in the project, parent and home files, plus the cases that must not be refused (clean rc, fresh lockfile, anonymous server, own token). Also checked end to end on Yarn 2.4.1 to 4.15.0.