Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cap maximum number of retries at 25 #343

Closed
wants to merge 4 commits into from
Closed

feat: cap maximum number of retries at 25 #343

wants to merge 4 commits into from

Conversation

johannschopplich
Copy link
Contributor

πŸ”— Linked issue

Related:

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR adds a sanity default value for the configurable retries option.

This enhancement is suggested by @pi0 following the security issue detected by @OhB00. In the Nuxt module API Party the fetch options were passed to a server route, which consumed the fetch options as-is. This enabled attackers to force a retry value of whatever.

It might be best to set a maximum number of retries. Not only for security reasons, but also for developers as a safety measures.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (ff395c2) 56.86% compared to head (68c5f44) 57.00%.

❗ Current head 68c5f44 differs from pull request most recent head a83a5d2. Consider uploading reports for the commit a83a5d2 to get more accurate results

Files Patch % Lines
src/fetch.ts 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #343      +/-   ##
==========================================
+ Coverage   56.86%   57.00%   +0.13%     
==========================================
  Files          16       16              
  Lines         728      735       +7     
  Branches      113      114       +1     
==========================================
+ Hits          414      419       +5     
- Misses        303      305       +2     
  Partials       11       11              

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@@ -136,6 +136,9 @@ await ofetch("http://google.com/404", {
});
```

> [!NOTE]
Copy link
Member

Choose a reason for hiding this comment

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

I think we can use a normal paragraph since no user action is involved...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

// Retry
if (context.options.retry !== false && !isAbort) {
let retries;
if (typeof context.options.retry === "number") {
retries = context.options.retry;
if (retries > MAX_RETRIES) {
Copy link
Member

Choose a reason for hiding this comment

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

What about introducing new maxRetries option to allow setting the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if this defeats the purpose of this PR. My understanding was to include a sensible default for maximum retries. Instead of a maxRetries option, retries basically does the same, right?
If you dislike the idea of an internal maximum, which I completely get, please close this PR. πŸ™‚

Copy link
Member

Choose a reason for hiding this comment

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

Well it could be a configurable global in fetch factory so basically it is second cap but also configurable if someone/framework/util needs too :)

@johannschopplich
Copy link
Contributor Author

I don't think these changes are useful to most users. There are much more interesting PRs at hand to elevate ofetch to the next level, such as #357 for local/global interceptors.

So I'm closing this PR. All the best to ofetch! Love it. πŸ™Œ

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.

2 participants