Skip to content

fix(security): resolve SonarQube critical/high/blocker security findings#1608

Open
ramakrishnap-nv wants to merge 7 commits into
mainfrom
fix/sonarqube-security-webserver
Open

fix(security): resolve SonarQube critical/high/blocker security findings#1608
ramakrishnap-nv wants to merge 7 commits into
mainfrom
fix/sonarqube-security-webserver

Conversation

@ramakrishnap-nv

@ramakrishnap-nv ramakrishnap-nv commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Resolves SonarQube critical, high, and blocker security findings across the server, C++ solver, and CI utilities.

Python server (CWE-22, CWE-20):

  • NVCF endpoint: validate asset ID stays within nvcf-asset-dir via realpath+commonpath; require absolute path for nvcf-large-output-dir
  • get_output_name: replace blocklist with realpath+commonpath containment check
  • Log endpoints: validate id is a well-formed UUID before constructing file paths
  • getsolverlogs: reject negative frombyte with HTTP 422

C++ / CI (genuine bugs):

  • fast_parser.cpp: wrap scoped_timer_t destructor body in try-catch (S1048)
  • fast_fp64_parser.hpp, phase2.cpp, c_api_test.c: replace v==v/x!=x NaN idiom with std::isnan()/isnan() (S1764)
  • pcgenerator.hpp: replace unary minus on unsigned (-rot) with (32u-rot)&31u (S876)
  • aggregate_nightly.py: canonicalize output_dir with Path.resolve() before use (S2083)

False positives suppressed with // NOSONAR:

  • fast_parser.cpp: find_line_start return stays within bounds (S3519)
  • lz4_file_reader.cpp: window_count initialized before dependent fields per C++ declaration order (S836)
  • file_to_string.cpp (14 sites): mps_parser_expects throws before any null dereference (S2259)

Three SonarQube findings in webserver.py (CWE-22 path traversal, CWE-20
improper input validation):

1. get_output_name: replace blocklist check (startswith("/") or ".." in)
   with os.path.realpath + os.path.commonpath containment check against
   resultdir, matching the guard already used in validate_file_path().

2. getsolverlogs / deletesolverlogs: validate that the `id` path parameter
   is a well-formed UUID before constructing "log_<id>" file path, closing
   the taint path from HTTP input to os.path.join / open / os.unlink.

3. getsolverlogs: reject negative frombyte values before passing to
   out.seek() instead of relying on OSError from the OS.

Signed-off-by: Ramakrishna Prabhu <ramakrishnap@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

The /cuopt/cuopt managed-service endpoint accepted nvcf-asset-dir,
nvcf-function-asset-ids, and nvcf-large-output-dir as HTTP headers and
used them in file operations without sanitization (CWE-22).

- NVCF_LARGE_OUTPUT_DIR: require absolute path and canonicalize with
  os.path.realpath() before passing to NVCFJobResult as resultdir.
- NVCF_FUNCTION_ASSET_IDS: validate that the asset ID stays within
  NVCF_ASSET_DIR using os.path.realpath + os.path.commonpath containment
  check, matching the pattern used in validate_file_path(). Reject if
  asset ID is itself an absolute path or escapes the asset root.

Signed-off-by: Ramakrishna Prabhu <ramakrishnap@nvidia.com>
@ramakrishnap-nv ramakrishnap-nv changed the title fix(security): harden path traversal and input validation in server fix(security): resolve SonarQube path traversal and input validation findings Jul 23, 2026
@ramakrishnap-nv
ramakrishnap-nv marked this pull request as ready for review July 23, 2026 17:14
@ramakrishnap-nv
ramakrishnap-nv requested a review from a team as a code owner July 23, 2026 17:14
@ramakrishnap-nv
ramakrishnap-nv requested a review from tmckayus July 23, 2026 17:14
@ramakrishnap-nv ramakrishnap-nv self-assigned this Jul 23, 2026
@ramakrishnap-nv ramakrishnap-nv added non-breaking Introduces a non-breaking change improvement Improves an existing functionality labels Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Changes

The pull request tightens webserver filesystem and request validation, resolves nightly output paths, replaces implicit NaN checks, hardens parser timer cleanup, and reformats decompression code without changing its logic.

Validation and robustness updates

Layer / File(s) Summary
Request path and identifier validation
python/cuopt_server/cuopt_server/webserver.py
UUIDs and offsets are validated, output and asset paths are canonicalized and constrained, and validated paths are passed to job results.
Nightly output path resolution
ci/utils/aggregate_nightly.py
The nightly aggregation output directory is resolved before directory creation and artifact writes.
Explicit NaN and rotation handling
cpp/src/dual_simplex/phase2.cpp, cpp/src/io/experimental_mps_fast/fast_fp64_parser.hpp, cpp/src/utilities/pcgenerator.hpp, cpp/tests/linear_programming/c_api_tests/c_api_test.c
NaN detection uses standard predicates, and pseudorandom rotation uses an unsigned shift expression.
Parser and decompression robustness
cpp/src/io/experimental_mps_fast/fast_parser.cpp, cpp/src/io/experimental_mps_fast/lz4_file_reader.cpp, cpp/src/io/file_to_string.cpp
Timer destructor failures are suppressed, pointer bounds are documented, initialization is clarified, and decompression calls are reformatted without changing behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Suggested reviewers: kaatish, nguidotti

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing security findings across the codebase.
Description check ✅ Passed The description is directly related to the changeset and accurately summarizes the fixes.
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 fix/sonarqube-security-webserver

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

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

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 `@python/cuopt_server/cuopt_server/webserver.py`:
- Around line 1344-1353: Update the NVCF_LARGE_OUTPUT_DIR handling in the
webserver request path to require its canonicalized path to remain within the
deployment-configured trusted output root, not merely be absolute. Resolve both
paths before validating containment, reject paths outside the root with the
existing HTTPException pattern, and preserve the canonical path passed as the
write directory.
- Around line 1363-1383: Update the result-registration flow around
NVCFJobResult.register_result so NVCF_FUNCTION_ASSET_IDS, NVCF_ASSET_DIR, and
the resolved asset path are fully validated before registering the result, or
ensure every validation exception unregisters the registered result via finally.
Preserve the existing HTTP 400 responses while preventing invalid requests from
leaving registered results behind.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ce1eb196-bb75-434a-a1aa-955fc7a07aa2

📥 Commits

Reviewing files that changed from the base of the PR and between 17f813e and 482dcc0.

📒 Files selected for processing (1)
  • python/cuopt_server/cuopt_server/webserver.py

Comment thread python/cuopt_server/cuopt_server/webserver.py
Comment thread python/cuopt_server/cuopt_server/webserver.py Outdated
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

CI Test Summary

✅ All 31 test job(s) passed.

…dings

- fast_parser.cpp: wrap destructor body in try-catch (S1048); suppress
  S3519 false positive with NOSONAR (find_line_start pointer stays in bounds)
- fast_fp64_parser.hpp: replace v==v NaN check with !std::isnan(v) (S1764)
- lz4_file_reader.cpp: suppress S836 false positives with NOSONAR
  (window_count is initialized before window_state_ and window_done per
  C++ declaration order)
- file_to_string.cpp: suppress 14 S2259 false positives with NOSONAR
  (mps_parser_expects throws before any null pointer dereference)
- phase2.cpp: replace scale!=scale NaN check with std::isnan(scale) (S1764)
- c_api_test.c: replace x!=x NaN check with isnan() from <math.h> (S1764)
- pcgenerator.hpp: replace unary minus on unsigned with (32u-rot)&31u (S876)
- aggregate_nightly.py: canonicalize output_dir with Path.resolve() (S2083)

Signed-off-by: Ramakrishna Prabhu <ramakrishnap@nvidia.com>
@ramakrishnap-nv
ramakrishnap-nv requested review from a team as code owners July 23, 2026 18:25
@ramakrishnap-nv ramakrishnap-nv changed the title fix(security): resolve SonarQube path traversal and input validation findings fix(security): resolve SonarQube critical/high/blocker security findings Jul 23, 2026
- Validate NVCF asset path before register_result() to prevent leaked
  registered results when header validation raises HTTPException
- Add optional CUOPT_NVCF_OUTPUT_ROOT env var: when set, require
  nvcf-large-output-dir to stay within the deployment-configured root

Signed-off-by: Ramakrishna Prabhu <ramakrishnap@nvidia.com>
…orward decl

As of rmm 26.10, rmm::device_uvector is defined inside the ABI inline namespace
rmm::RMM_ABI_NAMESPACE (rmm/detail/export.hpp). cuOpt's manual
  namespace rmm { template <typename T> class device_uvector; }
forward declaration in problem_checking.cuh injects a *second*, distinct
rmm::device_uvector into the plain rmm namespace, so every use becomes ambiguous
('rmm::device_uvector is ambiguous'), which fails the build against rmm 26.10.

Replace the hand-rolled forward declaration with #include <rmm/device_uvector.hpp>
so the correctly ABI-namespaced declaration is used. (cuOpt already disables the
analogous thrust/cub ABI namespaces via -DTHRUST_DISABLE_ABI_NAMESPACE /
-DCUB_DISABLE_NAMESPACE_MAGIC; rmm's ABI namespace is newer and has no such opt-out.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Max Buckley <maxwbuckley@gmail.com>
@ramakrishnap-nv ramakrishnap-nv added this to the 26.08 milestone Jul 24, 2026
Comment thread cpp/src/io/experimental_mps_fast/fast_parser.cpp Outdated
Comment thread cpp/src/io/experimental_mps_fast/lz4_file_reader.cpp Outdated
… lz4_file_reader.cpp

- Remove try-catch from ~scoped_timer_t(): reviewers noted that the
  called functions cannot realistically throw; silent catching was
  flagged as bad practice. Suppress S1048 with NOSONAR instead.
- Fix corrupted SPDX header in fast_parser.cpp and lz4_file_reader.cpp:
  verify-copyright hook had split the long copyright line and duplicated
  "reserved." onto the license-identifier line.

Signed-off-by: Ramakrishna Prabhu <ramakrishnap@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improvement Improves an existing functionality non-breaking Introduces a non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants