Skip to content

test: cover http: credential redaction and FormData prototype guard - #11299

Open
renanmpimentel wants to merge 3 commits into
axios:v1.xfrom
renanmpimentel:test/security-regression-coverage
Open

renanmpimentel wants to merge 3 commits into
axios:v1.xfrom
renanmpimentel:test/security-regression-coverage

Conversation

@renanmpimentel

@renanmpimentel renanmpimentel commented Oct 6, 2026 •

Copy link
Copy Markdown

Summary

Two security guards in lib/ can currently be removed without any unit test failing. This PR adds one regression test for each. Test-only.

  1. Credential redaction for http: URLs (lib/core/buildFullPath.js). Invalid-URL errors redact userinfo with /^(https?:\/{0,2})[^/?#]*@/i, but the existing test only uses an https: URL. Changing https? to https keeps the suite green while buildFullPath(undefined, 'http:admin:[email protected]/v1') puts admin:hunter2 in error.message, which AxiosError.toJSON() serializes and apps commonly log.
  2. __proto__ guard in formDataToJSON (lib/helpers/formDataToJSON.js). The existing pollution test checks that Object.prototype stays clean, which still holds without the guard. What the guard prevents is local: without it, __proto__[isAdmin]=true makes the returned object inherit isAdmin: "true" (result.isAdmin === "true"), while JSON.stringify(result) shows only {"name":"bob"}. The new test asserts the result keeps Object.prototype and does not expose isAdmin.

Linked issue

None. Found by mutation testing and statement-removal analysis: both removals survived the full tests/unit suite.

Changes

  • tests/unit/core/buildFullPath.test.js: redacts credentials in http: URLs as well as https: URLs
  • tests/unit/helpers/formDataToJSON.test.js: should not replace the prototype of the resulting object
  • PRE_RELEASE_CHANGELOG.md: Maintenance entry

Validation

Node v26.12.1, integrated with v1.x at e6b79d9 (head 473d241):

  • npm ci --ignore-scripts: passed
  • npm run lint: passed
  • node node_modules/typescript/bin/tsc --noEmit --strict --lib es2020,dom --module Node16 --moduleResolution Node16 index.d.ts index.d.cts: passed
  • npm run build: passed
  • npm run test:vitest:unit: 74 files, 1,702 tests passed
  • git diff --check origin/v1.x: passed; added-line secret-pattern scan: 0 matches
  • Regression mutations on the earlier base 2b169bb (temporary, reverted): narrowing https? to https and removing the __proto__ guard each made its new test fail.
  • Browser suites: not run. This PR changes Node unit tests and the prerelease entry; no runtime or browser code changed.
  • GitHub Actions on this head: Continuous integration, Bundle Size, and zizmor each report action_required; maintainer approval is needed before CI results exist.

Compatibility and documentation

No semver impact (test-only). No PRE_RELEASE_DOCS.md or index.d.ts/index.d.cts changes needed.

Checklist

  • Scope, target branch, and linked issue/rationale checked
  • PRE_RELEASE_CHANGELOG.md entry added or updated (or AGENTS.md's automated release-preparation exception explained)
  • Regression tests and relevant negative/platform cases covered (or N/A with reason)
  • Applicable local checks completed, with actual commands and results recorded above
  • Deferred release docs and ESM/CJS types/tests updated where needed (or N/A with reason): N/A, test-only
  • Semver impact stated and intentional breaking changes explained
  • Final diff reviewed for security, unrelated changes, generated artifacts, and test/debug leftovers
  • Latest GitHub Actions status recorded separately from review/security bot results: action_required on the current head; maintainer approval is pending, so CI is not green yet.

AI tooling assisted with this change; the ai-assisted label is applied.


Found with supertest: mutation testing plus statement-removal analysis, with every finding confirmed by running the regression against the unmodified test.


Summary by cubic

Description

Test-only PR adding two regression tests found via mutation testing and statement-removal analysis: both security guards could be removed without any existing unit test failing. These tests make sure the guards stay.

  • buildFullPath now has a test covering credential redaction for http: URLs in invalid-URL error messages. Existing coverage only used https:, so narrowing the redaction regex to https alone kept the suite green while leaking admin:hunter2 into error.message.
  • formDataToJSON now has a test asserting a __proto__[isAdmin] FormData field cannot replace the prototype of the resulting object. Without the guard, the result inherits isAdmin: "true" from an attacker-chosen prototype while JSON.stringify only shows {"name":"bob"}.

Docs

No documentation changes needed. Test-only change; no runtime, public API, or type changes. PRE_RELEASE_CHANGELOG.md gets a maintenance entry linking this PR.

Testing

Two unit tests added, plus a changelog entry:

  • tests/unit/core/buildFullPath.test.js: redacts credentials in http: URLs as well as https: URLs.
  • tests/unit/helpers/formDataToJSON.test.js: should not replace the prototype of the resulting object.
  • PRE_RELEASE_CHANGELOG.md: maintenance entry referencing this PR.

Verified both new tests fail against the unguarded source and pass with it restored; full unit suite passes (1519 tests). Lint passes.

Semantic version impact

Patch. Test-only change with no runtime, public API, or type impact.

Written for commit 712a4d8. Summary will update on new commits.

Review in cubic

- buildFullPath: add an http: case to the credential redaction tests.
  Restricting the redaction regex to https: kept the whole unit suite
  green while leaking "admin:hunter2" into the error message.
- formDataToJSON: assert that a `__proto__[isAdmin]` field cannot
  replace the prototype of the resulting object. Removing the
  `__proto__` guard kept the whole unit suite green while the result
  inherited `isAdmin: "true"` from an attacker-chosen prototype.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] No blocking issues identified in this test-only PR; runtime code, public APIs, and types remain unchanged.

Summary

Adds two security regression tests without changing runtime code.

  • HTTP error tests now check that URL credentials stay hidden.
  • FormData tests now check that __proto__ cannot change the result’s prototype.

No new actionable issues found. Tests were inspected but not run during this review.

Reviews (3) · Last reviewed commit: "chore: sync security regression tests wi..." · Reviewed by Greptile

Comment thread PRE_RELEASE_CHANGELOG.md Resolved
@jasonsaayman jasonsaayman added commit::tests The PR is related to tests v1x Version 1 labels Oct 7, 2026
@jasonsaayman jasonsaayman added the ai-assisted This PR was created with or in conjunction with AI label Oct 21, 2026

@jasonsaayman jasonsaayman 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.

PR #11299 - test: cover http: credential redaction and FormData prototype guard

Repo: axios/axios Author: @renanmpimentel Base: v1.x Files: 3 **+30/-0
CI: Unavailable: no checks returned; no build/test workflow result is present in this snapshot. Mergeability: conflicting. Reviewed head: 712a4d892bca8359199ee37ae11a8ba708dc2a4f.

Repo Profile

Axios is an npm JavaScript HTTP client for browsers and Node, with XHR/Fetch/HTTP adapters, default and named exports, interceptors, headers/errors, and paired ESM/CJS declarations. The target uses Vitest plus browser and package/module tests; v1 packaging covers older Node CJS runtimes as well as current ESM, Bun and Deno. Contributions preserve transport/security boundaries, add regression coverage and prerelease records, and defer unreleased user docs to PRE_RELEASE_DOCS.md. This review uses the actual target-branch guidance and files, not the separate local v0 checkout.

Verdict

Request changes — No concrete source defect found in this review; the missing latest-head validation and merge conflicts prevent merge approval.
Posted as a comment review for the validation/integration hold; no formal code-change request is implied beyond the specific items below.

Change Explanation And User Impact

The HTTP additions assert that credentials do not leak into serialized diagnostics. The form reconstruction tests also assert the prototype of the returned object, which catches an unsafe result even when Object.prototype itself is unchanged. No runtime behavior changes in this PR. Inferred maintainer effect: an implementation that creates a polluted result or exposes request credentials will fail a direct contract assertion rather than passing a weaker global-prototype check.

Validation scope: source/diff and regression-test review. Examples explicitly marked executed used isolated source snapshots on Node 24.18.0 with the workspace dependency installation; these were focused checks, not a clean install, full CI matrix, or full test-suite run. Author-reported test results were not treated as independently executed.

Competing PRs

Search: axios/axios open PRs, including drafts; full open-list scan plus formDataToJSON in:title,body, 11295 in:title,body, credential redaction in:title,body. Complementary searches were run across related APIs/issues; no query reached the 100-result cap and no search failed. The five explicitly excluded PRs were not reviewed or modified in this batch.

#11296 and #11328 address the same length-slot failure. #11296 uses a narrower guard and has both insertion orders plus browser HTML-form coverage, so it is preferred. #11278 preserves empty field names; #11280 supplies a benchmark; #11299 strengthens hardening tests. Those are complementary. Newly opened #11353 uses the same targeted guard as #11296, with fewer regressions and no prerelease entry; its combined length/nested/dotted cases are covered by #11296.

Preferred PR: No competing implementation supersedes this PR; continue it independently.

Unique contributions: The submitted regression cases protect this specific boundary; preserve them independently of adjacent fixes.

Action: No duplicate closure: the candidates are complementary or no equivalent solution was found.

Project Fit

North star: Reliable HTTP transport and configuration across supported JavaScript environments, without embedding application-specific policy.

Benefits: Protects credential redaction and the prototype of returned form objects.

Tradeoffs: Security tests must distinguish trusted caller config from attacker-controlled keys and avoid claiming a stronger redaction boundary than the implementation provides.

Fit: Strong — The underlying problem belongs in the transport, serializer, declarations or their maintenance tests.

Adversarial Review

Strongest objection: Security tests must distinguish trusted caller config from attacker-controlled keys and avoid claiming a stronger redaction boundary than the implementation provides. Latest-head integration evidence is still needed.

Abuse/failure modes checked: Read the credential assertions and result-prototype checks, their cleanup, and the existing hardening code they exercise. This is additional defense regression coverage, not evidence of a newly fixed vulnerability.

Result: No concrete source defect established in the examined cases; validation and integration limits remain below.

Disposition

Continue
Address the specific blockers below; no unrelated scope or complementary PR should be closed.

Semver

patch — Corrects existing behavior or strengthens internal tooling/tests without adding a public API.

Breaking Changes

None: this is test/tooling-only work or a declaration widening for already-supported runtime behavior.

Documentation

PRE_RELEASE_CHANGELOG.md records the change. No new API reference or migration is required for this scoped correction; keep the release description consistent with the behavior and limits above.

Performance And Regression Risk

Hot path touched: No shipped runtime change.

Performance concern: No shipped runtime hot path changes; tooling/type validation still needs the appropriate CI run.

Regression risk: low — the changed boundary needs regression and integration coverage, particularly after any rebase.

Evidence requested: The latest-head checks listed below; no extra benchmark requested for this scoped change.

Blocking Issues

  • Latest-head build/test validation is unavailable in the returned GitHub checks. Run or attach the repository build, relevant regression suite and required package/type/browser checks before merge; review/security bots alone do not establish that they pass. This is a validation hold, not an invented source defect.
  • GitHub reports merge conflicts with the current target. Resolve them and re-run relevant checks; the reviewed source snapshot is not a tested merge result.

Non-Blocking Suggestions

  • Keep the returned-object prototype assertions alongside global pollution checks; they detect different failure modes.

Looks Good

  • Read the credential assertions and result-prototype checks, their cleanup, and the existing hardening code they exercise. This is additional defense regression coverage, not evidence of a newly fixed vulnerability.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-assisted This PR was created with or in conjunction with AI commit::tests The PR is related to tests v1x Version 1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants