Skip to content

fix(mcp): skip empty secret values in redactText#39923

Closed
derodero24 wants to merge 1 commit intomicrosoft:mainfrom
derodero24:fix-1474
Closed

fix(mcp): skip empty secret values in redactText#39923
derodero24 wants to merge 1 commit intomicrosoft:mainfrom
derodero24:fix-1474

Conversation

@derodero24
Copy link
Copy Markdown

Summary

Fixes microsoft/playwright-mcp#1474

Empty-string secret values parsed from .env files (e.g. KEY=#{VAR}# where dotenv strips comments) cause String.replaceAll("", ...) to insert the replacement tag between every character. This grows the string exponentially across multiple empty secrets, crashing V8 with a RangeError.

  • Skip empty secretValue in _redactSecrets() before calling replaceAll
  • Filter out empty values in dotenvFileLoader() at parse time

Fixes microsoft/playwright-mcp#1474

When a secrets .env file contains empty-string values (e.g. from
dotenv parsing comments like `KEY=#{VAR}#`), `replaceAll("", ...)`
inserts the replacement between every character, causing exponential
string growth and a V8 RangeError.

Guard against empty values in both `_redactSecrets` and
`dotenvFileLoader` to prevent the crash.

Fixes microsoft/playwright-mcp#1474
@derodero24
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

for (const [secretName, secretValue] of Object.entries(this._context.config.secrets ?? {}))
text = text.replaceAll(secretValue, `<secret>${secretName}</secret>`);
for (const [secretName, secretValue] of Object.entries(this._context.config.secrets ?? {})) {
if (secretValue)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I had to double-check JS truthiness rules to see if this works for "false" or "0", e.g. CI=false. Not the usual secret value, but usual contents of .env. The behaviour is correct, but I expect other readers to stumble over this too. Let's make it easier to reason about:

Suggested change
if (secretValue)
if (secretValue !== "")
Suggested change
if (secretValue)
if (secretValue.length)

return undefined;
return dotenv.parse(fs.readFileSync(value, 'utf8'));
const parsed = dotenv.parse(fs.readFileSync(value, 'utf8'));
return Object.fromEntries(Object.entries(parsed).filter(([, v]) => v));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wouldn't a fix in one of the two locations be enough? Why do we need both?

@pavelfeldman
Copy link
Copy Markdown
Member

pavelfeldman commented Apr 3, 2026

That issue was closed

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.

[Bug] RangeError: Invalid string length on Blazor WASM pages - snapshot serialization crashes

3 participants