Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

user-agent truncated #2852

Closed
regiskuckaertz opened this Issue · 1 comment

2 participants

@regiskuckaertz

Hello,

Due to our internal security policy, I must set up npm so that a common UA string is sent with each request. I'm using FF 14's (on Windows):

Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1

but it looks like the string is truncated where an ; occurs, hence the following string is sent:

Mozilla/5.0 (Windows NT 6.1

I found the culprit in npm/node_modules/ini/ini.js, lines 59-60:

var rem = line.indexOf(";")
if (rem !== -1) line = line.substr(0, rem)//.trim()

However, commenting these lines out did not change anything. So I wondered if the UA header was ever used in the request, but I got lost at some point in npm/node_modules/npm-registry-client/lib/request.js.

That's why I'm getting back to you: is it possible that despite the UA string is correctly set, it is never used in the current version of the app?

Cheers

@isaacs
Owner

It's definitely a matter of truncating in the ini file. Observe:

$ # no npmrc file
$ ls -laF ~/.npmrc
-rw-r--r--  1 isaacs  staff  0 Oct  4 08:51 /Users/isaacs/.npmrc

$ # start up a dummy server that just dumps headers.  doesn't actually *work* of course, but just for testing.
$ node -e "require('http').createServer(function(q,s){ console.log(q.headers); s.end('ok') }).listen(1234)" &
[1] 37412

$ # now send a request with a cli-set user-agent
$ npm view npm --user-agent "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1" --registry http://localhost:1234/ --loglevel silent
{ accept: 'application/json',
  'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1',
  host: 'localhost:1234',
  connection: 'keep-alive' }

$ # set it in the ini file
$ npm config set user-agent 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1'
$ cat ~/.npmrc
user-agent = Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1

$ # see if it picks it up
$ npm view npm --registry http://localhost:1234/ --loglevel silent
{ accept: 'application/json',
  'user-agent': 'Mozilla/5.0 (Windows NT 6.1',
  host: 'localhost:1234',
  connection: 'keep-alive' }

$ # there's the bug^
$ # does the file have the right contents?
$ cat ~/.npmrc
user-agent = Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1

$ # yes, it does.  so it's an ini-read issue.
$ # try using the environment to set the UA
$ export npm_config_user_agent='Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1'
$ npm view npm --registry http://localhost:1234/ --loglevel silent
{ accept: 'application/json',
  'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:14.0) Gecko/20120405 Firefox/14.0a1',
  host: 'localhost:1234',
  connection: 'keep-alive' }

$ # yep, that works.

Issue: isaacs/ini#9

@isaacs isaacs closed this
@isaacs isaacs referenced this issue from a commit in isaacs/ini
@isaacs isaacs Fix #9 Allow escaped ; chars in values 3438987
@isaacs isaacs reopened this
@isaacs isaacs closed this issue from a commit
@isaacs isaacs ini@1.0.5
fix #2852
d05e632
@isaacs isaacs closed this in d05e632
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.