@@ -62,7 +62,7 @@ module.exports = (function sailsPostgresql() {
62
62
} ) . execSync ( ) ;
63
63
} catch ( e ) {
64
64
setImmediate ( function done ( ) {
65
- return cb ( e ) ;
65
+ return cb ( redactPasswordsInMeta ( e ) ) ;
66
66
} ) ;
67
67
return ;
68
68
}
@@ -95,14 +95,14 @@ module.exports = (function sailsPostgresql() {
95
95
modelDefinitions : modelDefinitions
96
96
} ) . switch ( {
97
97
error : function error ( err ) {
98
- return next ( err ) ;
98
+ return next ( redactPasswordsInMeta ( err ) ) ;
99
99
} ,
100
100
success : function success ( ) {
101
101
return next ( ) ;
102
102
}
103
103
} ) ;
104
104
} , function asyncCb ( err ) {
105
- cb ( err ) ;
105
+ cb ( redactPasswordsInMeta ( err ) ) ;
106
106
} ) ;
107
107
} ,
108
108
@@ -130,12 +130,12 @@ module.exports = (function sailsPostgresql() {
130
130
query : query
131
131
} ) . switch ( {
132
132
error : function error ( err ) {
133
- return cb ( err ) ;
133
+ return cb ( redactPasswordsInMeta ( err ) ) ;
134
134
} ,
135
135
notUnique : function error ( errInfo ) {
136
136
var e = new Error ( errInfo . message ) ;
137
137
e . footprint = errInfo . footprint ;
138
- return cb ( e ) ;
138
+ return cb ( redactPasswordsInMeta ( e ) ) ;
139
139
} ,
140
140
success : function success ( report ) {
141
141
var record = report && report . record || undefined ;
@@ -158,12 +158,12 @@ module.exports = (function sailsPostgresql() {
158
158
query : query
159
159
} ) . switch ( {
160
160
error : function error ( err ) {
161
- return cb ( err ) ;
161
+ return cb ( redactPasswordsInMeta ( err ) ) ;
162
162
} ,
163
163
notUnique : function error ( errInfo ) {
164
164
var e = new Error ( errInfo . message ) ;
165
165
e . footprint = errInfo . footprint ;
166
- return cb ( e ) ;
166
+ return cb ( redactPasswordsInMeta ( e ) ) ;
167
167
} ,
168
168
success : function success ( report ) {
169
169
var records = report && report . records || undefined ;
@@ -186,7 +186,7 @@ module.exports = (function sailsPostgresql() {
186
186
query : query
187
187
} ) . switch ( {
188
188
error : function error ( err ) {
189
- return cb ( err ) ;
189
+ return cb ( redactPasswordsInMeta ( err ) ) ;
190
190
} ,
191
191
success : function success ( report ) {
192
192
return cb ( undefined , report . records ) ;
@@ -208,12 +208,12 @@ module.exports = (function sailsPostgresql() {
208
208
query : query
209
209
} ) . switch ( {
210
210
error : function error ( err ) {
211
- return cb ( err ) ;
211
+ return cb ( redactPasswordsInMeta ( err ) ) ;
212
212
} ,
213
213
notUnique : function error ( errInfo ) {
214
214
var e = new Error ( errInfo . message ) ;
215
215
e . footprint = errInfo . footprint ;
216
- return cb ( e ) ;
216
+ return cb ( redactPasswordsInMeta ( e ) ) ;
217
217
} ,
218
218
success : function success ( report ) {
219
219
if ( report ) {
@@ -239,7 +239,7 @@ module.exports = (function sailsPostgresql() {
239
239
query : query
240
240
} ) . switch ( {
241
241
error : function error ( err ) {
242
- return cb ( err ) ;
242
+ return cb ( redactPasswordsInMeta ( err ) ) ;
243
243
} ,
244
244
success : function success ( report ) {
245
245
if ( report ) {
@@ -265,7 +265,7 @@ module.exports = (function sailsPostgresql() {
265
265
query : query
266
266
} ) . switch ( {
267
267
error : function error ( err ) {
268
- return cb ( err ) ;
268
+ return cb ( redactPasswordsInMeta ( err ) ) ;
269
269
} ,
270
270
success : function success ( report ) {
271
271
return cb ( undefined , report ) ;
@@ -287,7 +287,7 @@ module.exports = (function sailsPostgresql() {
287
287
query : query
288
288
} ) . switch ( {
289
289
error : function error ( err ) {
290
- return cb ( err ) ;
290
+ return cb ( redactPasswordsInMeta ( err ) ) ;
291
291
} ,
292
292
success : function success ( report ) {
293
293
return cb ( undefined , report ) ;
@@ -309,7 +309,7 @@ module.exports = (function sailsPostgresql() {
309
309
query : query
310
310
} ) . switch ( {
311
311
error : function error ( err ) {
312
- return cb ( err ) ;
312
+ return cb ( redactPasswordsInMeta ( err ) ) ;
313
313
} ,
314
314
success : function success ( report ) {
315
315
return cb ( undefined , report ) ;
@@ -331,7 +331,7 @@ module.exports = (function sailsPostgresql() {
331
331
query : query
332
332
} ) . switch ( {
333
333
error : function error ( err ) {
334
- return cb ( err ) ;
334
+ return cb ( redactPasswordsInMeta ( err ) ) ;
335
335
} ,
336
336
success : function success ( report ) {
337
337
return cb ( undefined , report ) ;
@@ -364,7 +364,7 @@ module.exports = (function sailsPostgresql() {
364
364
meta : meta
365
365
} ) . switch ( {
366
366
error : function error ( err ) {
367
- return cb ( err ) ;
367
+ return cb ( redactPasswordsInMeta ( err ) ) ;
368
368
} ,
369
369
success : function success ( report ) {
370
370
// Waterline expects the result to be undefined if the table doesn't
@@ -393,7 +393,7 @@ module.exports = (function sailsPostgresql() {
393
393
meta : meta
394
394
} ) . switch ( {
395
395
error : function error ( err ) {
396
- return cb ( err ) ;
396
+ return cb ( redactPasswordsInMeta ( err ) ) ;
397
397
} ,
398
398
success : function success ( ) {
399
399
return cb ( ) ;
@@ -414,7 +414,7 @@ module.exports = (function sailsPostgresql() {
414
414
meta : meta
415
415
} ) . switch ( {
416
416
error : function error ( err ) {
417
- return cb ( err ) ;
417
+ return cb ( redactPasswordsInMeta ( err ) ) ;
418
418
} ,
419
419
success : function success ( ) {
420
420
return cb ( ) ;
@@ -435,10 +435,10 @@ module.exports = (function sailsPostgresql() {
435
435
meta : meta
436
436
} ) . switch ( {
437
437
error : function error ( err ) {
438
- return cb ( err ) ;
438
+ return cb ( redactPasswordsInMeta ( err ) ) ;
439
439
} ,
440
440
badConnection : function badConnection ( err ) {
441
- return cb ( err ) ;
441
+ return cb ( redactPasswordsInMeta ( err ) ) ;
442
442
} ,
443
443
success : function success ( ) {
444
444
return cb ( ) ;
@@ -460,7 +460,7 @@ module.exports = (function sailsPostgresql() {
460
460
meta : meta
461
461
} ) . switch ( {
462
462
error : function error ( err ) {
463
- return cb ( err ) ;
463
+ return cb ( redactPasswordsInMeta ( err ) ) ;
464
464
} ,
465
465
success : function success ( ) {
466
466
return cb ( ) ;
@@ -472,3 +472,19 @@ module.exports = (function sailsPostgresql() {
472
472
473
473
return adapter ;
474
474
} ) ( ) ;
475
+
476
+ var REDACT_REPLACEMENT = '$1:****@' ;
477
+ var REDACT_REGEX_SINGLE = / ^ ( p o s t g r e s : \/ \/ [ ^ : \s ] * ) : [ ^ @ \s ] * @ / ;
478
+ var REDACT_REGEX_MULTI = / ( p o s t g r e s : \/ \/ [ ^ : \s ] * ) : [ ^ @ \s ] * @ / g;
479
+
480
+ function redactPasswordsInMeta ( err ) {
481
+ if ( err ) {
482
+ if ( err . meta && err . meta . url ) {
483
+ err . meta . url = err . meta . url . replace ( REDACT_REGEX_SINGLE , REDACT_REPLACEMENT ) ;
484
+ }
485
+ if ( err . message ) {
486
+ err . message = err . message . replace ( REDACT_REGEX_MULTI , REDACT_REPLACEMENT ) ;
487
+ }
488
+ }
489
+ return err ;
490
+ }
0 commit comments