refactor(backend): validate numeric IDs and use url.Values for upstream URLs #2

Merged
starkSV merged 1 commit from improve-backend-url-encoding into main 2026-05-12 19:09:32 +05:30
starkSV commented 2026-05-12 19:01:01 +05:30 (Migrated from github.com)

Summary

  • Reject non-numeric product_id and sku_id with HTTP 400 before any upstream request is made, preventing parameter injection into Microsoft API query strings
  • Replace all fmt.Sprintf URL construction with url.Values.Set + .Encode() across handleSkuInfo, handleProxy, and setupSession

Test plan

  • product_id=abc → 400 product_id must be a numeric value
  • product_id=2618%26profile=injected → 400 (injection blocked)
  • Missing product_id → 400 product_id query parameter is required
  • sku_id=notanumber → 400 sku_id must be a numeric value
  • product_id=2618 (valid) → 200 OK from Microsoft

Summary by CodeRabbit

  • Bug Fixes

    • Implemented parameter validation to ensure product identifiers and SKU values are properly formatted as numeric values before processing, preventing invalid requests from reaching downstream services.
  • Refactor

    • Standardized request parameter encoding across endpoints to ensure consistent URL formatting, proper escaping of special characters, and improved overall system reliability.

Review Change Stack

## Summary - Reject non-numeric `product_id` and `sku_id` with HTTP 400 before any upstream request is made, preventing parameter injection into Microsoft API query strings - Replace all `fmt.Sprintf` URL construction with `url.Values.Set` + `.Encode()` across `handleSkuInfo`, `handleProxy`, and `setupSession` ## Test plan - [x] `product_id=abc` → 400 `product_id must be a numeric value` - [x] `product_id=2618%26profile=injected` → 400 (injection blocked) - [x] Missing `product_id` → 400 `product_id query parameter is required` - [x] `sku_id=notanumber` → 400 `sku_id must be a numeric value` - [x] `product_id=2618` (valid) → 200 OK from Microsoft <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Implemented parameter validation to ensure product identifiers and SKU values are properly formatted as numeric values before processing, preventing invalid requests from reaching downstream services. * **Refactor** * Standardized request parameter encoding across endpoints to ensure consistent URL formatting, proper escaping of special characters, and improved overall system reliability. [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/starkSV/windows-iso-downloader/pull/2) <!-- end of auto-generated comment: release notes by coderabbit.ai -->
coderabbitai[bot] commented 2026-05-12 19:01:12 +05:30 (Migrated from github.com)
📝 Walkthrough

Walkthrough

Single file update to backend/main.go that refactors URL query construction across three handlers to use net/url encoding instead of manual fmt.Sprintf strings, adds numeric validation for product ID and SKU ID parameters, and updates a related comment.

Changes

Query Construction and Input Validation

Layer / File(s) Summary
setupSession handler refactoring
backend/main.go
Imports net/url and refactors three outbound Microsoft requests to build query strings via url.Values instead of manual formatting: session/org queries, mdt.js parameters, and fingerprint response parameters.
handleSkuInfo validation and query refactoring
backend/main.go
Validates that product_id is numeric before processing, then replaces the getskuinformationbyproductedition query assembly with url.Values-based encoding.
handleProxy validation and multi-query refactoring
backend/main.go
Validates both product_id and sku_id as numeric values, returning JSON 400 errors on invalid input. Refactors warmup request and GetProductDownloadLinksBySku request URLs to use url.Values. Updates comment on SetEscapeHTML(false).

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Query strings encode with grace,
No Sprintf left to trace—
url.Values leads the way,
Validation guards each day,
Cleaner code in every place!

🚥 Pre-merge checks | 5
Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title 'refactor(backend): validate numeric IDs and use url.Values for upstream URLs' accurately and specifically describes both main changes in the pull request: input validation for numeric IDs and replacement of sprintf-based URL construction with url.Values encoding.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

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 improve-backend-url-encoding

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


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

<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Single file update to `backend/main.go` that refactors URL query construction across three handlers to use `net/url` encoding instead of manual `fmt.Sprintf` strings, adds numeric validation for product ID and SKU ID parameters, and updates a related comment. ## Changes **Query Construction and Input Validation** | Layer / File(s) | Summary | |---|---| | **setupSession handler refactoring** <br> `backend/main.go` | Imports `net/url` and refactors three outbound Microsoft requests to build query strings via `url.Values` instead of manual formatting: session/org queries, mdt.js parameters, and fingerprint response parameters. | | **handleSkuInfo validation and query refactoring** <br> `backend/main.go` | Validates that `product_id` is numeric before processing, then replaces the `getskuinformationbyproductedition` query assembly with `url.Values`-based encoding. | | **handleProxy validation and multi-query refactoring** <br> `backend/main.go` | Validates both `product_id` and `sku_id` as numeric values, returning JSON 400 errors on invalid input. Refactors warmup request and `GetProductDownloadLinksBySku` request URLs to use `url.Values`. Updates comment on `SetEscapeHTML(false)`. | ## Estimated Code Review Effort 🎯 2 (Simple) | ⏱️ ~10 minutes ## Poem > 🐰 Query strings encode with grace, > No `Sprintf` left to trace— > `url.Values` leads the way, > Validation guards each day, > Cleaner code in every place! ✨ </details> <!-- walkthrough_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 5</summary> <details> <summary>✅ Passed checks (5 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. | | Title check | ✅ Passed | The title 'refactor(backend): validate numeric IDs and use url.Values for upstream URLs' accurately and specifically describes both main changes in the pull request: input validation for numeric IDs and replacement of sprintf-based URL construction with url.Values encoding. | | 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. | </details> <sub>✏️ Tip: You can configure your own custom pre-merge checks in the settings.</sub> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- finishing_touch_checkbox_start --> <details> <summary>✨ Finishing Touches</summary> <details> <summary>📝 Generate docstrings</summary> - [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> Create stacked PR - [ ] <!-- {"checkboxId": "3e1879ae-f29b-4d0d-8e06-d12b7ba33d98"} --> Commit on current branch </details> <details> <summary>🧪 Generate unit tests (beta)</summary> - [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Create PR with unit tests - [ ] <!-- {"checkboxId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} --> Commit unit tests in branch `improve-backend-url-encoding` </details> </details> <!-- finishing_touch_checkbox_end --> <!-- This is an auto-generated comment: all tool run failures by coderabbit.ai --> > [!WARNING] > There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. > > <details> > <summary>🔧 golangci-lint (2.12.2)</summary> > > level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" > > > > > </details> <!-- end of auto-generated comment: all tool run failures by coderabbit.ai --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands and usage tips.</sub> <!-- tips_end --> <!-- internal state start --> <!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKPR1AGxJcKJAGZoYvgUABQCgQDWZLQAlFwSaB7wtNQkkBiOlPAMkACS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xvJvFshUxUAHA/BqymDOw8E0hKpqo64UwplwR91UBPIMKsK9ztSDylA1TnANSiBQLbCHzrgnyXT7STSELujm5QUSjBiSibTGifzjSjyG865wSHAGgcSuKlisjPSuBIL9yYKAyjy2TYwbRhR6A59IYlZOlQS64kBFKH5KBJ1fZ6AdMUxUBuyzxW9NAVKWKHTjz2LTyoKdTrRHyPBnyZKAjzLaAFLGxgQq5EI0lRK8jxK8jJLbDpLPLVpBy+YTgmBhRAKrklKXT3LwKvS6SlTtKWTdKXT2SDK65jK0yzLFELKITjcbL4Ml0sygEnK/gXLEELcmL6SVTWKjyTzNTfK6YeKDT+LfyRq8BVo/AMq2JziSDIrTNEAYq+j/DoDYTK5K8bBCT6zfj7RoTQsosFQlU0B6KGBaAcw8MSBwsFQGA7l1RRBVBPJQ8lU/ABAlUvJaAVp1RaB1Ry11QAaIsVR1QFDPIGAy1ZRPIlUFQFDLrbUNr2hbAnSDrmMpg0B1Q/BI8F8CMvJ1Qcwcw4swcGB1QBBnsI8waPqphYtFUCapgK0FQdQ/B5CtUGASMlBgbZCRClDQV+iDB8VeBjDKBTCXT6D9C8VDDSUQxex1NWCsj5VLDwUDBRU4TK8TK6BgRcAXQvlH5aAXDWB1AXDhlcBpVZReb8VJbpayhZbUg9Cox9AgA=== --> <!-- internal state end -->
cloudflare-workers-and-pages[bot] commented 2026-05-12 19:01:23 +05:30 (Migrated from github.com)

Deploying msdl-frontend with  Cloudflare Pages  Cloudflare Pages

Latest commit: 37f947c
Status:   Deploy successful!
Preview URL: https://98dd8258.msdl-frontend.pages.dev
Branch Preview URL: https://improve-backend-url-encoding.msdl-frontend.pages.dev

View logs

## Deploying msdl-frontend with &nbsp;<a href="https://pages.dev"><img alt="Cloudflare Pages" src="https://user-images.githubusercontent.com/23264/106598434-9e719e00-654f-11eb-9e59-6167043cfa01.png" width="16"></a> &nbsp;Cloudflare Pages <table><tr><td><strong>Latest commit:</strong> </td><td> <code>37f947c</code> </td></tr> <tr><td><strong>Status:</strong></td><td>&nbsp;✅&nbsp; Deploy successful!</td></tr> <tr><td><strong>Preview URL:</strong></td><td> <a href='https://98dd8258.msdl-frontend.pages.dev'>https://98dd8258.msdl-frontend.pages.dev</a> </td></tr> <tr><td><strong>Branch Preview URL:</strong></td><td> <a href='https://improve-backend-url-encoding.msdl-frontend.pages.dev'>https://improve-backend-url-encoding.msdl-frontend.pages.dev</a> </td></tr> </table> [View logs](https://dash.cloudflare.com/?to=/630cc520524402c8c1de35025c15b122/pages/view/msdl-frontend/98dd8258-c846-4d70-b2f5-2ebbb02cc324)
coderabbitai[bot] (Migrated from github.com) reviewed 2026-05-12 19:03:36 +05:30
coderabbitai[bot] (Migrated from github.com) left a comment
🧹 Nitpick comments (1)
backend/main.go (1)

175-178: Quick win

Consider extracting repeated numeric-param validation into one helper.

Both handlers duplicate the same parse/error pattern; centralizing it will keep behavior/messages consistent and reduce drift.

♻️ Suggested refactor
+func requireNumericQueryParam(w http.ResponseWriter, name, value string) bool {
+	if value == "" {
+		respondJSONError(w, http.StatusBadRequest, fmt.Sprintf("%s query parameter is required", name))
+		return false
+	}
+	if _, err := strconv.Atoi(value); err != nil {
+		respondJSONError(w, http.StatusBadRequest, fmt.Sprintf("%s must be a numeric value", name))
+		return false
+	}
+	return true
+}
-	if productID == "" {
-		respondJSONError(w, http.StatusBadRequest, "product_id query parameter is required")
-		return
-	}
-	if _, err := strconv.Atoi(productID); err != nil {
-		respondJSONError(w, http.StatusBadRequest, "product_id must be a numeric value")
+	if !requireNumericQueryParam(w, "product_id", productID) {
 		return
 	}
-	if productID == "" || skuID == "" {
-		respondJSONError(w, http.StatusBadRequest, "product_id and sku_id query parameters are required")
-		return
-	}
-	if _, err := strconv.Atoi(productID); err != nil {
-		respondJSONError(w, http.StatusBadRequest, "product_id must be a numeric value")
-		return
-	}
-	if _, err := strconv.Atoi(skuID); err != nil {
-		respondJSONError(w, http.StatusBadRequest, "sku_id must be a numeric value")
+	if !requireNumericQueryParam(w, "product_id", productID) || !requireNumericQueryParam(w, "sku_id", skuID) {
 		return
 	}

Also applies to: 277-284

🤖 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 `@backend/main.go` around lines 175 - 178, Handlers duplicate numeric parameter
parsing using strconv.Atoi and respondJSONError; extract this into a single
helper (e.g., parseNumericParam or parseIDFromRequest) that accepts the string
value and parameter name, returns the int (or error), and centralizes the "must
be a numeric value" response using respondJSONError and the same HTTP status.
Replace direct strconv.Atoi calls for productID (and the other handler's param)
with calls to this helper to keep behavior and messages consistent across
handlers.
🤖 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.

Nitpick comments:
In `@backend/main.go`:
- Around line 175-178: Handlers duplicate numeric parameter parsing using
strconv.Atoi and respondJSONError; extract this into a single helper (e.g.,
parseNumericParam or parseIDFromRequest) that accepts the string value and
parameter name, returns the int (or error), and centralizes the "must be a
numeric value" response using respondJSONError and the same HTTP status. Replace
direct strconv.Atoi calls for productID (and the other handler's param) with
calls to this helper to keep behavior and messages consistent across handlers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ab568493-41d9-447b-bc3b-b592061e7dd8

📥 Commits

Reviewing files that changed from the base of the PR and between 10ad222dde and 37f947cb32.

📒 Files selected for processing (1)
  • backend/main.go
<details> <summary>🧹 Nitpick comments (1)</summary><blockquote> <details> <summary>backend/main.go (1)</summary><blockquote> `175-178`: _⚡ Quick win_ **Consider extracting repeated numeric-param validation into one helper.** Both handlers duplicate the same parse/error pattern; centralizing it will keep behavior/messages consistent and reduce drift. <details> <summary>♻️ Suggested refactor</summary> ```diff +func requireNumericQueryParam(w http.ResponseWriter, name, value string) bool { + if value == "" { + respondJSONError(w, http.StatusBadRequest, fmt.Sprintf("%s query parameter is required", name)) + return false + } + if _, err := strconv.Atoi(value); err != nil { + respondJSONError(w, http.StatusBadRequest, fmt.Sprintf("%s must be a numeric value", name)) + return false + } + return true +} ``` ```diff - if productID == "" { - respondJSONError(w, http.StatusBadRequest, "product_id query parameter is required") - return - } - if _, err := strconv.Atoi(productID); err != nil { - respondJSONError(w, http.StatusBadRequest, "product_id must be a numeric value") + if !requireNumericQueryParam(w, "product_id", productID) { return } ``` ```diff - if productID == "" || skuID == "" { - respondJSONError(w, http.StatusBadRequest, "product_id and sku_id query parameters are required") - return - } - if _, err := strconv.Atoi(productID); err != nil { - respondJSONError(w, http.StatusBadRequest, "product_id must be a numeric value") - return - } - if _, err := strconv.Atoi(skuID); err != nil { - respondJSONError(w, http.StatusBadRequest, "sku_id must be a numeric value") + if !requireNumericQueryParam(w, "product_id", productID) || !requireNumericQueryParam(w, "sku_id", skuID) { return } ``` </details> Also applies to: 277-284 <details> <summary>🤖 Prompt for AI Agents</summary> ``` Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/main.go` around lines 175 - 178, Handlers duplicate numeric parameter parsing using strconv.Atoi and respondJSONError; extract this into a single helper (e.g., parseNumericParam or parseIDFromRequest) that accepts the string value and parameter name, returns the int (or error), and centralizes the "must be a numeric value" response using respondJSONError and the same HTTP status. Replace direct strconv.Atoi calls for productID (and the other handler's param) with calls to this helper to keep behavior and messages consistent across handlers. ``` </details> </blockquote></details> </blockquote></details> <details> <summary>🤖 Prompt for all review comments with AI agents</summary> ``` Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Nitpick comments: In `@backend/main.go`: - Around line 175-178: Handlers duplicate numeric parameter parsing using strconv.Atoi and respondJSONError; extract this into a single helper (e.g., parseNumericParam or parseIDFromRequest) that accepts the string value and parameter name, returns the int (or error), and centralizes the "must be a numeric value" response using respondJSONError and the same HTTP status. Replace direct strconv.Atoi calls for productID (and the other handler's param) with calls to this helper to keep behavior and messages consistent across handlers. ``` </details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: defaults **Review profile**: CHILL **Plan**: Pro Plus **Run ID**: `ab568493-41d9-447b-bc3b-b592061e7dd8` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 10ad222dde866874e1ccf2ccf9d0e63cc6b199e7 and 37f947cb32bb5cb36e8cf193a8d15f694d6a570c. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `backend/main.go` </details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: shekhar/windows-iso-downloader#2
No description provided.