Skip to content

fix(directory): harden VMACS query construction#226

Open
rlorenzo wants to merge 1 commit into
mainfrom
fix/vmacs-url-encode-loginid
Open

fix(directory): harden VMACS query construction#226
rlorenzo wants to merge 1 commit into
mainfrom
fix/vmacs-url-encode-loginid

Conversation

@rlorenzo

@rlorenzo rlorenzo commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What

Two small hardening changes to VMACSService.Search:

  1. URL-encode the login IDUri.EscapeDataString(loginID ?? string.Empty) before interpolating into the query URL, so reserved characters can't alter the request. Also drops a no-op .ToString().
  2. Extract the AUTH token to a named constantVmacsAuthToken instead of a magic literal in the URL string.

Why

Both surfaced during the CodeQL/agy review work. loginID is a DB-sourced campus login (AaudUser.LoginId, passed by both DirectoryController call sites), so exploitability is low; the AUTH value is a fixed internal-endpoint token, not a rotating secret. This is hygiene, not a vulnerability fix.

Scope note

The agy review suggested further changes (read the response stream directly instead of string→bytes→MemoryStream, and externalize the token/URL via config + DI). Those are behavior-adjacent / architectural and were deliberately kept out to keep this PR scoped; recommend a separate ticket for the static→DI refactor.

@codecov-commenter

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@codecov-commenter

codecov-commenter commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.51%. Comparing base (1a0996e) to head (81e0601).

Files with missing lines Patch % Lines
web/Areas/Directory/Services/VMACSService.cs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #226      +/-   ##
==========================================
- Coverage   44.51%   44.51%   -0.01%     
==========================================
  Files         895      895              
  Lines       51760    51761       +1     
  Branches     4827     4828       +1     
==========================================
  Hits        23041    23041              
- Misses      28149    28150       +1     
  Partials      570      570              
Flag Coverage Δ
backend 44.67% <0.00%> (-0.01%) ⬇️
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.

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

This PR hardens the Directory area’s VMACS lookup by URL-encoding the loginID value before it’s interpolated into the outbound query string, preventing reserved characters from altering the request.

Changes:

  • Encode loginID via Uri.EscapeDataString(loginID ?? string.Empty) before building the VMACS query URL.
  • Remove a no-op .ToString() call on an already-string interpolated value.

@rlorenzo rlorenzo force-pushed the fix/vmacs-url-encode-loginid branch from c372293 to 2767fcb Compare June 17, 2026 02:07
@rlorenzo rlorenzo changed the title fix(directory): URL-encode VMACS login ID in query fix(directory): harden VMACS query construction Jun 17, 2026
@rlorenzo rlorenzo requested a review from Copilot June 17, 2026 02:07

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 1 out of 1 changed files in this pull request and generated no new comments.

public class VMACSService
{
// Fixed token required by the internal VMACS trust endpoint (not a rotating secret).
private const string VmacsAuthToken = "06232005";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bsedwards Should this be a config value?

@rlorenzo rlorenzo force-pushed the fix/vmacs-url-encode-loginid branch from 2767fcb to 4a2c7c9 Compare June 24, 2026 01:51
- URL-encode the login ID (Uri.EscapeDataString) before interpolating it
  into the VMACS query URL so reserved characters can't alter the request.
- Extract the fixed AUTH token into a named VmacsAuthToken constant
  instead of a magic literal in the URL string.
- Drop a no-op .ToString() on the interpolated string.

loginID is a DB-sourced campus login (low exploitability) and the AUTH
token is a fixed internal-endpoint value, so this is hygiene/hardening,
not a vulnerability fix.
@rlorenzo rlorenzo force-pushed the fix/vmacs-url-encode-loginid branch from 4a2c7c9 to 81e0601 Compare June 26, 2026 03:05
@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

VMACSService now stores the VMACS AUTH token in a constant and uses it when building the trust query. The loginID value is URL-encoded before being added to the request.

Changes

VMACS trust query update

Layer / File(s) Summary
Named AUTH token and encoded loginID
web/Areas/Directory/Services/VMACSService.cs
Adds a private VmacsAuthToken constant and builds the VMACS trust query with Uri.EscapeDataString(loginID ?? string.Empty) for loginID and the constant for AUTH.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested reviewers

  • bsedwards
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change to VMACS query construction.
Description check ✅ Passed The description directly matches the code changes and scope of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/vmacs-url-encode-loginid

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.

@rlorenzo

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Actionable comments posted: 1

🤖 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/Directory/Services/VMACSService.cs`:
- Around line 27-28: The URL construction in VMACSService is still embedded in
the lookup logic, so pull the request-building portion out into a small helper
method (for example, in the same service near the login lookup path) that takes
the login ID and returns the encoded query string. Then add focused tests
against that helper to cover null, spaces, +, &, and = cases so the
Uri.EscapeDataString behavior and request format in the lookup path are
independently verifiable.
🪄 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: bd9770b9-c6b2-4fcf-885c-070c57819dc7

📥 Commits

Reviewing files that changed from the base of the PR and between 1a0996e and 81e0601.

📒 Files selected for processing (1)
  • web/Areas/Directory/Services/VMACSService.cs

Comment on lines +27 to +28
string encodedLoginId = Uri.EscapeDataString(loginID ?? string.Empty);
string request = $"/trust/query.xml?dbfile=3&index=CampusLoginId&find={encodedLoginId}&format=CHRIS4&AUTH={VmacsAuthToken}";

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.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the query builder independently testable.

Line 27-28 changed lookup semantics, but this path still has no patch coverage. Pull the URL construction into a small helper and add cases for null, spaces, +, &, and = so encoding regressions fail fast.

🤖 Prompt for 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.

In `@web/Areas/Directory/Services/VMACSService.cs` around lines 27 - 28, The URL
construction in VMACSService is still embedded in the lookup logic, so pull the
request-building portion out into a small helper method (for example, in the
same service near the login lookup path) that takes the login ID and returns the
encoded query string. Then add focused tests against that helper to cover null,
spaces, +, &, and = cases so the Uri.EscapeDataString behavior and request
format in the lookup path are independently verifiable.

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