CodeQL 12: chore: style sweep for remaining CodeQL alerts#198
Conversation
📝 WalkthroughWalkthroughPull request modernizes code across test data, controllers, and helpers by adopting contemporary C# patterns: DateTime arithmetic precision adjustments, ternary expressions replacing if/else blocks, implicit ToString() calls in string formatting, parameter renames in HttpHelper, and null-coalescing consolidation in UserHelper. ChangesCode Style Modernization Refactoring
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
Bundle ReportBundle size has no change ✅ |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #198 +/- ##
==========================================
+ Coverage 42.96% 42.98% +0.02%
==========================================
Files 877 877
Lines 51468 51433 -35
Branches 4802 4803 +1
==========================================
- Hits 22113 22109 -4
+ Misses 28831 28800 -31
Partials 524 524
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
- UserHelper.cs: capture user into 'fallbackUser' local before
GetOrCreate lambda so ReSharper AccessToModifiedClosure is silenced
- HttpHelper.cs: drop stale '<param name="memoryCache">' XML tag now
that the other params don't have matching tags (was creating 5
InvalidXmlDocComment warnings since the rename)
- test/ClinicalScheduler/{EmailNotificationTest,TestDataBuilder}.cs:
replace '(double)(-7 * x)' with '-7.0 * x' — same intent (force the
multiplication into double per cs/loss-of-precision) but no
RedundantCast warning from ReSharper
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
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 `@web/Areas/RAPS/Controllers/RAPSController.cs`:
- Line 315: Add a deny-access helper on RAPSController to centralize logging and
403 rendering: implement a private method (e.g., DenyAccess(string reason) or
DenyAccessResult(string reason)) in RAPSController that logs the reason via the
controller logger, sets Response.StatusCode = 403, and returns View("403") (or
an appropriate IActionResult). Replace duplicated denial code paths in methods
like any access checks inside RAPSController to call this helper instead of
repeating log + status + view logic, keeping the same log message format and
ensuring the helper returns IActionResult to be used with return statements.
In `@web/Controllers/HomeController.cs`:
- Line 315: The code currently logs raw CAS XML via
HttpHelper.Logger.Log(NLog.LogLevel.Warn, "No username. CAS response: " + doc),
which may leak user identifiers; sanitize/redact sensitive fields from the CAS
response before logging by using the LogSanitizer utilities (e.g.,
LogSanitizer.SanitizeString or SanitizeId) on the variable doc or on the
extracted attributes, then pass the sanitized string to HttpHelper.Logger.Log
(keep the "No username. CAS response:" prefix but replace doc with the sanitized
output).
🪄 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: ASSERTIVE
Plan: Pro
Run ID: f890a93f-65d0-470c-876d-651c0bddcba5
📒 Files selected for processing (12)
test/ClinicalScheduler/EmailNotificationTest.cstest/ClinicalScheduler/TestDataBuilder.csweb/Areas/CMS/Controllers/CMSController.csweb/Areas/Curriculum/Services/TermCodeService.csweb/Areas/Directory/Models/LdapUserContact.csweb/Areas/Effort/Services/VerificationService.csweb/Areas/RAPS/Controllers/RAPSController.csweb/Areas/RAPS/Services/UinformService.csweb/Areas/Students/Services/GradYearClassLevel.csweb/Classes/HttpHelper.csweb/Classes/UserHelper.csweb/Controllers/HomeController.cs
The fallback log path for a CAS validation response with no username embedded the raw XML in the message. CAS responses come from an external source and can contain user identifiers and claim attributes, so per CLAUDE.md the value must pass through LogSanitizer before hitting the log. Wraps the doc.ToString() in LogSanitizer.SanitizeString.
Summary
Sweep PR covering the remaining straightforward CodeQL style alerts that earlier PRs deferred.
Closes
cs/useless-tostring-call (7):
HomeController.cs:315-doc.ToString()in string concat → dropGradYearClassLevel.cs:57,60,69-.ToString()afterintin"V" + ...UinformService.cs:274-epochTime.ToString()in concatLdapUserContact.cs:39-v.ToString()in concatTermCodeService.cs:39-year.ToString()instring.Formatcs/missed-ternary-operator (6 / 17):
HttpHelper.cs:51-HttpContextgetter collapsed to expression-bodied?.HttpContextRAPSController.cs:315,359-if/else return View(...)→ ternaryCMSController.cs:28-if/else return cms.X(...)→ ternaryVerificationService.cs:773-dueDateif/else assignment → ternaryUserHelper.cs:68,152,280,345- fourif (x != null) return x; else return Y;blocks →x ?? Y(in CodeQL 12 part 1 before this PR was scoped - folded in here)cs/local-shadows-member (3):
HttpHelper.ConfigureparametershttpContextAccessor,authorizationService,dataProtectionProviderrenamed to non-shadowing names (contextAccessor,authzService,dataProtection); the assignments to private static fields no longer need theHttpHelper.qualifier.cs/loss-of-precision (3):
test/ClinicalScheduler/EmailNotificationTest.cs:122-123andTestDataBuilder.cs:179- explicit(double)casts around theintarithmetic flowing intoDateTime.AddDays(double).Not addressed
Remaining
cs/missed-ternary-operator(11) where the branches contain multi-statement bodies that don't fit ternary cleanly (UinformService.cs:247 deserialize path, EffortAuditService.cs:605 IQueryable build, etc.) - converting them would hurt readability. Same forcs/complex-condition(17) which are subjective rewrites,cs/complex-block(1),cs/nested-if-statements(2). The twojs/implicit-operand-conversionalerts incourse-import-dialog.test.ts:72,96are intentional test code simulating non-Error throws.Context
Twelfth in the
CodeQL N:cleanup series.Test plan
npm run test:backend- 1946 tests passing