Skip to content

refactor(codeql): decompose complex conditions + harden Vite web-root check#227

Merged
rlorenzo merged 2 commits into
mainfrom
refactor/codeql-complex-condition
Jun 26, 2026
Merged

refactor(codeql): decompose complex conditions + harden Vite web-root check#227
rlorenzo merged 2 commits into
mainfrom
refactor/codeql-complex-condition

Conversation

@rlorenzo

@rlorenzo rlorenzo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What

1. Decompose complex boolean conditions (cs/complex-condition), behavior-preserving:

  • CMS.CheckFilePermission — early-return guard clauses; resolve the user's permissions once into an OrdinalIgnoreCase HashSet instead of an O(n²) per-permission scan.
  • ViteProxyHelpers.CreateProxyRequestmethodSupportsBody / hasReadableBody named bools.

2. Fix a directory-boundary bug (folded-in follow-up): the Vite static-file path check used resolvedPhysical.StartsWith(resolvedWebRoot), which a sibling like wwwroot-secret would pass. Append a trailing separator (via Path.EndsInDirectorySeparator) so the check respects the directory boundary.

@codecov-commenter

codecov-commenter commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 11.53846% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.49%. Comparing base (1a0996e) to head (933006c).

Files with missing lines Patch % Lines
web/Areas/CMS/Data/CMS.cs 0.00% 16 Missing ⚠️
web/ViteProxyHelpers.cs 30.00% 4 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #227      +/-   ##
==========================================
- Coverage   44.51%   44.49%   -0.02%     
==========================================
  Files         895      895              
  Lines       51760    51778      +18     
  Branches     4827     4834       +7     
==========================================
  Hits        23041    23041              
- Misses      28149    28165      +16     
- Partials      570      572       +2     
Flag Coverage Δ
backend 44.65% <11.53%> (-0.02%) ⬇️
frontend 41.32% <ø> (ø)

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.

@codecov-commenter

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

Copilot AI 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.

Pull request overview

Refactors several complex boolean conditions into named sub-conditions / guard clauses to address CodeQL cs/complex-condition findings while keeping behavior the same.

Changes:

  • CMS.CheckFilePermission: adds an early-return for public files and extracts permission checks into named booleans.
  • ScheduleEditService: deduplicates duplicate/constraint message checks via a helper method.
  • ViteProxyHelpers.CreateProxyRequest: extracts named booleans for “method supports body” and “has readable body”.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
web/ViteProxyHelpers.cs Simplifies proxy request body-copy condition via named booleans.
web/Areas/CMS/Data/CMS.cs Refactors CMS file permission logic into guard clause + named condition variables.
web/Areas/ClinicalScheduler/Services/ScheduleEditService.cs Extracts DB constraint/duplicate detection into a helper for reuse.

Comment thread web/Areas/CMS/Data/CMS.cs Outdated
Comment thread web/Areas/ClinicalScheduler/Services/ScheduleEditService.cs
@rlorenzo rlorenzo force-pushed the refactor/codeql-complex-condition branch from 36fb462 to 472d0e8 Compare June 16, 2026 23:05
@rlorenzo rlorenzo requested a review from Copilot June 16, 2026 23:06

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread web/ViteProxyHelpers.cs Outdated
Comment thread web/Areas/CMS/Data/CMS.cs Outdated
@rlorenzo rlorenzo force-pushed the refactor/codeql-complex-condition branch from 472d0e8 to 65a70be Compare June 16, 2026 23:42
@rlorenzo rlorenzo requested a review from Copilot June 17, 2026 00:06

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread web/ViteProxyHelpers.cs Outdated
Comment thread web/Areas/ClinicalScheduler/Services/ScheduleEditService.cs Outdated
@rlorenzo rlorenzo force-pushed the refactor/codeql-complex-condition branch from 3199d4b to 3ceffd8 Compare June 17, 2026 02:30
@rlorenzo rlorenzo requested a review from Copilot June 17, 2026 02:30
@rlorenzo rlorenzo changed the title refactor(codeql): decompose complex boolean conditions refactor(codeql): decompose complex conditions + harden Vite web-root check Jun 17, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@rlorenzo rlorenzo force-pushed the refactor/codeql-complex-condition branch from 3ceffd8 to f9850b1 Compare June 24, 2026 01:51
Extract named sub-conditions / guard clauses to clear cs/complex-condition
findings, behavior-preserving:

- CMS.CheckFilePermission: early-return guard clauses; resolve the user's
  permissions once into an OrdinalIgnoreCase HashSet instead of re-querying
  per file permission (removes an O(n^2) scan).
- ViteProxyHelpers.CreateProxyRequest: methodSupportsBody / hasReadableBody
  named bools, comparing the request method with OrdinalIgnoreCase rather
  than allocating an uppercased copy.
@rlorenzo rlorenzo force-pushed the refactor/codeql-complex-condition branch from f9850b1 to 2d26d38 Compare June 26, 2026 03:06
@rlorenzo

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR refactors CMS file-permission evaluation into ordered early returns and updates Vite proxy helpers to gate request-body copying and tighten static-file fallback path containment checks.

Changes

CMS file permission evaluation

Layer / File(s) Summary
Permission checks
web/Areas/CMS/Data/CMS.cs
CheckFilePermission now evaluates public access, empty-permission secure access, explicit permission matches, and explicit people matches through ordered early returns after building a case-insensitive user-permission set once.

Vite proxy request and fallback handling

Layer / File(s) Summary
Request body gating
web/ViteProxyHelpers.cs
CreateProxyRequest now uses case-insensitive GET/HEAD checks and a separate readable-body test before copying request content.
Fallback path boundary
web/ViteProxyHelpers.cs
HandleProxyError now appends a directory separator to resolvedWebRoot before the containment check against the resolved file path.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • ucdavis/VIPER#190: Also changes web/ViteProxyHelpers.cs static-file fallback path handling and traversal-related path construction.

Suggested reviewers

  • bsedwards
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 accurately summarizes the refactor and Vite web-root hardening in the changeset.
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.
Description check ✅ Passed The description matches the PR changes, covering the permission refactor, request body logic cleanup, and the directory-boundary fix.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/codeql-complex-condition

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Append a trailing separator to the resolved web root before the
StartsWith containment check so a sibling directory (e.g. wwwroot-secret)
cannot satisfy the prefix check against wwwroot and bypass the
directory-traversal guard when serving Vite static files.
@rlorenzo rlorenzo force-pushed the refactor/codeql-complex-condition branch from 2d26d38 to 933006c Compare June 26, 2026 21:38
@rlorenzo rlorenzo merged commit 4564dae into main Jun 26, 2026
13 checks passed
@rlorenzo rlorenzo deleted the refactor/codeql-complex-condition branch June 26, 2026 23:18
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.

4 participants