Skip to content

Commit

Permalink
Properly obfuscate query parameters in logs (#3793)
Browse files Browse the repository at this point in the history
* fix-3789

* fix3789 add unit test
  • Loading branch information
youngerong authored and flovilmart committed May 11, 2017
1 parent 22ba398 commit e0be653
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions spec/CloudCodeLogger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,20 @@ describe("Cloud Code Logger", () => {
.then(null, e => done.fail(JSON.stringify(e)));
}).pend('needs more work.....');
});

it('cloud function should obfuscate password', done => {
const logController = new LoggerController(new WinstonLoggerAdapter());

Parse.Cloud.define('testFunction', (req, res) => {
res.success(1002,'verify code success');
});

Parse.Cloud.run('testFunction', {username:'hawk',password:'123456'})
.then(() => logController.getLogs({ from: Date.now() - 500, size: 1000 }))
.then((res) => {
const entry = res[0];
expect(entry.params.password).toMatch(/\*\*\*\*\*\*\*\*/);
done();
})
.then(null, e => done.fail(e));
});
9 changes: 9 additions & 0 deletions src/Controllers/LoggerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export class LoggerController extends AdaptableController {
}
}

if (e.params) {
for (const key of Object.keys(e.params)) {
if (key === 'password') {
e.params[key] = '********';
break;
}
}
}

return e;
});
}
Expand Down

0 comments on commit e0be653

Please sign in to comment.