This repository was archived by the owner on Mar 11, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +25
-6
lines changed
Expand file tree Collapse file tree 5 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 11# UNRELEASED
22- [ FIXED] Expose BasePlugin.
3+ - [ FIXED] Prevent double encoding of credentials passed in URL user information
4+ when using the ` cookieauth ` plugin.
5+ - [ IMPROVED] Documented the characters that are required to be encoded in URL
6+ user information.
37- [ IMPROVED] Documented the legacy compatibility behaviour that always adds the
48 ` cookieauth ` plugin when using the initialization callback functionality.
59
Original file line number Diff line number Diff line change @@ -156,7 +156,20 @@ var Cloudant = require('@cloudant/cloudant');
156156var cloudant = Cloudant (" http://MYUSERNAME:MYPASSWORD@localhost:5984" );
157157~~~
158158
159- ** Note** : If you pass in a ` username ` , ` password ` , and ` url ` that contains
159+ ** Note** : It is preferred to pass credentials using the ` account ` /` username ` and
160+ ` password ` configuration options rather than as part of the URL. However, if you
161+ choose to pass credentials in the user information subcomponent of the URL then
162+ they must be [ percent encoded] ( https://tools.ietf.org/html/rfc3986#section-3.2.1 ) .
163+ Specifically within either the username or passowrd the characters ` : / ? # [ ] @ % `
164+ _ MUST_ be precent-encoded, other characters _ MAY_ be percent encoded.
165+ For example for the username ` user123 ` and password ` colon:at@321 ` :
166+ ```
167+ https://user123:colon%3aat%40321@localhost:5984
168+ ```
169+ Credentials must not be percent encoded when passing them via other configuration
170+ options besides ` url ` .
171+
172+ If you pass in ` username ` and ` password ` options and a ` url ` that contains
160173credentials, the ` username ` and ` password ` will supercede the credentials within
161174the ` url ` . For example, ` myusername ` and ` mypassword ` will be used in the code
162175below during authentication:
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ class CookieTokenManager extends TokenManager {
2929 this . _client ( {
3030 url : this . _sessionUrl ,
3131 method : 'POST' ,
32- form : {
32+ json : true ,
33+ body : {
3334 name : this . _username ,
3435 password : this . _password
3536 } ,
Original file line number Diff line number Diff line change @@ -49,8 +49,9 @@ class CookiePlugin extends BasePlugin {
4949 client ,
5050 this . _jar ,
5151 u . format ( sessionUrl , { auth : false } ) ,
52- sessionUrl . username ,
53- sessionUrl . password
52+ // Extract creds from URL and decode
53+ decodeURIComponent ( sessionUrl . username ) ,
54+ decodeURIComponent ( sessionUrl . password )
5455 ) ;
5556
5657 if ( cfg . autoRenew ) {
Original file line number Diff line number Diff line change @@ -21,10 +21,10 @@ const nock = require('../nock.js');
2121const uuidv4 = require ( 'uuid/v4' ) ; // random
2222
2323const ME = process . env . cloudant_username || 'nodejs' ;
24- const PASSWORD = process . env . cloudant_password || 'sjedon' ;
24+ const PASSWORD = process . env . cloudant_password || 'sjedon!@#"£$%^&*() ' ;
2525const SERVER = process . env . SERVER_URL || `https://${ ME } .cloudant.com` ;
2626const SERVER_NO_PROTOCOL = SERVER . replace ( / ^ h t t p s ? : \/ \/ / , '' ) ;
27- const SERVER_WITH_CREDS = `https://${ ME } :${ PASSWORD } @${ SERVER_NO_PROTOCOL } ` ;
27+ const SERVER_WITH_CREDS = `https://${ ME } :${ encodeURIComponent ( PASSWORD ) } @${ SERVER_NO_PROTOCOL } ` ;
2828const DBNAME = `/nodejs-cloudant-${ uuidv4 ( ) } ` ;
2929const COOKIEAUTH_PLUGIN = [ { cookieauth : { autoRenew : false } } ] ;
3030
You can’t perform that action at this time.
0 commit comments