Skip to content

feat: Add configurable sensitive data masking with custom patterns #5109

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

Draft
wants to merge 2 commits into
base: 3.x
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 24, 2025

This PR adds comprehensive sensitive data masking capabilities to CodeceptJS, allowing users to define custom patterns to obfuscate sensitive information like emails, credit cards, phone numbers, and other data in all output including logs, steps, debug messages, and error messages.

Overview

CodeceptJS can now automatically mask sensitive data in all output using the enhanced maskSensitiveData configuration option. This builds upon the existing boolean configuration to support custom regex patterns with user-defined mask strings.

Configuration

Backward Compatible Boolean Configuration

// codecept.conf.js
exports.config = {
  maskSensitiveData: true, // Uses built-in patterns for common sensitive data
  // ... other config
}

Advanced Custom Patterns Configuration

// codecept.conf.js
exports.config = {
  maskSensitiveData: {
    enabled: true,
    patterns: [
      {
        name: 'Email',
        regex: /(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b)/gi,
        mask: '[MASKED_EMAIL]'
      },
      {
        name: 'Credit Card',
        regex: /\b(?:\d{4}[- ]?){3}\d{4}\b/g,
        mask: '[MASKED_CARD]'
      },
      {
        name: 'Phone Number',
        regex: /(\+?1[-.\s]?)?\(?([0-9]{3})\)?[-.\s]?([0-9]{3})[-.\s]?([0-9]{4})/g,
        mask: '[MASKED_PHONE]'
      }
    ]
  },
  // ... other config
}

Example Output

With the above configuration, sensitive data is automatically masked:

Before:

Given I have user email "john.doe@company.com"
And I have credit card "4111 1111 1111 1111" 
And I have phone number "+1-555-123-4567"

After:

Given I have user email "[MASKED_EMAIL]"
And I have credit card "[MASKED_CARD]"
And I have phone number "[MASKED_PHONE]"

Where Masking Applies

  • Step descriptions and output
  • Debug messages (--debug mode)
  • Log messages (--verbose mode)
  • Error messages
  • Success messages
  • BDD step output (works alongside existing secret() function)

Implementation Details

  • New masking utility (lib/utils/mask_data.js) handles both boolean and object configurations
  • Enhanced output system (lib/output.js) applies masking consistently across all output methods
  • Leverages existing invisi-data package which already supports custom patterns
  • 100% backward compatible with existing boolean configuration and secret() function
  • Comprehensive test coverage with 17 tests covering all scenarios

Testing

All existing functionality continues to work unchanged:

  • Existing secret() function still masks individual values
  • Boolean maskSensitiveData: true configuration works as before
  • All 443 existing tests pass
  • New comprehensive test suite validates custom pattern functionality

Fixes #5108.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • googlechromelabs.github.io
  • https://storage.googleapis.com/chrome-for-testing-public/138.0.7204.168/linux64/chrome-headless-shell-linux64.zip
    • Triggering command: node install.mjs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] feat: hidden sensitive data in logs, steps, etc. feat: Add configurable sensitive data masking with custom patterns Aug 24, 2025
@Copilot Copilot AI requested a review from kobenguyent August 24, 2025 11:51
Copilot finished work on behalf of kobenguyent August 24, 2025 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: hidden sensitive data in logs, steps, etc.
2 participants