Skip to content

fix: reject NaN and Inf in ValidateNumericParam - #1494

Closed
DsThakurRawat wants to merge 2 commits into
OneBusAway:mainfrom
DsThakurRawat:fix/1492-reject-nonfinite
Closed

DsThakurRawat wants to merge 2 commits into
OneBusAway:mainfrom
DsThakurRawat:fix/1492-reject-nonfinite

Conversation

@DsThakurRawat

@DsThakurRawat DsThakurRawat commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Rejects NaN, ±Inf and overflow values in ValidateNumericParam, so report-problem location params with non-finite values are dropped like unparseable ones instead of being stored verbatim. Reuses the existing isFinite helper from #1490.

Verified: new table cases fail on main and pass with the fix; full internal/utils suite and go vet clean.

Fixes #1492

Summary by CodeRabbit

  • Bug Fixes
    • Numeric inputs representing NaN, positive or negative infinity, or values that overflow to infinity are now rejected.

strconv.ParseFloat accepts NaN, Inf and overflow values without error,
so report-problem location params passed validation and were stored
verbatim. Reuse the existing isFinite helper from OneBusAway#1490 to drop them
like unparseable input.

Fixes OneBusAway#1492

Signed-off-by: Divyansh Rawat <divyanshrawatofficial@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: b695dc34-ddf3-472e-acee-eff2af735fa0

📥 Commits

Reviewing files that changed from the base of the PR and between 8ab5cc3 and b75ab39.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 517f7cc1-2754-4705-a23e-02330353e550

📥 Commits

Reviewing files that changed from the base of the PR and between c887d91 and 8ab5cc3.

📒 Files selected for processing (2)
  • internal/utils/api.go
  • internal/utils/api_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

ValidateNumericParam now rejects parsed NaN and infinite values. Tests cover NaN, positive and negative infinity, and an input that overflows to infinity. Empty input continues to return an empty string.

Changes

Numeric parameter validation

Layer / File(s) Summary
Finite-value validation and test coverage
internal/utils/api.go, internal/utils/api_test.go
ValidateNumericParam rejects non-finite parsed values. Tests cover NaN, Inf, -Infinity, and 1e400.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: ahmedhossamdev

Merge Risk: ⚪ Minimal · up to 8ab5c

Non-finite report values are treated as absent optional fields, consistent with the documented inputs. No merge-blocking issue remains.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 8ab5c

The change narrows which location values can be stored and does not appear to change access or submission behavior. The assessment is limited by incomplete coverage of other potential callers.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated effect is confined to location fields in examined problem-report submissions. Complete caller coverage and exposure beyond those paths are not established.

Trust Boundaries and Controls

  • observed — At the examined HTTP-input boundary, the revised control filters non-finite numeric strings before they reach nullable database parameters. It does not add an identity or authorization check.

Resilience and Maintainability Implications

  • inferred — Repeated or concurrent calls apply the same stateless normalization; the examined handler’s write-failure response remains separate from validation and unchanged.
🚥 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: rejecting NaN and infinity values in ValidateNumericParam.
Linked Issues check ✅ Passed The PR satisfies issue #1492. ValidateNumericParam now rejects parsed NaN, positive infinity, negative infinity, and overflow values, and returns the empty string for these invalid values. The cha…
Out of Scope Changes check ✅ Passed The PR changes only internal/utils/api.go and its tests. The production change implements issue #1492, and the test cases verify the required validation behavior. No unrelated change is shown.

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.

@sonarqubecloud

Copy link
Copy Markdown

@Ahmedhossamdev

Copy link
Copy Markdown
Member

Thanks @DsThakurRawat, LGTM. This does what #1492 asks.

One thing for whoever merges: #1499 later moved the policy for these params to a 400 through ParseFloatParam, and Java already returns 400 for userLat=Inf, -Infinity and 1e400 (only NaN gets a 200). #1501 switches the report-problem handlers over to that. So this is a fine interim fix, but it will be superseded once that lands.

@DsThakurRawat

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #1499. With #1499 merged, the report-problem endpoints use ParseFloatParam to reject non-finite and overflow values, resolving #1492 on main.

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.

Reject NaN and Inf in report-problem location params

2 participants