Skip to content

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

Open
rlorenzo wants to merge 2 commits into
mainfrom
refactor/codeql-complex-condition
Open

refactor(codeql): decompose complex conditions + harden Vite web-root check#227
rlorenzo wants to merge 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.

Scope

ScheduleEditService was removed from this PR to avoid overlapping with #229 — that PR owns the duplicate-detection fix (SqlException.Number), which also clears the complex-condition alert there. 14 other complex-condition alerts were dismissed (EF/LINQ predicates that must stay single expressions, plus test-file chains).

Two commits: the refactor and the security fix are kept separate.

@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.47%. Comparing base (f6dbe72) to head (3ceffd8).

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.49%   44.47%   -0.02%     
==========================================
  Files         895      895              
  Lines       51655    51673      +18     
  Branches     4812     4819       +7     
==========================================
  Hits        22983    22983              
- Misses      28108    28124      +16     
- Partials      564      566       +2     
Flag Coverage Δ
backend 44.63% <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 added 2 commits June 16, 2026 19:23
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.
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 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.

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.

3 participants