fix: fallback to GET when config.method is undefined in adapters (closes #6960) by MarcosNocetti · Pull Request #10683 · axios/axios · GitHub
Skip to content

fix: fallback to GET when config.method is undefined in adapters (closes #6960)#10683

Open
MarcosNocetti wants to merge 2 commits intoaxios:v1.xfrom
MarcosNocetti:fix/method-touppercase-6960
Open

fix: fallback to GET when config.method is undefined in adapters (closes #6960)#10683
MarcosNocetti wants to merge 2 commits intoaxios:v1.xfrom
MarcosNocetti:fix/method-touppercase-6960

Conversation

@MarcosNocetti
Copy link
Copy Markdown

@MarcosNocetti MarcosNocetti commented Apr 10, 2026

Summary

  • Adds (config.method || 'get') fallback before .toUpperCase() in all 3 adapters
  • Prevents TypeError: undefined is not an object (evaluating 'config.method.toUpperCase')
  • Includes regression test

Root Cause

Axios._request() normalizes config.method at line 145, but request interceptors run after this normalization and can delete or nullify config.method. The adapters then crash when calling .toUpperCase() on undefined.

Changes

File Change
lib/adapters/xhr.js:36 _config.method.toUpperCase()(_config.method || 'get').toUpperCase()
lib/adapters/http.js:338 config.method.toUpperCase()(config.method || 'get').toUpperCase()
lib/adapters/fetch.js:240 method.toUpperCase()(method || 'get').toUpperCase()
tests/unit/regression/method-undefined.test.js New regression test (2 cases)

The 'get' default matches the same fallback already used in Axios.js:145.

Test plan

  • Regression test passes: npx vitest run tests/unit/regression/method-undefined.test.js (2/2)
  • Full test suite passes
  • Manual verification with interceptor that deletes config.method

Summary by cubic

Prevents crashes when config.method is unset by defaulting to GET across adapters and fixes fetch preprocessing to avoid unnecessary upload handling. Adds a regression test to guard against future breakage (closes #6960).

Description

  • Changes
    • XHR/HTTP: use (config.method || 'get').toUpperCase() before use.
    • Fetch: set method = method || 'get' immediately after destructuring so upload guards see the correct method.
  • Reasoning
    • Interceptors can remove config.method after normalization, making .toUpperCase() throw and causing incorrect fetch upload preprocessing.
  • Context
    • No public API changes; matches existing axios defaults.

Testing

  • Added tests/unit/regression/method-undefined.test.js (2 cases):
    • Defaults to GET when an interceptor removes config.method.
    • http adapter does not throw TypeError when method is undefined.

Written for commit 7bc149c. Summary will update on new commits.

Adds defensive (config.method || 'get') fallback in xhr, http, and fetch
adapters before calling .toUpperCase(). This prevents TypeError when an
interceptor removes config.method after Axios._request() normalization.

Includes regression test.

Closes axios#6960
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 4 files

Confidence score: 3/5

  • There is a concrete regression risk in lib/adapters/fetch.js: method fallback happens after upload preprocessing, so an undefined method can be treated as non-GET during preprocessing before later being coerced to GET.
  • Given the medium severity (6/10) and high confidence (8/10), this is more than a cosmetic issue and could affect request behavior for callers that omit method.
  • Pay close attention to lib/adapters/fetch.js - ensure method normalization happens before any method-dependent upload preprocessing.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="lib/adapters/fetch.js">

<violation number="1" location="lib/adapters/fetch.js:240">
P2: Method fallback is applied too late: undefined `method` can pass non-GET upload preprocessing before being coerced to GET in `resolvedOptions`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread lib/adapters/fetch.js Outdated
The (method || 'get') fallback was applied at resolvedOptions (line 240)
but undefined method would incorrectly pass the upload preprocessing
guard (method !== 'get' && method !== 'head') at line 190, causing
unnecessary Request/stream creation for what should be a GET request.

Moves the fallback to right after destructuring so all downstream code
sees a valid method string.
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.

TypeError: undefined is not an object (evaluating 'config.method.toUpperCase') — not sure where I'm going wrong

1 participant