Skip to content

Hardening dashboard client - #622

Merged
urfeex merged 18 commits into
UniversalRobots:masterfrom
urfeex:hardening_dashboard_client
Nov 16, 2026
Merged

urfeex merged 18 commits into
UniversalRobots:masterfrom
urfeex:hardening_dashboard_client

Conversation

@urfeex

@urfeex urfeex commented Nov 13, 2026

Copy link
Copy Markdown
Member

This PR adds hardening of the dasboard client (Mainly the x-implementation) to avoid escapes from string replacements.

This affects

  • generating JSON structures based on user input
  • generating request URLS including user input
  • validating program names
  • validating downloaded artifacts such as programs
  • validating version strings before creating objects from them

Use structured json instead of on-the-fly construction of a JSON string
to avoid json member injection.

This also moves all non-URSim tests for the RobotAPI in a standalone
test file.
This prevents errors and vulnerabilities resulting from a dashboard server responding
with an illegal version string. An unexpected response could potentially
crash the client. With this fix applied, it throws a UrException instead
making this able to resolve. E.g. during G5 client startup we query the version.
If that throws now, connect() returns false instead of the application crashing.
This change does

- make sure the given program name doesn't lead to path traversal on the URL
- verify that the received response does contain something that looks like a program
- make sure the file is written atomically through a tempfile to avoid following pre-placed symlinks
@urfeex
urfeex requested a review from a team November 13, 2026 08:49
@urfeex urfeex added the bugfix label Nov 13, 2026
Copilot AI balanced review requested due to automatic review settings November 13, 2026 08:49
@urfeex urfeex added this to the 2.18.0 milestone Nov 13, 2026
@cursor

cursor Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes authentication-adjacent connect flows, URL/JSON construction from user input, and file download semantics—incorrect validation could break integrations or leave residual security gaps.

Overview
Hardens the dashboard client against malformed robot responses and unsafe use of caller-supplied program names, with the largest behavioral changes in the PolyScope X (DashboardClientImplX) path.

Connection and version handling: connect() on G5 and X now treats bad version discovery (empty/malformed PolyScope replies or invalid Robot API JSON/version strings) as a failed connection (false) instead of leaking non-library exceptions. G5 uses shared token extraction before VersionInformation::fromString(). Version parsing is stricter (2–4 digit-only uint32 components, mixed ./- separators) and is aligned with script reader version literals.

PolyScope X request safety: Robot API JSON goes through a wrapper that maps parse failures to UrException. Load program bodies are built with nlohmann::json instead of string concatenation. Download program rejects path traversal (including multi-pass percent decoding), verifies the payload is a program export with a matching name, and persists via new writeFileAtomically() (exclusive temp file + rename). Docs note unauthenticated dashboard TCP exposure.

Tests: G5 welcome/version connect tests, expanded version/helper coverage, connect-timeout slack, and mock Robot API tests moved into always-built dashboard_client_x_unit_tests.

Reviewed by Cursor Bugbot for commit 0dc1c43. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.85650% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.07%. Comparing base (3ead504) to head (0dc1c43).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/ur/dashboard_client_implementation_x.cpp 80.13% 7 Missing and 22 partials ⚠️
src/ur/dashboard_client_implementation_g5.cpp 84.00% 2 Missing and 2 partials ⚠️
src/helpers.cpp 89.28% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #622      +/-   ##
==========================================
- Coverage   84.08%   84.07%   -0.01%     
==========================================
  Files         127      127              
  Lines        8425     8561     +136     
  Branches     3829     3913      +84     
==========================================
+ Hits         7084     7198     +114     
- Misses        937      949      +12     
- Partials      404      414      +10     
Flag Coverage Δ
python_scripts 49.69% <ø> (ø)
start_ursim 93.16% <ø> (-1.03%) ⬇️
unit 64.09% <72.52%> (+2.44%) ⬆️
ur20-latest 81.45% <73.09%> (+0.29%) ⬆️
ur5-3.14.3 81.17% <73.09%> (+0.25%) ⬆️
ur5e-10.11.0 77.12% <72.64%> (+0.46%) ⬆️
ur5e-10.12.0 77.95% <80.71%> (+0.29%) ⬆️
ur5e-10.7.0 76.62% <72.64%> (+0.45%) ⬆️
ur5e-5.9.4 81.41% <73.09%> (+0.24%) ⬆️
ur7e-10.13.0 78.40% <80.71%> (+0.14%) ⬆️
ur7e-10.14.0 78.64% <82.95%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@mergify

mergify Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

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.

🟡 Changes recommended

Downloads can silently overwrite the destination with an unverified or wrong program because missing export identities are accepted and percent-decoding alters the requested program name.

2 open issues
What changed in this PR

This PR hardens the library’s dashboard clients, primarily PolyScope X, against unsafe input handling and malformed robot responses.

Changes:

  • Uses JSON serialization, validates program download names and payloads, and adds atomic file writes.
  • Enforces strict version parsing and handles malformed replies during connection setup.
  • Expands regression coverage and moves robot-free PolyScope X tests into a dedicated target.
File Description
tests/​test_version_information.cpp Tests malformed versions and numeric boundaries.
tests/​test_helpers.cpp Tests atomic writes, cleanup, and filesystem failures.
tests/​test_dashboard_client.cpp Adds G5 version parsing and connection tests.
tests/​test_dashboard_client_x.cpp Moves mock tests out of the integration suite.
tests/​test_dashboard_client_x_unit.cpp Adds dedicated mock-based tests and hardening coverage.
tests/​CMakeLists.txt Registers unit tests and connection-test timeouts.
src/​ur/​version_information.cpp Validates version syntax and component ranges.
src/​ur/​dashboard_client_implementation_x.cpp Hardens JSON handling and program downloads.
src/​ur/​dashboard_client_implementation_g5.cpp Handles malformed version replies during connection.
src/​helpers.cpp Implements atomic file replacement.
include/​ur_client_library/​ur/​version_information.h Documents accepted version formats and exceptions.
include/​ur_client_library/​ur/​dashboard_client.h Documents connection failures and download-name restrictions.
include/​ur_client_library/​ur/​dashboard_client_implementation.h Documents shared connection and download contracts.
include/​ur_client_library/​ur/​dashboard_client_implementation_x.h Documents malformed Robot API connection replies.
include/​ur_client_library/​ur/​dashboard_client_implementation_g5.h Documents malformed dashboard connection replies.
include/​ur_client_library/​helpers.h Declares and documents the atomic-write helper.
doc/​architecture/​dashboard_client.rst Explains connection failures and network-exposure precautions.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 13, 2026 09:11

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.

🔵 Needs a closer look

JSON serialization failures bypass the expected UrException contract, while temporary-file handling rejects valid long filenames and can replace destinations despite close errors.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

Medium severity Use a short temporary basename for saved files

src/​helpers.cpp:318

Appending seven characters to the complete destination basename rejects otherwise valid save paths near the filesystem's filename limit. On a filesystem with a 255-byte limit, a 255-byte destination can be created normally, but this temporary filename fails with ENAMETOOLONG, so program downloads that previously worked now fail. Use a short, fixed-length temporary basename in the destination directory instead.

Medium severity Handle close failures before replacing the destination

src/​helpers.cpp:335

Please check the close result before renaming the temporary file. Filesystems such as NFS can report delayed I/O, quota, or space errors from close() even after write() returned the full byte count. Currently those failures still replace the existing destination and return success. Treat a failed close as a write failure and clean up the temporary file; check _close() in the Windows branch too.

Medium severity Translate serialization errors to UrException

src/​ur/​dashboard_client_implementation_x.cpp:475

dump() uses strict UTF-8 validation, so a caller-supplied name containing an invalid byte (for example, std::string(1, '\xff')) now throws nlohmann::json::type_error before sending the request. This exception passes through both public load-program wrappers unchanged and bypasses callers that handle UrException. Translate serialization failures into UrException, as the new response parser does, and cover malformed UTF-8 in the serialization tests.

2 resolved since last review

Review effort: Balanced

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@urfeex
urfeex force-pushed the hardening_dashboard_client branch from 5f38568 to 3383eb9 Compare November 13, 2026 11:21
Copilot AI balanced review requested due to automatic review settings November 13, 2026 11:21

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

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.

🟡 Changes recommended

The atomic-write helper can silently replace an existing destination with an empty file for 4 GiB inputs on 64-bit Windows and incorrectly report success.

6 open issues

Review effort: Balanced

Comment thread src/helpers.cpp Resolved
Comment thread src/helpers.cpp Resolved
Comment thread src/helpers.cpp Resolved
Comment thread tests/test_dashboard_client.cpp Resolved
Comment thread tests/test_helpers.cpp Resolved
@urfeex
urfeex force-pushed the hardening_dashboard_client branch from 3383eb9 to c64d422 Compare November 13, 2026 11:35
Copilot AI balanced review requested due to automatic review settings November 13, 2026 11:35

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.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/helpers.cpp Resolved
Wait APIs (select/poll/WSAPoll) may return slightly before the requested
timeout.

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.

🔵 Needs a closer look

Human assessment is needed because unpublished findings identify a critical script-parsing regression and failures when handling large POSIX writes.

1 open issue
1 resolved since last review

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 13, 2026 14:13

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/helpers.cpp Resolved

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.

🔵 Needs a closer look

Human assessment is needed to evaluate a version-parsing edge case that silently accepts malformed replies, allowing connection and version commands to report success.

1 open issue

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 16, 2026 07:21

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

Comment thread src/helpers.cpp Resolved

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.

🟡 Changes recommended

Write or close failures can return an empty error message when temporary-file cleanup succeeds, also causing the message assertion in writeFileAtomicallyWriteError to fail.

2 open issues

Review effort: Balanced

Comment thread src/helpers.cpp Resolved
@urfeex
urfeex force-pushed the hardening_dashboard_client branch from 62bb36f to d47bec8 Compare November 16, 2026 07:27
Copilot AI balanced review requested due to automatic review settings November 16, 2026 07:27

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.

🟡 Changes recommended

The stricter parser rejects build-suffix literals still passed by ScriptReader, aborting script generation; the caller needs normalization and a regression test.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread src/ur/version_information.cpp Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit d47bec8. Configure here.

Comment thread doc/architecture/dashboard_client.rst Resolved
Allows parsing version strings such as "5.12.0-123"
Copilot AI balanced review requested due to automatic review settings November 16, 2026 08:04

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.

🟡 Changes recommended

Version parsing normalizes every hyphen without validating placement, allowing both dashboard connection paths to accept malformed replies such as 5-12-0 and 5.12-0.123.

2 open issues
1 resolved since last review

Review effort: Balanced

Comment thread src/ur/version_information.cpp Resolved
Copilot AI balanced review requested due to automatic review settings November 16, 2026 08:47

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.

🔵 Needs a closer look

Human assessment is needed because a critical version-ordering inconsistency can make both comparison directions return true and select the wrong script branch.

2 open issues

Review effort: Balanced

@urfeex
urfeex requested a review from urrsk November 16, 2026 09:05
@urfeex
urfeex merged commit 5ec6678 into UniversalRobots:master Nov 16, 2026
57 of 67 checks passed
@urfeex
urfeex deleted the hardening_dashboard_client branch November 16, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants