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
11 changes: 11 additions & 0 deletions lib/transport/selenium-webdriver/httpclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ module.exports = function(settings, HttpResponse) {

}

isDataRedacted(data) {
for (const value of Object.values(data)) {
if (typeof(value) === 'string' && value.includes('\uE000')) {
return true;
}
}

return false;
}

/** @override */
send(httpRequest) {
const {method, data, path} = httpRequest;
Expand All @@ -52,6 +62,7 @@ module.exports = function(settings, HttpResponse) {
this.options.data = data;
this.options.path = path;
this.options.method = method;
this.options.redact = this.isDataRedacted(data);

const request = new HttpRequest(this.options);

Expand Down
14 changes: 10 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 @@ -591,11 +591,12 @@ module.exports = class MethodMappings {
},

setElementValueRedacted(...args) {
// FIXME: redact password in verbose HTTP logs, it's only redacted in the command logs
args.push(true); // Passing true for readacting.

return this.methods.session.setElementValue.call(this, ...args);
},

async setElementValue(webElementOrId, value) {
async setElementValue(webElementOrId, value, redacted = false) {
if (Array.isArray(value)) {
value = value.join('');
} else {
Expand All @@ -612,7 +613,12 @@ module.exports = class MethodMappings {
throw err;
}
}
await element.sendKeys(value);
if (redacted) {
// Using Key.NULL as a flag for redacted values.
await element.sendKeys(value, Key.NULL);
} else {
await element.sendKeys(value);
}

return null;
},
Expand Down
Loading