Skip to content

XRAY-171572 - Refuse yarn jf c fallback with proxy or TLS settings - #953

Open
Phavya-jfrog wants to merge 2 commits into
jfrog:devfrom
Phavya-jfrog:feature/XRAY-171572-yarn-proxy
Open

Phavya-jfrog wants to merge 2 commits into
jfrog:devfrom
Phavya-jfrog:feature/XRAY-171572-yarn-proxy

Conversation

@Phavya-jfrog

@Phavya-jfrog Phavya-jfrog commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

We already check that the registry is on the jf c host, but not how Yarn reaches it. A project can keep the registry on the right host and still add httpProxy/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

  • Refuse before lending. jf ca checks every .yarnrc.yml Yarn reads: the project, the parent dirs of the temp copy Yarn runs in, and ~/.yarnrc.yml. If any sets httpProxy, httpsProxy, networkSettings, enableStrictSsl: false (also 0, or an env default like "${X:-false}") or unsafeHttpWhitelist, it refuses and names the setting and file, never the value. An unreadable rc is refused too (fail closed).
  • Only where the token could leak. The check runs after the project copy, right before the install, and only when the jf c credential would actually be lent. A fresh yarn.lock (no install), an anonymous jf c server, or a token of the project's own are not refused.
  • Random env var. The token's env var name is now random per run and unset afterwards, so a project can't reference it by name.
  • Honors YARN_RC_FILENAME.

Impact

  • Closes the proxy/TLS leak path for jf ca on Yarn 2, 3 and 4.
  • Behavior change: a developer with a legitimate proxy (project or ~/.yarnrc.yml) no longer gets the jf c fallback and must put their own token in .yarnrc.yml. The error says so.
  • For a plain-http jf c server, set YARN_UNSAFE_HTTP_WHITELIST in the environment, not unsafeHttpWhitelist in the rc. The Yarn integration tests now do this.
  • Open for Security: whether unsafeHttpWhitelist should 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.

Screenshot 2026-11-19 at 3 48 25 PM

@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI; Enforced overrides: Organization, Workspace
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: 5abc352f-2397-4508-ba91-94b3b1aa7b8f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

if yarnrcValueIsSet(raw["httpsProxy"]) {
add("httpsProxy")
}
if yarnrcValueIsFalse(raw["enableStrictSsl"]) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@gauriy-tech

Copy link
Copy Markdown
Collaborator

Question on the design: ~/.yarnrc.yml and the parents of the temp copy are refused exactly like the project's own rc, although a project can't write to them. A developer with a corporate proxy in ~/.yarnrc.yml loses the jf c fallback, which the description notes. Was refusing those files intentional, or would refusing only the project's rc (and the temp-base parents) be acceptable? I also couldn't find the alternatives noted anywhere, for example forcing YARN_HTTPS_PROXY= and YARN_ENABLE_STRICT_SSL=true for the child (env overrides rc on Yarn 2.4.1, 3.2.1 and 4.5.0, though it doesn't cover networkSettings, the whitelist or CA keys). It may be worth a line in the description on why the denylist was chosen, and that a project shipping yarnPath or plugins runs code with the token's env var visible, which this check doesn't address.


Review generated by xray-pr-review

This branch is waiting to be deployed

1 waiting deployment
frogbot — 6264bcd0 Waiting Nov 20, 2026 by Phavya-jfrog via scan-pull-request #4839
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants