Skip to content

fix(http): decode URL basic auth credentials#10825

Merged
jasonsaayman merged 4 commits intoaxios:v1.xfrom
afurm:af/fix-url-basic-auth-decoding
Apr 30, 2026
Merged

fix(http): decode URL basic auth credentials#10825
jasonsaayman merged 4 commits intoaxios:v1.xfrom
afurm:af/fix-url-basic-auth-decoding

Conversation

@afurm
Copy link
Copy Markdown
Contributor

@afurm afurm commented Apr 29, 2026

Summary

Decodes username and password values parsed from URL userinfo before passing them to Node's HTTP auth option.

This fixes Basic auth credentials such as my%40email.com:pass@host being sent as my%40email.com:pass instead of my@email.com:pass.

Closes #5158.

Validation

  • npm run test:vitest:unit -- tests/unit/adapters/http.test.js
  • git diff --check
  • npx eslint lib/adapters/http.js tests/unit/adapters/http.test.js

Summary by cubic

Decodes URL-encoded Basic Auth credentials in request URLs and guards against malformed encodings. The Authorization header now uses decoded values without throwing on bad input.

Description

  • Decode parsed.username and parsed.password with a new decodeURIComponentSafe helper before composing the auth option in the Node HTTP adapter.
  • If decoding fails, fall back to the original strings so malformed userinfo is passed through unchanged.

Docs

  • Add a note in /docs/ that URL-encoded credentials in request URLs are decoded in the Node HTTP adapter, and malformed encodings are left as-is.

Testing

  • Added unit tests:
    • Decoded credentials produce the expected Basic header.
    • Malformed encodings do not throw and remain percent-encoded.

Semantic version impact

  • Patch (bug fix, no API changes).

Written for commit f4e3955. Summary will update on new commits. Review in cubic

@afurm afurm requested a review from jasonsaayman as a code owner April 29, 2026 15:05
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 2 files

Confidence score: 3/5

  • There is a concrete behavior risk in lib/adapters/http.js: unconditional URL credential decoding can throw on malformed percent-escapes, which can break request setup for affected inputs.
  • This lands as moderate merge risk because the issue is user-facing and high-confidence, even though it appears scoped to a specific parsing edge case rather than broad functionality.
  • Pay close attention to lib/adapters/http.js - guard or safely handle credential decoding errors so malformed URLs do not cause unexpected setup failures or error-type changes.
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/http.js">

<violation number="1" location="lib/adapters/http.js:642">
P2: Unconditionally decoding URL credentials can throw on malformed percent escapes, breaking request setup and changing the error type.</violation>
</file>

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

Comment thread lib/adapters/http.js Outdated
@jasonsaayman jasonsaayman added priority::medium A medium priority commit::fix The PR is related to a bugfix labels Apr 30, 2026
@jasonsaayman jasonsaayman merged commit 2a51828 into axios:v1.x Apr 30, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commit::fix The PR is related to a bugfix priority::medium A medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Basic authentication gets (double?) escaped

2 participants