Skip to content

Commit c84d0a4

Browse files
authored
scrub all requests and auth header, fix changeReader stall - fixes #255, #257 (#256)
* scrub all requests and auth header - fixes #255 * change changeReader to max out retry back-off at one minute, instead of infinite - fixes #257 * also scrub URL for response headers - #256
1 parent 1c46ec9 commit c84d0a4

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

lib/changesreader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ class ChangesReader {
210210
self.continue = false
211211
} else {
212212
// don't immediately retry on error - exponential back-off
213-
delay = delay ? Math.max(60000, delay * 2) : 5000
213+
delay = delay ? Math.min(60000, delay * 2) : 5000 // up to and no more than one minute
214214
}
215215

216216
self.ee.emit(EVENT_ERROR, err)

lib/nano.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ module.exports = exports = function dbScope (cfg) {
101101
}
102102
return str
103103
}
104+
105+
function scrubRequest (req, cloned) {
106+
// scrub credentials
107+
req.url = scrubURL(req.url)
108+
if (req.headers.cookie) {
109+
req.headers.cookie = 'XXXXXXX'
110+
}
111+
if (req.auth) {
112+
if (!cloned) {
113+
req.auth = JSON.parse(JSON.stringify(req.auth)) // clone just auth if not already cloned
114+
}
115+
req.auth.username = SCRUBBED_STR
116+
req.auth.password = SCRUBBED_STR
117+
}
118+
}
119+
104120
const responseHandler = function (response, req, opts, resolve, reject, callback) {
105121
const statusCode = response.status || (response.response && response.response.status) || 500
106122
if (response.isAxiosError && response.response) {
@@ -111,7 +127,7 @@ module.exports = exports = function dbScope (cfg) {
111127

112128
// let parsed
113129
const responseHeaders = Object.assign({
114-
uri: req.url,
130+
uri: scrubURL(req.url),
115131
statusCode: statusCode
116132
}, response.headers)
117133
if (!response.status) {
@@ -163,11 +179,7 @@ module.exports = exports = function dbScope (cfg) {
163179
delete body.stack
164180

165181
// scrub credentials
166-
req.url = scrubURL(req.url)
167-
responseHeaders.uri = scrubURL(responseHeaders.uri)
168-
if (req.headers.cookie) {
169-
req.headers.cookie = 'XXXXXXX'
170-
}
182+
scrubRequest(req)
171183

172184
log({ err: 'couch', body: body, headers: responseHeaders })
173185

@@ -201,6 +213,8 @@ module.exports = exports = function dbScope (cfg) {
201213
}
202214
const message = response.statusText
203215

216+
scrubRequest(req)
217+
204218
const responseHeaders = Object.assign({
205219
uri: req.url,
206220
statusCode: statusCode
@@ -368,11 +382,7 @@ module.exports = exports = function dbScope (cfg) {
368382

369383
// scrub and log
370384
const scrubbedReq = JSON.parse(JSON.stringify(req))
371-
scrubbedReq.url = scrubURL(scrubbedReq.url)
372-
if (scrubbedReq.auth) {
373-
scrubbedReq.auth.username = SCRUBBED_STR
374-
scrubbedReq.auth.password = SCRUBBED_STR
375-
}
385+
scrubRequest(scrubbedReq, true)
376386
log(scrubbedReq)
377387

378388
// add http agents

0 commit comments

Comments
 (0)