Skip to content

feat(core): Add user-agent header to network requests and create yarn version file#7155

Open
thegoddo wants to merge 1 commit into
yarnpkg:masterfrom
thegoddo:feat/yarn_user_agent
Open

feat(core): Add user-agent header to network requests and create yarn version file#7155
thegoddo wants to merge 1 commit into
yarnpkg:masterfrom
thegoddo:feat/yarn_user_agent

Conversation

@thegoddo

Copy link
Copy Markdown

What's the problem this PR addresses?

Currently, outgoing HTTP requests from Yarn do not specify a unique, standardized User-Agent header, causing underlying request engines (like got) to default to their own client string formats.

This presents a challenge for enterprise networks, corporate firewalls, and system administrators who monitor incoming telemetry. Without a distinct User-Agent identifying the package manager and its environment, administrators cannot accurately track, audit, or whitelist/allowlist traffic originating specifically from Yarn.

Closes #7146

How did you fix it?

  1. Injected a Fallback User-Agent: Added a standardized userAgent header within the central requestImpl execution loop inside packages/yarnpkg-core/sources/httpUtils.ts.
  2. Environment Safety: Constructed the string format as yarn/${yarnVersion} node/${process.version} to dynamically capture both the engine variant and runtime environment. It leverages the monorepo's YarnVersion module, safely falling back to an 'unknown' flag if running outside a packaged environment.
  3. Preserved Custom Overrides: Placed the new 'user-agent' property at the top of the headers assignment block inside gotOptions, using the object spread operator (...headers) right below it. This ensures any plugin or specific utility passing an explicit custom header will cleanly overwrite the default.
  4. Code Quality & Style Alignment: Adhered strictly to the project's codebase patterns by naming the internal variable in camelCase (userAgent), while keeping the network protocol configuration key lowercase ('user-agent') as expected by the underlying HTTP utility clients.
  5. Monorepo Release Syncing: Manually created a unified tracking map inside the .yarn/versions/ directory to explicitly link a patch release across @yarnpkg/core, @yarnpkg/cli, and its dependent monorepo workspaces to prevent pipeline dependency validation conflicts.

Checklist

  • I have read the Contributing Guide.

  • I have set the packages that need to be released for my changes to be effective.

  • I will check that all automated PR checks pass before the PR gets reviewed.

@thegoddo thegoddo changed the title Add user-agent header to network requests and create yarn version file FEAT: Add user-agent header to network requests and create yarn version file May 27, 2026
@thegoddo thegoddo changed the title FEAT: Add user-agent header to network requests and create yarn version file feat(core): Add user-agent header to network requests and create yarn version file May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Set a proper User-Agent header on outgoing HTTP request

1 participant