Skip to content

Conversation

@petebacondarwin
Copy link
Contributor

@petebacondarwin petebacondarwin commented Jan 26, 2026

Sanitize commands and arguments in telemetry to prevent accidentally capturing sensitive information.

Changes:

  • Renamed telemetry fields from command/args to sanitizedCommand/sanitizedArgs to distinguish from historical fields that may have contained sensitive data in older versions
  • Command names now come from command definitions rather than user input, preventing accidental capture of sensitive data pasted as positional arguments
  • Sentry breadcrumbs now use the safe command name from definitions
  • Argument values are only included if explicitly allowed via COMMAND_ARG_ALLOW_LIST
  • Argument keys (names) are always included since they come from command definitions, not user input
    Replaces fix(wrangler): add safe command/args handling for telemetry #12063, which added the redundant logArgs: false behaviour. See fix(wrangler): add safe command/args handling for telemetry #12063 (comment)

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal fix

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2026

🦋 Changeset detected

Latest commit: 34c0bfc

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Jan 26, 2026
@petebacondarwin petebacondarwin marked this pull request as ready for review January 26, 2026 17:26
@petebacondarwin petebacondarwin requested a review from a team as a code owner January 26, 2026 17:26
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 26, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12153

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12153

miniflare

npm i https://pkg.pr.new/miniflare@12153

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12153

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12153

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12153

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12153

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12153

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12153

wrangler

npm i https://pkg.pr.new/wrangler@12153

commit: 34c0bfc

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional flags.

Open in Devin Review

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Nice simplification!

I added a couple comments inline

@petebacondarwin
Copy link
Contributor Author

Rewritten the sanitizedArgs code to make it less scary and more clear where the sanitization should happen. PTAL @vicb

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View issue and 8 additional flags in Devin Review.

Open in Devin Review

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View issue and 9 additional flags in Devin Review.

Open in Devin Review

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

Some of my comments could probably be addressed in a follow up PR.
Could you please create/update an issue for the minor comments you decide not to address here?

argsWithSanitizedKeys,
allowedArgs
);
const argsUsed = Object.keys(argsWithSanitizedKeys).sort();
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not fan of "argsUsed" because I find this too generic.

What about "userSuppliedArgs" or something similar.

I would also be nice to figure out a place to document it, either in the JSDoc of sendCommandEvent or a newly introduce type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

argsUsed is the property sent in the metrics event.
I don't think this refactor is the right place to discuss that.
#12192

Copy link
Contributor

@vicb vicb Jan 27, 2026

Choose a reason for hiding this comment

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

Reopening...

argsUsed is the property sent in the metrics event.

It doesn't mean we can not use a clearer and meaningful name in the code, does it?

The only place where we "have to" use this name is when sending the payload

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be dealt with in the linked issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Reopening...

Sorry but isn't this newly introduced code?

I think it's fair to fix existing code later but I don't think introducing new "not great" code is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@vicb you concern at the start of this thread above is merely a naming/documentation one, which is itself entirely subjective.

The previous code looked like this:

const sanitizedArgs = sanitizeArgKeys(
  properties.args ?? {},
  options.argv
);
const sanitizedArgsKeys = Object.keys(sanitizedArgs).sort();

const commonEventProperties: CommonEventProperties = {
  ...
  argsUsed: sanitizedArgsKeys,
  argsCombination: sanitizedArgsKeys.join(", "),
  ...
};

So you can see that all that has effectively happened is that sanitizedArgsKeys variable is now argsUsed.

This PR is therefore not new code, and is not reducing the quality of the code in any tangible meaningful way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can discuss further on the linked issue, if you feel strongly about the naming of this variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Your call here.
My point is that it is a shame to introduce code and create an issue to change it at the same time - knowing that the update would take approximately 30s.

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Jan 27, 2026
- Renames telemetry event fields so that we can distinguish them in the metric reporting tools:
  - 'command' -> 'safeCommand' (without 'wrangler ' prefix and containing no positional args at all)
  - 'args' -> 'safeArgs' (only including allowed args, with sanitized values)
- Moves Sentry breadcrumbs for command start/error into the metrics dispatcher to ensure they don't include positional args.
Moved the sanitization to the command handling machinery rather than the metrics dispatcher.
This makes it clear that the values passed to be dispatched must have already been sanitized.
@petebacondarwin petebacondarwin force-pushed the pbd/wrangler/sanitized-metrics branch from 5e7c1f5 to 34c0bfc Compare January 27, 2026 20:59
@petebacondarwin petebacondarwin merged commit cb72c11 into main Jan 27, 2026
41 checks passed
@petebacondarwin petebacondarwin deleted the pbd/wrangler/sanitized-metrics branch January 27, 2026 21:39
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants