Skip to content

Harden server parsing and shell command handling#1229

Merged
GT-610 merged 2 commits into
mainfrom
cleanup/0712
Jul 12, 2026
Merged

Harden server parsing and shell command handling#1229
GT-610 merged 2 commits into
mainfrom
cleanup/0712

Conversation

@GT-610

@GT-610 GT-610 commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Tighten parsing for connection, CPU, and network stats so malformed or truncated rows are skipped instead of crashing
  • Quote container IDs and image refs before sending shell commands to reduce injection risk
  • Capture stderr in persistent shell output while keeping completion marker parsing isolated to stdout
  • Add tests covering the new parsing and quoting behavior

Testing

  • Added unit tests for Conn.parse, SingleCpuCore.parse, NetSpeed, shellSingleQuote, and PersistentShell
  • Existing test coverage was extended to validate malformed input handling and command-quoting behavior

Summary by CodeRabbit

  • Bug Fixes
    • Improved parsing robustness for server TCP, CPU, and network speed data, including handling truncated or malformed rows and irregular whitespace.
    • Prevented incorrect network speed results when time delta is non-positive.
    • Adjusted persistent shell results to include stderr in the returned output without treating stderr markers as completion status.
  • Security
    • Added consistent shell-argument quoting for container/image and SSH-related commands.
  • Tests
    • Added/expanded unit tests covering parsing failures, malformed CPU rows, zero delta speed behavior, stderr handling, and shell argument escaping.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f4a80538-9daa-4a3e-93d9-ecda6b917bbb

📥 Commits

Reviewing files that changed from the base of the PR and between 4deee41 and fc406ca.

📒 Files selected for processing (4)
  • lib/data/model/server/conn.dart
  • lib/data/model/server/cpu.dart
  • test/conn_test.dart
  • test/cpu_test.dart

📝 Walkthrough

Walkthrough

Server metric parsing now handles truncated or malformed input, irregular whitespace, and non-positive network time deltas. Container lifecycle and UI commands quote shell arguments through a shared helper. Persistent shell execution buffers stderr separately, ignores stderr completion markers for exit status, and includes stderr in command output. Tests cover these parsing, quoting, timing, and shell-output behaviors.

Possibly related PRs

Suggested reviewers: lollipopkit

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: hardening parsing logic and shell command handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cleanup/0712

Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested a review from lollipopkit July 12, 2026 08:44

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/data/model/server/conn.dart`:
- Around line 23-26: Update the Conn parsing flow to parse the MaxConn and
AttemptFails tokens before constructing Conn, using the existing index symbols
_maxConnIndex and _attemptFailsIndex. Return null when either int parse fails,
and pass the validated parsed values to Conn instead of defaulting invalid
tokens to zero.

In `@lib/data/model/server/cpu.dart`:
- Around line 138-141: Update the CPU row parsing loop around the item trimming
and matches-length check so blank lines are skipped with continue rather than
terminating parsing. Preserve termination only for a non-CPU record when needed
to avoid consuming later /proc/stat sections, while continuing to parse
subsequent valid CPU rows.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 139ef35f-396a-482f-b2d2-19a8f055d9fc

📥 Commits

Reviewing files that changed from the base of the PR and between 0102c84 and 4deee41.

📒 Files selected for processing (11)
  • lib/data/model/server/conn.dart
  • lib/data/model/server/cpu.dart
  • lib/data/model/server/net_speed.dart
  • lib/data/provider/container.dart
  • lib/data/ssh/persistent_shell.dart
  • lib/view/page/container/actions.dart
  • test/conn_test.dart
  • test/container_test.dart
  • test/cpu_test.dart
  • test/net_speed_test.dart
  • test/persistent_shell_test.dart

Comment thread lib/data/model/server/conn.dart Outdated
Comment thread lib/data/model/server/cpu.dart
@GT-610
GT-610 merged commit 90e1cdc into main Jul 12, 2026
5 checks passed
@GT-610
GT-610 deleted the cleanup/0712 branch July 12, 2026 09:00
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.

1 participant