Skip to content

Commit e0be653

Browse files
youngerongflovilmart
authored andcommitted
Properly obfuscate query parameters in logs (#3793)
* fix-3789 * fix3789 add unit test
1 parent 22ba398 commit e0be653

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

spec/CloudCodeLogger.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,20 @@ describe("Cloud Code Logger", () => {
228228
.then(null, e => done.fail(JSON.stringify(e)));
229229
}).pend('needs more work.....');
230230
});
231+
232+
it('cloud function should obfuscate password', done => {
233+
const logController = new LoggerController(new WinstonLoggerAdapter());
234+
235+
Parse.Cloud.define('testFunction', (req, res) => {
236+
res.success(1002,'verify code success');
237+
});
238+
239+
Parse.Cloud.run('testFunction', {username:'hawk',password:'123456'})
240+
.then(() => logController.getLogs({ from: Date.now() - 500, size: 1000 }))
241+
.then((res) => {
242+
const entry = res[0];
243+
expect(entry.params.password).toMatch(/\*\*\*\*\*\*\*\*/);
244+
done();
245+
})
246+
.then(null, e => done.fail(e));
247+
});

src/Controllers/LoggerController.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@ export class LoggerController extends AdaptableController {
6464
}
6565
}
6666

67+
if (e.params) {
68+
for (const key of Object.keys(e.params)) {
69+
if (key === 'password') {
70+
e.params[key] = '********';
71+
break;
72+
}
73+
}
74+
}
75+
6776
return e;
6877
});
6978
}

0 commit comments

Comments
 (0)