Skip to content

feat: redact username in logging - #45

Open
yCodeTech wants to merge 6 commits into
refactor/logging-environment-variablesfrom
feat/redact-username-in-logging
Open

feat: redact username in logging#45
yCodeTech wants to merge 6 commits into
refactor/logging-environment-variablesfrom
feat/redact-username-in-logging

Conversation

@yCodeTech

Copy link
Copy Markdown
Owner

This pull request introduces a new utility function to redact the current OS username from log output and applies it where necessary to prevent leaking personally identifiable information (usernames) in logs. The main changes involve adding the redactUsername function and updating logging statements and data accessors to use it, especially when logging paths or configuration data that may contain the username.

Sensitive Data Redaction:

  • Added a recursive redactUsername function in src/utils.ts to sanitize strings, arrays, objects, and Maps by replacing occurrences of the current OS username with "<redacted>".
  • Updated logging in src/configuration.ts to redact the username from environment variables and language config file paths before outputting them.
  • Updated ExtensionData in src/extensionData.ts to redact the username from the extensionPath property and all extension discovery paths when accessed for logging.
  • Updated imports in src/extensionData.ts to include the new redactUsername utility.

Utility Improvements:

  • Added the os module import in src/utils.ts to support cross-platform username detection.

…paths.

The `getAllExtensionDiscoveryPaths` method signature has always been typed as returning a readonly Map, but that's just for compile-time. For run-time it was still returning the actual Map which could be mutated externally.

- Fixed `getAllExtensionDiscoveryPaths` ExtensionData method to return a new Map of the `extensionDiscoveryPaths` Map, to prevent external mutation of the paths.
- Implemented `redactUsername` utility function to sanitise logs by removing the OS username.

- Updated logging statements to use the new redaction utility in:
    - `logDebugInfo` method in `Configuration` class.
    - `getAllExtensionDiscoveryPaths` and `prepareForLogging` methods in `ExtensionData` class.
Copilot AI lite review requested due to automatic review settings August 4, 2026 23:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a reusable redaction utility to prevent leaking the current OS username in log output, and applies it to a few high-signal logging/data-access paths in the extension.

Changes:

  • Added redactUsername in src/utils.ts to recursively redact usernames in strings across nested data structures.
  • Updated Configuration.logDebugInfo() logging to redact usernames from environment data and language config file paths.
  • Updated ExtensionData to redact usernames in extensionPath and extension discovery paths when used for logging.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/utils.ts Introduces redactUsername utility used for recursive username redaction in log-bound data.
src/configuration.ts Applies username redaction to debug logging of environment/config path-related data.
src/extensionData.ts Redacts username from extension path and discovery paths exposed for logging.

Comment thread src/utils.ts Outdated
Comment thread src/extensionData.ts
Comment thread src/utils.ts Outdated
- Moved `redactUsername` function from utils into Logger, simplifying the new method, and adding it's call into the `formatMeta` method after it's transformed the data into a string.

By implementing the `redactUsername` method directly into Logger, we can ensure that any calls to logger with additional meta data, will have the username automatically redacted. So even if more logs are added in future, we don't forget to redact the usernames before Logger gets it.

This also fixes various copilot review comments on the previous implementation because its no longer recursing into objects or arrays, it's just replacing directly on the string immediately before logging to output.

- Updated logging statements to remove the old redaction utility in:
    - `logDebugInfo` method in `Configuration` class.
    - `getAllExtensionDiscoveryPaths` and `prepareForLogging` methods in `ExtensionData` class.
- Introduced new `warn` log level.

    - Added `warn` enum option to the `logLevel` user setting and adjusted all the options descriptions.

    - Implemented `warn` method in `Logger` class to handle warning messages.

    - Updated `logLevels` in the `utils` interface to include `warn`.

    - Added `warn` level in `shouldLog` method in `Logger` and adjusted all the weights.

- Added new `hasWarnedAboutRedactionFailure` property to determine whether the user has already been warned about a redaction failure.

- Added new `warnOnRedactionFailure` method in Logger to warn users when the username couldn't be determined and redaction failed. This method uses the new `hasWarnedAboutRedactionFailure` property to check if it's already been outputted, as this is a once per session warning. It also uses the new `warn` logger method.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (3)

src/logger.ts:233

  • Username redaction is currently only applied to the formatted meta output (via formatMeta()), not to the main message string appended in logMessage(). This still allows usernames to leak when call sites interpolate paths directly into the message (e.g., logger.info(Loaded DEV_USER_EXTENSIONS_PATH: "${devPath}") in src/utils.ts). Consider redacting the message before appending it to the output channel (and ideally also for important() logs) so redaction is consistently applied.
			data = lines.join(",\n");
		}

		return this.redactUsername(data);
	}

src/logger.ts:299

  • The warning text says "debug logs may not be redacted", but username redaction is applied to any log meta that goes through formatMeta() (including info/warn/error). The message should be accurate so users understand the scope of the redaction failure.
		this.warn("Could not determine OS username; debug logs may not be redacted before sharing.");

src/logger.ts:261

  • PR description says a recursive redactUsername utility was added to src/utils.ts and applied across configuration/extension data accessors, but the implementation shown here adds redaction inside Logger instead. Please update the PR description (or align the implementation) so it accurately reflects where redaction lives and how it’s applied.
	/**
	 * Redact the OS username from a string, replacing it with `<redacted>`, to avoid leaking
	 * it into debug logs that could be shared.
	 *
	 * @param {string} text The text to redact.

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.

2 participants