Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

couchdb-auth-proxy

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

couchdb-auth-proxy - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

159

index.js

@@ -11,4 +11,117 @@ 'use strict';

var name = "couchdb-auth-proxy";
var version = "1.1.2";
var version = "1.1.3";
var asyncGenerator = function () {
function AwaitValue(value) {
this.value = value;
}
function AsyncGenerator(gen) {
var front, back;
function send(key, arg) {
return new Promise(function (resolve, reject) {
var request = {
key: key,
arg: arg,
resolve: resolve,
reject: reject,
next: null
};
if (back) {
back = back.next = request;
} else {
front = back = request;
resume(key, arg);
}
});
}
function resume(key, arg) {
try {
var result = gen[key](arg);
var value = result.value;
if (value instanceof AwaitValue) {
Promise.resolve(value.value).then(function (arg) {
resume("next", arg);
}, function (arg) {
resume("throw", arg);
});
} else {
settle(result.done ? "return" : "normal", result.value);
}
} catch (err) {
settle("throw", err);
}
}
function settle(type, value) {
switch (type) {
case "return":
front.resolve({
value: value,
done: true
});
break;
case "throw":
front.reject(value);
break;
default:
front.resolve({
value: value,
done: false
});
break;
}
front = front.next;
if (front) {
resume(front.key, front.arg);
} else {
back = null;
}
}
this._invoke = send;
if (typeof gen.return !== "function") {
this.return = undefined;
}
}
if (typeof Symbol === "function" && Symbol.asyncIterator) {
AsyncGenerator.prototype[Symbol.asyncIterator] = function () {
return this;
};
}
AsyncGenerator.prototype.next = function (arg) {
return this._invoke("next", arg);
};
AsyncGenerator.prototype.throw = function (arg) {
return this._invoke("throw", arg);
};
AsyncGenerator.prototype.return = function (arg) {
return this._invoke("return", arg);
};
return {
wrap: function (fn) {
return function () {
return new AsyncGenerator(fn.apply(this, arguments));
};
},
await: function (value) {
return new AwaitValue(value);
}
};
}();
var asyncToGenerator = function (fn) {

@@ -31,5 +144,5 @@ return function () {

return Promise.resolve(value).then(function (value) {
return step("next", value);
step("next", value);
}, function (err) {
return step("throw", err);
step("throw", err);
});

@@ -44,4 +157,4 @@ }

function index (fn) {
let opts = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
function couchdbAuthProxy(fn) {
let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -55,4 +168,4 @@ if (typeof fn === "object") {

}var _opts = opts;
let via = _opts.via;
let secret = _opts.secret;
let via = _opts.via,
secret = _opts.secret;
var _opts$target = _opts.target;

@@ -88,3 +201,3 @@ let target = _opts$target === undefined ? "http://localhost:5984" : _opts$target;

const existing = res.getHeader("Via");
const viaheader = `${ existing ? existing + ", " : "" }${ req.httpVersion } ${ via } (${ name }/${ version })`;
const viaheader = `${existing ? existing + ", " : ""}${req.httpVersion} ${via} (${name}/${version})`;
res.setHeader("Via", viaheader);

@@ -104,6 +217,12 @@ });

if (ctx != null) {
var _headerFields = headerFields;
const username = _headerFields.username,
roles = _headerFields.roles,
token = _headerFields.token;
cleanHeaders(req, [username, roles, token]);
const n = typeof ctx.name === "string" ? ctx.name : "";
req.headers[headerFields.username] = n;
req.headers[headerFields.roles] = Array.isArray(ctx.roles) ? ctx.roles.join(",") : "";
if (secret) req.headers[headerFields.token] = signRequest(n, secret);
req.headers[username] = n;
req.headers[roles] = Array.isArray(ctx.roles) ? ctx.roles.join(",") : "";
if (secret) req.headers[token] = sign(n, secret);
}

@@ -124,9 +243,9 @@

// couchdb proxy signed token
function signRequest(user, secret) {
const sign = couchdbAuthProxy.sign = function (user, secret) {
return crypto.createHmac("sha1", secret).update(user).digest("hex");
}
};
// for methods that we don't know if they are callback or promise async
function confusedAsync(fn, ctx) {
let args = arguments.length <= 2 || arguments[2] === undefined ? [] : arguments[2];
let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];

@@ -144,2 +263,12 @@ if (fn.length > args.length) {

module.exports = index;
// removes a list of headers from a request
// accounts for Node.js lowercase headers
// https://github.com/tyler-johnson/couchdb-auth-proxy/issues/7
function cleanHeaders(req, headers) {
headers.forEach(header => {
delete req.headers[header];
delete req.headers[header.toLowerCase()];
});
}
module.exports = couchdbAuthProxy;

9

package.json
{
"name": "couchdb-auth-proxy",
"version": "1.1.2",
"version": "1.1.3",
"description": "An HTTP reverse proxy library for quick and dirty Couchdb proxy authentication",

@@ -14,2 +14,3 @@ "author": "Tyler Johnson <tyler@tylerjohnson.me>",

"build": "make clean && make",
"test": "make test.js && node test.js",
"prepublish": "npm run build",

@@ -33,5 +34,9 @@ "autorelease": "autorelease pre && npm publish && autorelease post"

"eslint": "^3.2.2",
"express": "^4.15.2",
"rollup": "^0.34.3",
"rollup-plugin-babel": "^2.6.1",
"rollup-plugin-json": "^2.0.1"
"rollup-plugin-json": "^2.0.1",
"supertest": "^3.0.0",
"tape": "^4.6.3",
"tape-promise": "^2.0.1"
},

@@ -38,0 +43,0 @@ "keywords": [],

@@ -1,4 +0,4 @@

# couchdb-auth-proxy
# CouchDB Auth Proxy
[![npm](https://img.shields.io/npm/v/couchdb-auth-proxy.svg)](https://www.npmjs.com/package/couchdb-auth-proxy) [![David](https://img.shields.io/david/tyler-johnson/couchdb-auth-proxy.svg)](https://david-dm.org/tyler-johnson/couchdb-auth-proxy) [![Build Status](https://travis-ci.org/tyler-johnson/couchdb-auth-proxy.svg?branch=master)](https://travis-ci.org/tyler-johnson/couchdb-auth-proxy)
[![npm](https://img.shields.io/npm/v/couchdb-auth-proxy.svg)](https://www.npmjs.com/package/couchdb-auth-proxy) [![Build Status](https://travis-ci.org/tyler-johnson/couchdb-auth-proxy.svg?branch=master)](https://travis-ci.org/tyler-johnson/couchdb-auth-proxy)

@@ -69,3 +69,3 @@ A Node.js HTTP reverse proxy library for quick and dirty CouchDB proxy authentication.

- `options.target` (String) - The URL of the CouchDB server to proxy to. This server must have [proxy authentication enabled](http://docs.couchdb.org/en/1.6.1/api/server/authn.html#proxy-authentication). Defaults to `http://localhost:5984`.
- `options.secret` (String) - The [CouchDB secret](http://docs.couchdb.org/en/1.6.1/config/auth.html#couch_httpd_auth/secret) used to sign proxy tokens and cookies. This is very much an optional parameter and in general there is very little reason to use a secret. This is only absolutely required if `couch_httpd_auth/proxy_use_secret` is enabled on CouchDB.
- `options.secret` (String) - The [CouchDB secret](http://docs.couchdb.org/en/1.6.1/config/auth.html#couch_httpd_auth/secret) used to sign proxy tokens and cookies. This is only required if `couch_httpd_auth/proxy_use_secret` is enabled on CouchDB (which is recommended).
- `options.via` (String) - The name of the proxy to add to the `Via` header. This is so consumers of the HTTP API can tell that the request was directed through a proxy. This is optional and the `Via` header will be excluded when not provided.

@@ -72,0 +72,0 @@ - `options.headerFields` (Object) - A map of custom header fields to use for the proxy. This should match what is declared in CouchDB `couch_httpd_auth` configuration, under `x_auth_roles`, `x_auth_token`, and `x_auth_username`. This is the default map:

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc