Skip to content

feat(runner+browserstack): Mask sensitive data for Reporters (and more) #13938

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

Merged

Conversation

dprevost-LMI
Copy link
Contributor

@dprevost-LMI dprevost-LMI commented Dec 1, 2024

Proposed changes

To provide easier security, here is a PR which has two main goals:

  1. On the element.setValue, add a new boolean mask option allowing to mask from everyone besides appium the value set in an input element. This allows with the simple {mask : true} to hide the password, for example, of a real production user from wdio logs, any reporters, the performance tool and anyone listening on any emit. The cherry on top is the participation of appium's folks, where even in Appium's logs (see PR), this value continues to be masked with the simple boolean options. 🎉

    • Note: Some limitations exist
      1. Appium plugins, which we do not have control over.
      2. Only setValue and addValue commands are supported. Not the getValue, for example.
  2. A regex expression can now be configured in the wdio logs to hide more sensitive information. For example, when using BrowserStack, the user's key is in plain text. Now we can pass a simple regex pattern like maskingPattern: '--key=([^ ]*)', which will mask this value in the logs.

See the issue for the history of the discussion that led to the PR decisions.

Example for case 1:
Logs:
423178061-29c8d9bc-43a3-4187-b699-4dc16f18da0d

Allure-reporter
423178068-e0bd30a2-90b8-4ae3-a2bf-9ae0a0357d0d

Example for case 2:
423178049-d7a20a80-e3eb-4f81-a82e-47befcfeb0bf

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Further comments

Reviewers: @webdriverio/project-committers

Related to issue #13937
Appium-related issue

@dprevost-LMI dprevost-LMI changed the title [FEATURE] Masking sensitive data for Reporters and other tools using onBeforeComand & onAfterCommand [FEATURE]: Masking sensitive data for Reporters and other tools using onBeforeComand & onAfterCommand Dec 1, 2024
Copy link

pkg-pr-new bot commented Dec 1, 2024

Open in StackBlitz

eslint-plugin-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@13938

@wdio/allure-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@13938

@wdio/appium-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@13938

@wdio/browser-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@13938

@wdio/browserstack-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@13938

@wdio/cli

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@13938

@wdio/concise-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@13938

@wdio/config

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@13938

@wdio/cucumber-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@13938

@wdio/dot-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@13938

@wdio/firefox-profile-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@13938

@wdio/globals

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@13938

@wdio/jasmine-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@13938

@wdio/json-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@13938

@wdio/junit-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@13938

@wdio/lighthouse-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@13938

@wdio/local-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@13938

@wdio/logger

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@13938

@wdio/mocha-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@13938

@wdio/protocols

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@13938

@wdio/repl

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@13938

@wdio/reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@13938

@wdio/runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@13938

@wdio/sauce-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@13938

@wdio/shared-store-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@13938

@wdio/smoke-test-cjs-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@13938

@wdio/smoke-test-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@13938

@wdio/smoke-test-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@13938

@wdio/spec-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@13938

@wdio/static-server-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@13938

@wdio/sumologic-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@13938

@wdio/testingbot-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@13938

@wdio/types

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@13938

@wdio/utils

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@13938

@wdio/webdriver-mock-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@13938

webdriver

npm i https://pkg.pr.new/webdriverio/webdriverio/webdriver@13938

webdriverio

npm i https://pkg.pr.new/webdriverio/webdriverio@13938

commit: c86527d

@dprevost-LMI dprevost-LMI changed the title [FEATURE]: Masking sensitive data for Reporters and other tools using onBeforeComand & onAfterCommand feat(runner+browserstack) Masking sensitive data for Reporters and other tools using onBeforeComand & onAfterCommand Dec 2, 2024
@dprevost-LMI dprevost-LMI changed the title feat(runner+browserstack) Masking sensitive data for Reporters and other tools using onBeforeComand & onAfterCommand feat(runner+browserstack) Mask sensitive data for Reporters and other tools on the before/after hook Dec 2, 2024
@dprevost-LMI dprevost-LMI changed the title feat(runner+browserstack) Mask sensitive data for Reporters and other tools on the before/after hook feat(runner+browserstack) Mask sensitive data for Reporters (and more) on the before/after hook Dec 2, 2024
@dprevost-LMI dprevost-LMI changed the title feat(runner+browserstack) Mask sensitive data for Reporters (and more) on the before/after hook feat(runner+browserstack): Mask sensitive data for Reporters (and more) on the before/after hook Dec 2, 2024
@dprevost-LMI dprevost-LMI force-pushed the masked-sensible-information branch from f1c6a2e to 13570dc Compare December 8, 2024 19:38
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments

@dprevost-LMI dprevost-LMI force-pushed the masked-sensible-information branch 2 times, most recently from 7a712fc to b6a4f6c Compare December 10, 2024 00:04
@dprevost-LMI dprevost-LMI changed the title feat(runner+browserstack): Mask sensitive data for Reporters (and more) on the before/after hook feat(runner+browserstack): Mask sensitive data for Reporters (and more) Dec 10, 2024
@christian-bromann
Copy link
Member

Just to note here: we are working with different logs:

  • WDIO logs like in this screenshot:
    image
  • Appium logs that Appium is creating and may be intercepted by WebdriverIO
  • Vendor logs

It would be awesome if the solution:

  • sends the actual value to Appium, e.g. when calling $('selector').setValue(process.env.SECRET_PASSWORD) but masks them in the wdio logs which requires changes to transformCommandLogResult
  • applies automatically log filters to Appium when user uses @wdio/appium-service and warns the user to apply them when an independent Appium server is being used

I am open to how the mask option look like as long as it is intuitive. Maybe there is an NPM package that detects secrets and can give us an indication whether we should mask it. Otherwise aligning with what Appium does makes total sense to me.

I don't think we can do anything about what the Vendor displays in their UI.

Hope this makes sense. Please let me know.

@dprevost-LMI
Copy link
Contributor Author

dprevost-LMI commented Dec 12, 2024

Let's settle this in the issue! #13937 (comment)

@dprevost-LMI dprevost-LMI force-pushed the masked-sensible-information branch from 33f944e to 71c8369 Compare January 25, 2025 19:49
@dprevost-LMI dprevost-LMI force-pushed the masked-sensible-information branch from 71c8369 to f7489c7 Compare March 16, 2025 01:08
@dprevost-LMI dprevost-LMI force-pushed the masked-sensible-information branch 2 times, most recently from 1fdd837 to b9e3b25 Compare March 21, 2025 12:22
@dprevost-LMI dprevost-LMI force-pushed the masked-sensible-information branch from 7cf4895 to 3a088a9 Compare May 10, 2025 17:11
@dprevost-LMI dprevost-LMI force-pushed the masked-sensible-information branch 2 times, most recently from 480dd57 to 90647ae Compare May 29, 2025 11:25
Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add some documentation for the new property somewhere here? I think it would help folks to discover this feature much better. I think we can just copy the docs from the logger readme file.

@dprevost-LMI
Copy link
Contributor Author

dprevost-LMI commented May 29, 2025

In addition to your request (done in 0708a6d), I had considered that a new "Security" section on the wdio website would be helpful.
Some idea I had for the page:

  1. Document the regular expression added from this PR for logs
  2. Document the { mask: true }, for user's password additional security
  3. Add the workaround of silencing the logger like below
/**
 * Set the logger level of the webdriver logger to 'error' before running a promise which is useful to hide sensitive information in the logs.
 */
export const withSilentLogger = async <T>(promise: () => Promise<T>): Promise<T> => {
  const webdriverLogLevel = driver.options.logLevel ?? 'error';

  try {
    logger.setLevel('webdriver', 'silent');
    return await promise();
  } finally {
    logger.setLevel('webdriver', webdriverLogLevel);
  }
};
  1. Point to the appium log filtering: https://appium.io/docs/en/2.0/guides/log-filters/
  2. Point to the BrowserStack masking: https://www.browserstack.com/docs/automate/selenium/hide-sensitive-data
  3. Maybe more...

What do you think?

@christian-bromann
Copy link
Member

What do you think?

Great idea! Let's do this.

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing stuff 🙌

@christian-bromann christian-bromann merged commit 2e07038 into webdriverio:main May 29, 2025
80 of 81 checks passed
@wdio-bot
Copy link
Contributor

Hey dprevost-LMI 👋

Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution.

We've sent you an email with further instructions on how to claim your expenses from our development fund.
Please make sure to check your spam folder as well. If you have any questions, feel free to reach out to us at [email protected] or in the contributing channel on Discord.

We are looking forward to more contributions from you in the future 🙌

Have a nice day,
The WebdriverIO Team 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[💡 Feature]: Proper masking for reporters, logging, and multiple emit events
4 participants