Skip to content

Commit

Permalink
add npm_client_version config option
Browse files Browse the repository at this point in the history
- to restrict which npm clients can login
  • Loading branch information
mstorus committed Jan 9, 2015
1 parent ed3eb37 commit ea16133
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function Config(config) {
}
}

if (!self.npm_client_version) {
self.npm_client_version = "*"
}

var users = {all:true, anonymous:true, 'undefined':true, owner:true, none:true}

var check_user_or_uplink = function(arg) {
Expand Down
6 changes: 6 additions & 0 deletions lib/index-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var expressJson5 = require('express-json5')
var Error = require('http-errors')
var Path = require('path')
var Middleware = require('./middleware')
var Semver = require('semver');
var Utils = require('./utils')
var expect_json = Middleware.expect_json
var match = Middleware.match
Expand Down Expand Up @@ -119,6 +120,11 @@ module.exports = function(config, auth, storage) {
var token = (req.body.name && req.body.password)
? auth.aes_encrypt(req.body.name + ':' + req.body.password).toString('base64')
: undefined

if (!Semver.satisfies(req.header('version'), config.npm_client_version)) {
return next( Error[422]('Your npm version is not accepted. Required: "' + config.npm_client_version + '" Received: "' + req.header('version') + '"') )
}

if (req.remote_user.name != null) {
res.status(201)
return next({
Expand Down

0 comments on commit ea16133

Please sign in to comment.