Skip to content

Mask and sanitize debugger welcome message before DAP console output - #4577

Merged
rentziass merged 3 commits into
mainfrom
rentziass-sanitize-debugger-welcome-message
Jul 28, 2026
Merged

Mask and sanitize debugger welcome message before DAP console output#4577
rentziass merged 3 commits into
mainfrom
rentziass-sanitize-debugger-welcome-message

Conversation

@rentziass

@rentziass rentziass commented Jul 28, 2026

Copy link
Copy Markdown
Member

DapDebugger.SendWelcomeMessage wrote the server-supplied DebuggerWelcomeMessage straight to the DAP console with no secret masking and no control-character handling. The field is service-populated today and not tenant-reachable, but nothing in the runner enforced that, so a value containing a secret or an ANSI escape sequence would have reached the debug console verbatim.

Approach

The custom welcome message now goes through the same treatment as every other user-visible string in the debugger:

  • MaskUserVisibleText (the existing SecretMasker wrapper already used for step names, source content, and eval results).
  • A new SanitizeConsoleText helper that strips C0/C1 control characters while preserving \t, \r, and \n so multi-line messages still render.

Note that stripping the ESC byte leaves the remaining literal text of an escape sequence behind, e.g. \u001b[31m becomes [31m. That is intentional: the goal is to neutralize terminal control, not to guess at and delete surrounding printable text.

The default help text path is unchanged, since that string is compiled into the runner.

Tests

  • WelcomeMessageMasksSecrets and WelcomeMessageStripsControlCharacters drive a real DAP session end to end and assert on the emitted output event.
  • A theory over SanitizeConsoleText covering null, empty, plain text, preserved whitespace, ESC, BEL/NUL/DEL, and C1 characters.

46/46 DapDebuggerL0 tests pass. The full suite passes apart from the pre-existing ProcessExtensionL0.SuccessReadProcessEnv failure, which needs _layout/externals/node20 present locally and is unrelated to this change.

Notes for reviewers

  • No new feature flag. The actions_runner_override_debugger_welcome_message flag already gates this entire code path, and adding a switch to turn masking back off would defeat the purpose.
  • ./dev.sh format is currently broken on macOS in my environment (dotnet-format cannot locate its net472 build host), so formatting was matched by hand against surrounding code.

rentziass and others added 2 commits July 28, 2026 12:12
The server-supplied DebuggerWelcomeMessage was written straight to the DAP
console with no secret masking and no control-character stripping. Route it
through the runner's SecretMasker and strip C0/C1 control characters (keeping
tab, CR and LF) so it can't leak secrets or inject terminal escape sequences.

Also document that the field is service-populated only, and that the runner
treats it as untrusted regardless.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1d5fcea8-f377-47aa-9013-98d64b2655a8
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1d5fcea8-f377-47aa-9013-98d64b2655a8
Copilot AI review requested due to automatic review settings July 28, 2026 10:45
@rentziass
rentziass requested a review from a team as a code owner July 28, 2026 10:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 hardens the DAP debugger welcome message path by ensuring server-supplied welcome text is treated as untrusted before being written to the DAP console, addressing secret leakage and terminal control-character injection concerns.

Changes:

  • Masks custom debugger welcome messages with the runner SecretMasker prior to console output.
  • Adds SanitizeConsoleText to strip C0/C1 control characters (preserving \t, \r, \n) and applies it to the welcome message.
  • Adds L0 tests covering secret masking and control-character stripping behavior.
Show a summary per file
File Description
src/Runner.Worker/Dap/DapDebugger.cs Applies masking/sanitization to the custom welcome message and adds SanitizeConsoleText.
src/Test/L0/Worker/DapDebuggerL0.cs Adds end-to-end and unit tests validating masking and sanitization behavior.
src/Runner.Worker/Dap/DebuggerConfig.cs Documents that the welcome message is treated as untrusted and sanitized/masked before console output.
src/Sdk/DTPipelines/Pipelines/AgentJobRequestMessage.cs Updates doc comment to remove “shown as-is” wording now that the runner sanitizes/masks.

Review details

  • Files reviewed: 4/4 changed files
  • Comments generated: 2
  • Review effort level: Low

Comment thread src/Runner.Worker/Dap/DapDebugger.cs
Comment thread src/Test/L0/Worker/DapDebuggerL0.cs
@rentziass
rentziass enabled auto-merge (squash) July 28, 2026 11:26
@rentziass
rentziass merged commit e1d1844 into main Jul 28, 2026
12 checks passed
@rentziass
rentziass deleted the rentziass-sanitize-debugger-welcome-message branch July 28, 2026 11:32
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.

3 participants