Skip to content

fix(retry): protect parseRetryAfterHeader from integer and time duration overflow - #1178

Merged
jeevatkm merged 3 commits into
go-resty:v3from
HarshalPatel1972:fix/retry-after-panic
Jul 5, 2026
Merged

fix(retry): protect parseRetryAfterHeader from integer and time duration overflow#1178
jeevatkm merged 3 commits into
go-resty:v3from
HarshalPatel1972:fix/retry-after-panic

Conversation

@HarshalPatel1972

Copy link
Copy Markdown
Contributor

Description

This PR addresses an un-guarded integer and time duration overflow vulnerability within the automatic retry header parsing engine (parseRetryAfterHeader). By introducing safe multiplication boundary thresholds, we ensure the client cleanly caps astronomical server-provided delays instead of corrupting the backoff context scheduler or causing a runtime panic.

Technical Context

When parsing an HTTP Retry-After header value, the client evaluates either delta-seconds or a specific HTTP-Date string.

  • In the seconds track, multiplying an arbitrary 64-bit integer directly by time.Second ($1,000,000,000$ nanoseconds) easily overflows the internal maximum limit of a Go time.Duration structure ($2^{63}-1$). This calculation error wraps the resulting delay into a negative duration, causing sub-system scheduling panics.
  • In the date fallback track, subtracting the current epoch time from an extreme future date parameter creates a differential calculation that can similarly exceed duration storage limits.

Resolution Strategy

  • Multiplication Ceiling Fencing: Injected an inline arithmetic boundary check using math.MaxInt64 / time.Second inside retry.go to intercept excessive delay parameters out of the gate.
  • Duration Range Normalization: Forced the computed date subtraction result to validate within expected positive limits, defaulting seamlessly to maximum bounds if a range wrap or negative anomaly is encountered.

Copilot AI review requested due to automatic review settings June 25, 2026 23:43

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.73%. Comparing base (b5060b2) to head (85e076b).
⚠️ Report is 3 commits behind head on v3.

Additional details and impacted files
@@            Coverage Diff             @@
##               v3    #1178      +/-   ##
==========================================
- Coverage   99.78%   99.73%   -0.05%     
==========================================
  Files          20       20              
  Lines        4124     4141      +17     
==========================================
+ Hits         4115     4130      +15     
- Misses          6        7       +1     
- Partials        3        4       +1     
Flag Coverage Δ
unittests 99.73% <100.00%> (-0.05%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jeevatkm jeevatkm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@HarshalPatel1972 Thanks for the PR.

Can you add test cases for patch coverage? See codecov report.

@jeevatkm

Copy link
Copy Markdown
Member

@HarshalPatel1972 ping

Signed-off-by: Harshal Patel <hp842484@gmail.com>
@HarshalPatel1972
HarshalPatel1972 requested a review from Copilot June 30, 2026 15:27

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@HarshalPatel1972

Copy link
Copy Markdown
Contributor Author

@HarshalPatel1972 ping

@jeevatkm Good catch! Just pushed an update to fix the coverage.

I added a couple of test cases in retry_test.go to specifically hit those overflow paths. One passes an intentionally massive integer to hit the seconds ceiling, and the other uses a date way out in the year 2293 to trigger the duration wrap-around.

Tests are passing locally, so codecov should be happy now. Let me know if everything looks good on your end!

@jeevatkm

jeevatkm commented Jul 1, 2026

Copy link
Copy Markdown
Member

@HarshalPatel1972 Thanks for updating tests. It seems the overflow path is not covered. Can you please check codecov?

@jeevatkm jeevatkm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@HarshalPatel1972 I have added a test case and merging it.

@jeevatkm
jeevatkm merged commit 3f32051 into go-resty:v3 Jul 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants