Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide password values from raw HTTP logs. #4066

Merged
Merged
7 changes: 6 additions & 1 deletion lib/http/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Auth = require('./auth.js');
const Formatter = require('./formatter.js');
const HttpResponse = require('./response.js');
const Utils = require('./../utils');
const {Key} = require('selenium-webdriver');
const {Logger, isString} = Utils;
const {DEFAULT_RUNNER_EVENTS: {LogCreated}, NightwatchEventHub} = require('../runner/eventHub.js');

Expand Down Expand Up @@ -126,7 +127,6 @@ class HttpRequest extends EventEmitter {
this.reqOptions = this.createHttpOptions(options);
this.hostname = Formatter.formatHostname(this.reqOptions.host, this.reqOptions.port, this.use_ssl);
this.retryAttempts = this.httpOpts.retry_attempts;
this.redact = options.redact || false;
garg3133 marked this conversation as resolved.
Show resolved Hide resolved

return this;
}
Expand Down Expand Up @@ -253,6 +253,11 @@ class HttpRequest extends EventEmitter {

return arg;
});
} else if (this.reqOptions.method === 'POST' && this.reqOptions.path.includes('/value')) {
if (params.text.startsWith(Key.NULL)){
params.text = '****';
params.value = '****'.split('');
}
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
}

const content = ` Request ${[this.reqOptions.method, this.hostname + this.reqOptions.path, retryStr + ' '].join(' ')}`;
Expand Down
16 changes: 12 additions & 4 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const {WebElement, WebDriver, Origin, By, until, Condition} = require('selenium-webdriver');
const {WebElement, WebDriver, Origin, By, until, Condition, Key} = require('selenium-webdriver');
const {Locator} = require('../../element');
const NightwatchLocator = require('../../element/locator-factory.js');
const {isString} = require('../../utils');
Expand Down Expand Up @@ -590,9 +590,17 @@ module.exports = class MethodMappings {
return null;
},

setElementValueRedacted(...args) {
// FIXME: redact password in verbose HTTP logs, it's only redacted in the command logs
return this.methods.session.setElementValue.call(this, ...args);
setElementValueRedacted(webElementOrId, value) {
let redactedValue;
if (value instanceof Array) {
value.unshift(Key.NULL);
redactedValue = value;
} else {
// Can be String or number.
redactedValue = Key.NULL + value;
}

garg3133 marked this conversation as resolved.
Show resolved Hide resolved
return this.methods.session.setElementValue.call(this, webElementOrId, redactedValue);
},

async setElementValue(webElementOrId, value) {
Expand Down
5 changes: 3 additions & 2 deletions test/src/api/commands/element/testSetPassword.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const assert = require('assert');
const {Key} = require('selenium-webdriver');
const MockServer = require('../../../../lib/mockserver.js');
const CommandGlobals = require('../../../../lib/globals/commands.js');

Expand All @@ -17,8 +18,8 @@ describe('setPassword', function() {
url: '/wd/hub/session/1352110219202/element/0/value',
method: 'POST',
postdata: {
text: 'password',
value: ['p', 'a', 's', 's', 'w', 'o', 'r', 'd']
text: Key.NULL + 'password',
value: [Key.NULL, 'p', 'a', 's', 's', 'w', 'o', 'r', 'd']
},
response: {
sessionId: '1352110219202',
Expand Down
Loading