Skip to content

use fully-resolved URI with custom scheme for HTTP Referer header, or a different header name entirely #930

Closed
@isaacs

Description

@isaacs

Background

The fact that the npm client sends a referer header with a redacted copy of the npm command is cute, and not exactly a violation of the HTTP specification, but a weird use of it, which has caused some recent disruptions and pushback.

The reason for choosing Referer in the first place is that it is very reliably left intact by proxies. And, semantically, the resource represented by the command sent to npm is the "thing" that triggered the request. However:

  1. Losing some data is not so bad. We already use npm-session and a few pacote headers, and rely on them in our registry data analysis. Some of them undoubtably get dropped by over eager proxies more frequently than Referer would, but it's fine.
  2. Using something other than a fully qualified URI is treated by some heuristics as an indication of malicious requests. While this is arguably inappropriate, it certainly does exist.
  3. Originally this was a way for us to help determine the frequency of install vs update vs install with a given argument. Well, in practice, some 99% or more of all requests are just Referer: install, so it doesn't actually provide much value in practice in aggregate. However, it can provide some insight in certain debugging scenarios, so it's not completely without merit.

Proposed Change

  • Remove the referer header from all npm CLI requests.
  • Add a npm-command header to registry requests, with the current value of the Referer header.

Alternatively, don't send an npm-command header, since it's always install anyway. (And when it isn't, there's usually a way to infer what's going on from the HTTP verb and route.)

Example

No user-facing changes, except that referer: in a typical npm request will be replaced with npm-command:.

How

Current Behaviour

npm sends a referer: header.

Desired Behaviour

npm does not send a referer: header.

Implementation

  • Unless a referer header is explicitly supplied in the headers option to make-fetch-happen, do not send a referer header.
  • Remove the --refer config flag in the cli where it calculates and redacts based on the argv.
  • Remove the refer field in npm.flatOptions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions