Skip to content

Harden verbose context logging against terminal control-character injection - #5

Closed
mkajander with Copilot wants to merge 2 commits into
mainfrom
copilot/check-security-issues
Closed

mkajander with Copilot wants to merge 2 commits into
mainfrom
copilot/check-security-issues

Conversation

Copilot AI commented Feb 16, 2026 •

Copy link
Copy Markdown

This PR addresses the security review request by tightening output handling in verbose logs. It removes a terminal-injection vector where untrusted context values (workspace/repo/source) could emit control characters to stderr.

  • Security hardening: verbose context output

    • Updated ResolvedContextReporter to sanitize workspace, repo, and source before writing diagnostic context lines.
    • Applies existing TerminalSanitizer at the log boundary so env/CLI/git-derived values cannot inject ANSI/control sequences.
  • Focused regression coverage

    • Added ResolvedContextReporterTests to assert control characters are stripped in both:
      • LogRepoContext(...)
      • LogWorkspaceContext(...)

Example of the applied pattern:

var workspace = TerminalSanitizer.Sanitize(context.Workspace) ?? string.Empty;
var repo = TerminalSanitizer.Sanitize(context.Repo) ?? string.Empty;
var source = TerminalSanitizer.Sanitize(
    string.IsNullOrWhiteSpace(context.Source) ? "unknown" : context.Source
) ?? "unknown";

Console.Error.WriteLine($"Context: workspace={workspace} repo={repo} source={source}");

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: mkajander <34684415+mkajander@users.noreply.github.com>
Copilot AI changed the title [WIP] Run code review for security issues Harden verbose context logging against terminal control-character injection Feb 16, 2026
Copilot AI requested a review from mkajander February 16, 2026 09:05
@mkajander mkajander closed this Feb 16, 2026
@mkajander
mkajander deleted the copilot/check-security-issues branch February 16, 2026 09:09
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