Skip to content

fix(cli): docker and sandbox output render remote text as rich markup #955

Closed

Description

@dan-petty

Problem

The devsecops review session 20261001-224227 (2026-10-02, a path review of the whole repository with local models) raised 563 findings. A triage of every finding against release/v0.2.25 (c279c18) judged 489 false. Each of the 2 defects below was confirmed with code evidence and then upheld by a second agent that tried to refute it. The severities are re-rated; the review's own ratings were inflated.

Insecure Regex Substitution in Docker Push Command (src/devops_cli/commands/docker.py:164, LOW, security)

  • Defect: The control-character strip works, but status text from the registry is then passed to print_info(clean_status, prefix=False) and print_error(clean_err, prefix=False) (lines 165 and 168), and the build stream lines (line 132) go through the same path, all without safe=True. console.py prints that text unescaped (formatted_message = escape_text(raw_message) if safe else raw_message), so Rich markup in remote content is interpreted. Checked with the repo's Rich: a status of denied: [/v2/repo] access raises MarkupError: closing tag '[/v2/repo]' ... doesn't match any open tag, so docker push crashes with a traceback instead of a clean Exit(1). [link=http://x]Pushed[/link] renders an attacker-chosen hyperlink, and [internal] text silently vanishes. The project already has print_safe for untrusted content, and a similar MarkupError was fixed in the TUI …
  • Skeptic's ruling: Upheld at LOW, re-scoped. The control-character strip in push and build works, and stripping shell metacharacters (the finding's fix) does nothing useful because nothing here reaches a shell. The real defect: registry push status/error text and build stream lines go to print_info(..., prefix=False) and print_error(..., prefix=False) without safe=True. In output/console.py, formatted_message = escape_text(raw_message) if safe else raw_message, and the result goes to Console.print …
  • Fix: Keep the control-character strip, and pass safe=True to print_info for build stream lines and push status, and to print_error for the push error. print_safe is the alternative; the project already uses it for untrusted content.
  • Regression test: In tests/test_docker.py, with the existing docker_engine fixture, set mock_client.images.push.return_value = [{"error": "denied: [/v2/repo] access"}] and invoke push registry/app:1. Assert exit_code == 1, isinstance(result.exception, SystemExit) and that '[/v2/repo]' appears literally in the output. Today result.exception is a rich.errors.MarkupError. Add a build case where images.build returns (img, [{"stream": "Step [/x] done\n"}]) and assert exit 0 with the literal text in …

Potential SSRF Vulnerability in Prometheus Scraping (src/devops_cli/commands/sandbox.py:535, LOW, security)

  • Defect: Metric names are already restricted by _METRIC_LINE_REGEX [a-zA-Z_:][a-zA-Z0-9_:]* (metrics.py:29-31), so the proposed name check does nothing. The claim that scraped content is unsafe in later rendering is correct for label values and TYPE text. _LABEL_REGEX accepts arbitrary values, and _record_type (metrics.py:328-332) stores free text from # TYPE lines. _render_prom_table (commands/sandbox.py:534-538) builds lbl_str = ", ".join(f"{k}={v}" ...) and m.metric_type.upper(), then calls print_table, which goes to render_table with safe=False (output/formatters/tables.py:62,103), so Rich parses the cells as markup. The scraped endpoint is remote content: the sandboxed workload's port, or a user-given URL. Reproduced against c279c18: up{job="[/]"} 1 (or # TYPE up [/]) makes the table render raise MarkupError "closing tag '[/]' at position 0 has nothing to close", which aborts …
  • Skeptic's ruling: I could not refute this. The original title (SSRF) and its fix (a metric-name regex) are wrong: METRIC_LINE_REGEX already limits names to [a-zA-Z:][a-zA-Z0-9_:]*, and _validate_scrape_url / validate_url_egress handle SSRF. The triage's narrower claim holds in the current code. _LABEL_REGEX accepts any label value, and _record_type (sandbox/metrics.py) stores the free text after '# TYPE ' as metric_type. _render_prom_table (commands/sandbox.py) joins those values into raw strings and …
  • Fix: 1. In _render_prom_table, escape every value that comes from the scrape: escape_text(m.name), escape_text(m.metric_type.upper()), and escape_text on the label string. Truncate the label string to 40 characters before escaping, so the cut cannot land inside an escape sequence. Alternatively, give print_table a safe: bool = False parameter that it passes to print(..., safe=safe), and have _render_prom_table call it with safe=True. That would also let other callers that show remote data (the trace waterfall, probe tables) opt in.
  1. In _record_type, keep a TYPE only when parts[2] matches the metric-name regex and parts[3].lower() is one of {counter, gauge, histogram, summary, untyped}. Otherwise ignore the line, so the type falls back to _infer_metric_type.
  2. Optionally, have print_warning(..., safe=True) handle snapshot.scrape_error, which can carry text from exceptions.
  • Regression test: tests/unit/commands/test_sandbox_metrics_render.py:
    (a) Build snapshot metrics with parse_prometheus_exposition('# TYPE up [/]\nup{job="[/]",x="[bold red]FAKE[/]"} 1'). Call _render_prom_table('t', metrics) with the module console patched to a Rich Console(record=True, width=200). Assert that no MarkupError is raised and that console.export_text() contains the literal strings 'job=[/]' and '[bold red]FAKE'. Today this raises MarkupError.
    (b) A unit test that parse_prometheus_exposition('# TYPE …

Acceptance criteria

  • Each defect above is fixed as its Fix line describes, or the PR says why another fix is better.
  • Each has its Regression test: offline, failing on the base revision and passing after the fix.
  • Removed code goes without shims (pre-1.0), and docs that described it are corrected.
  • uv run devops ci passes.

Key questions

  • One PR for all of these? Yes (proposed). They share a module area and none needs a design decision; each fix is small.

Activity

  1. added this to the v0.2.25 milestone on Oct 2, 2026
  2. added
    type/bug
    scope/cli
    priority/p3-low
    on Oct 2, 2026
  3. dan-petty commented on Oct 3, 2026

    @dan-petty
    OwnerAuthor

    Closed by #1073, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  4. added a commit that references this issue on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/clitype/bug

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions