Skip to content

feat: redact username in logging paths - #45

Merged
yCodeTech merged 10 commits into
refactor/logging-environment-variablesfrom
feat/redact-username-in-logging
Aug 6, 2026
Merged

feat: redact username in logging paths#45
yCodeTech merged 10 commits into
refactor/logging-environment-variablesfrom
feat/redact-username-in-logging

Conversation

@yCodeTech

@yCodeTech yCodeTech commented Aug 4, 2026

Copy link
Copy Markdown
Owner

This pull request introduces a new warning log level and improves logging safety by redacting OS usernames in paths from log output. It also refines the handling of extension discovery paths and updates log level descriptions for clarity.

Logging improvements:

  • Added a new warn log level, including support in the logger, log level comparisons, and the logLevels utils constant.
  • Implemented automatic redaction of the current OS username from all log messages and data to prevent accidental leaking of sensitive information. If the username cannot be determined, a warning is logged once per session while avoiding infinite recursion, and further redaction attempts are skipped.

Configuration and API updates:

  • Updated log level descriptions in package.json to reflect the new warn level and clarify which messages are included at each level.
  • The getAllExtensionDiscoveryPaths method now returns a new Map to prevent external mutation of internal state.

Other changes:

  • Minor code formatting and comments for clarity in configuration and extension data classes.

…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.

- Added the `redactUsername` method call in the `logMessage` method to redact usernames from the log messages, as they could have them too.

- Moved the method call to redact the meta data from `formatMeta` method into the `logMessage` method, so that the log message and data are both redacted from the same centralised method.
- Added a `hasWarnedAboutRedactionFailure` guard conditional at the top of the `redactUsername` method to skip redaction if a previous redact attempt failed.
- Changed the `hasWarnedAboutRedactionFailure` property flag to `skipRedaction` to better describe it's actual job of skipping redaction attempts after failure.

- Changed references to the old `hasWarnedAboutRedactionFailure` property to use the new `skipRedaction` property in the `redactUsername` and `warnOnRedactionFailure` methods.

- Removed the old `hasWarnedAboutRedactionFailure` guard conditional from the `warnOnRedactionFailure` method.

This is because the method will only run when the new `skipRedaction` flag is false thanks to the guard at the top of `redactUsername` method. So the extra guard is now redundant.

- Revised docblocks and code comments for clarity on the redaction behaviour.
@yCodeTech yCodeTech changed the title feat: redact username in logging feat: redact username in logging paths Aug 6, 2026
@yCodeTech yCodeTech added the enhancement New feature or quality of life enhancement label Aug 6, 2026
@yCodeTech
yCodeTech merged commit 5ec5c07 into master Aug 6, 2026
1 check passed
@yCodeTech
yCodeTech deleted the feat/redact-username-in-logging branch August 6, 2026 01:16
github-actions Bot added a commit that referenced this pull request Aug 7, 2026
@github-actions github-actions Bot mentioned this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or quality of life enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants